forked from security/hakurei
cmd/pkgserver: add /status endpoint
This commit is contained in:
@@ -2,8 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"fmt"
|
||||
"slices"
|
||||
"unique"
|
||||
|
||||
"hakurei.app/internal/pkg"
|
||||
"hakurei.app/internal/rosa"
|
||||
@@ -25,12 +25,13 @@ type PackageIndex struct {
|
||||
}
|
||||
|
||||
type PackageIndexEntry struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Website string `json:"website,omitempty"`
|
||||
Version string `json:"version"`
|
||||
Status string `json:"report,omitempty"`
|
||||
status []byte `json:"-"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Website string `json:"website,omitempty"`
|
||||
Version string `json:"version"`
|
||||
HasReport bool `json:"report,omitempty"`
|
||||
ident unique.Handle[pkg.ID] `json:"-"`
|
||||
status []byte `json:"-"`
|
||||
}
|
||||
|
||||
func createPackageIndex(cache *pkg.Cache, report *rosa.Report) (_ *PackageIndex, err error) {
|
||||
@@ -45,20 +46,18 @@ func createPackageIndex(cache *pkg.Cache, report *rosa.Report) (_ *PackageIndex,
|
||||
id := cache.Ident(a)
|
||||
st, n := report.ArtifactOf(id)
|
||||
var status []byte
|
||||
var statusUrl string
|
||||
if n < 1 {
|
||||
status = nil
|
||||
statusUrl = ""
|
||||
} else {
|
||||
status = st
|
||||
statusUrl = fmt.Sprintf("/api/%s/status/%s.log", ApiVersion, m.Name)
|
||||
}
|
||||
entry := PackageIndexEntry{
|
||||
Name: m.Name,
|
||||
Description: m.Description,
|
||||
Website: m.Website,
|
||||
Version: v,
|
||||
Status: statusUrl,
|
||||
HasReport: len(status) > 0,
|
||||
ident: id,
|
||||
status: status,
|
||||
}
|
||||
work[p] = entry
|
||||
|
||||
Reference in New Issue
Block a user