cmd/pkgserver: add get endpoint

This commit is contained in:
mae
2026-03-09 18:18:51 -05:00
parent 15d8780d7a
commit 5267455e59
2 changed files with 62 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"cmp"
"fmt"
"slices"
"hakurei.app/internal/pkg"
@@ -25,10 +26,11 @@ type PackageIndex struct {
type PackageIndexEntry struct {
Name string `json:"name"`
Description string `json:"description"`
Website string `json:"website"`
Description string `json:"description,omitempty"`
Website string `json:"website,omitempty"`
Version string `json:"version"`
status []byte
Status string `json:"report,omitempty"`
status []byte `json:"-"`
}
func createPackageIndex(cache *pkg.Cache, report *rosa.Report) (_ *PackageIndex, err error) {
@@ -43,16 +45,20 @@ 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/status/%s.log", m.Name)
}
entry := PackageIndexEntry{
Name: m.Name,
Description: m.Description,
Website: m.Website,
Version: v,
Status: statusUrl,
status: status,
}
work[p] = entry