Initial commit: AetherForge Linux (forge-mesh) v0.1.0-dev
Some checks failed
Test / test (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
This commit is contained in:
84
internal/api/handlers/forge.go
Normal file
84
internal/api/handlers/forge.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"forge-mesh/internal/auth"
|
||||
"forge-mesh/internal/forge"
|
||||
)
|
||||
|
||||
// ForgeHandler manages build artifacts.
|
||||
type ForgeHandler struct {
|
||||
DB *sql.DB
|
||||
Pipeline *forge.Pipeline
|
||||
Version string
|
||||
}
|
||||
|
||||
func (h *ForgeHandler) ListBuilds(w http.ResponseWriter, r *http.Request) {
|
||||
rows, err := h.DB.Query(`
|
||||
SELECT id, os, arch, version, checksum, signature, public, created_at
|
||||
FROM builds ORDER BY created_at DESC LIMIT 50
|
||||
`)
|
||||
if err != nil {
|
||||
http.Error(w, "internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
type buildRow struct {
|
||||
ID string `json:"id"`
|
||||
OS string `json:"os"`
|
||||
Arch string `json:"arch"`
|
||||
Version string `json:"version"`
|
||||
Checksum string `json:"checksum"`
|
||||
Signature string `json:"signature,omitempty"`
|
||||
Public bool `json:"public"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
var builds []buildRow
|
||||
for rows.Next() {
|
||||
var b buildRow
|
||||
var sig sql.NullString
|
||||
var pub int
|
||||
if err := rows.Scan(&b.ID, &b.OS, &b.Arch, &b.Version, &b.Checksum, &sig, &pub, &b.CreatedAt); err != nil {
|
||||
http.Error(w, "internal error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
b.Public = pub == 1
|
||||
if sig.Valid {
|
||||
b.Signature = sig.String
|
||||
}
|
||||
builds = append(builds, b)
|
||||
}
|
||||
if builds == nil {
|
||||
builds = []buildRow{}
|
||||
}
|
||||
auth.JSON(w, http.StatusOK, map[string]any{"builds": builds})
|
||||
}
|
||||
|
||||
func (h *ForgeHandler) TriggerBuild(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Public bool `json:"public"`
|
||||
}
|
||||
_ = json.NewDecoder(r.Body).Decode(&req)
|
||||
if !req.Public {
|
||||
req.Public = true
|
||||
}
|
||||
|
||||
builds, err := h.Pipeline.BuildAll(req.Public)
|
||||
if err != nil {
|
||||
auth.JSON(w, http.StatusOK, map[string]any{
|
||||
"ok": false,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
auth.JSON(w, http.StatusOK, map[string]any{
|
||||
"ok": true,
|
||||
"builds": builds,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user