Null-DRM-Official/apps/streamd/internal/api/apps.go
404errordeveloper da8e1123ec
All checks were successful
release / build-and-upload (push) Successful in 7m5s
Streamd v0.2.0: rename, modules panel, stable/beta channels
- Rename product/host binary to streamd (drm compat copy still shipped)
- Go module path streamd; STREAMD_* env aliases; agent UA streamd-agent
- Panel Modules store + agent pull sync (modstore / modsync)
- Rolling stable + beta download tags; README/docs channel curl blocks
- Release notes in docs/releases/v0.2.0.md attached by Forgejo Actions
2026-10-10 15:58:26 +02:00

74 lines
2.2 KiB
Go

package api
import (
"net/http"
"streamd/apps/streamd/internal/auth"
"streamd/modhost"
"streamd/mpd"
"streamd/repo"
)
// appInfo describes one modules/<name>/ provider to the dashboard, so the UI
// never has to hardcode a provider or channel name.
type appInfo struct {
Name string `json:"name"`
Channels []channelInfo `json:"channels"`
Rewriter string `json:"rewriter"`
HasConfig bool `json:"has_config"`
Error string `json:"error,omitempty"`
}
type channelInfo struct {
ID string `json:"id"`
Label string `json:"label"`
}
// apps answers GET /api/apps: which providers exist under the panel modules store.
// A single module that fails to describe is skipped with an error field rather
// than failing the whole list (bad uploads must not blank the stream pickers).
func (h *Handler) apps(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
writeErr(w, http.StatusMethodNotAllowed, "method not allowed")
return
}
if _, ok := auth.Guard(w, r, auth.RoleViewer); !ok {
return
}
out := []appInfo{}
mods, err := modhost.Discover(repo.Root())
if err != nil {
writeErr(w, http.StatusInternalServerError, err.Error())
return
}
for _, m := range mods {
bin, err := modhost.EnsureBuilt(m)
if err != nil {
out = append(out, appInfo{Name: m.Name, Channels: []channelInfo{}, Rewriter: "none", Error: err.Error()})
h.logger().Warn("module describe skipped", "module", m.Name, "err", err)
continue
}
d, err := modhost.RunDescribe(bin)
if err != nil {
out = append(out, appInfo{Name: m.Name, Channels: []channelInfo{}, Rewriter: "none", Error: err.Error()})
h.logger().Warn("module describe skipped", "module", m.Name, "err", err)
continue
}
if d.Name == "" {
d.Name = m.Name
}
info := appInfo{Name: d.Name, Channels: []channelInfo{}, Rewriter: "none"}
for _, ch := range d.Channels {
info.Channels = append(info.Channels, channelInfo{ID: ch.ID, Label: ch.Label})
}
info.HasConfig = len(info.Channels) > 0
if d.Rewriter != "" {
info.Rewriter = d.Rewriter
}
out = append(out, info)
}
writeJSON(w, http.StatusOK, map[string]any{
"apps": out,
"rewriters": mpd.Names(),
})
}