package api import ( "net/http" "streamd/apps/streamd/internal/auth" "streamd/modhost" "streamd/mpd" "streamd/repo" ) // appInfo describes one modules// 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(), }) }