Streamd v0.2.0: rename, modules panel, stable/beta channels
All checks were successful
release / build-and-upload (push) Successful in 7m5s

- 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
This commit is contained in:
404errordeveloper 2026-10-10 15:58:26 +02:00
parent 066e018749
commit da8e1123ec
140 changed files with 2949 additions and 851 deletions

View file

@ -10,10 +10,11 @@ import (
"strings"
"time"
"drmdecryption/apps/streamd/internal/auth"
"drmdecryption/apps/streamd/internal/db"
"drmdecryption/apps/streamd/internal/deps"
"drmdecryption/apps/streamd/internal/httpx"
"streamd/apps/streamd/internal/auth"
"streamd/apps/streamd/internal/db"
"streamd/apps/streamd/internal/deps"
"streamd/apps/streamd/internal/httpx"
"streamd/apps/streamd/internal/modstore"
)
type Supervisor interface {
@ -56,7 +57,11 @@ type Handler struct {
Deps deps.Status
WWWRoot string // data/www — used to report variant playlist health
LogRoot string // data/logs — source for the log tail endpoints
Log *slog.Logger
DataDir string // streamd --data root
Modules *modstore.Store
// ModulesNotify is set when the hub supports module change pushes.
ModulesNotify ModulesNotifier
Log *slog.Logger
}
func (h *Handler) Mount(mux *http.ServeMux) {

View file

@ -3,10 +3,10 @@ package api
import (
"net/http"
"drmdecryption/apps/streamd/internal/auth"
"drmdecryption/modhost"
"drmdecryption/mpd"
"drmdecryption/repo"
"streamd/apps/streamd/internal/auth"
"streamd/modhost"
"streamd/mpd"
"streamd/repo"
)
// appInfo describes one modules/<name>/ provider to the dashboard, so the UI
@ -16,6 +16,7 @@ type appInfo struct {
Channels []channelInfo `json:"channels"`
Rewriter string `json:"rewriter"`
HasConfig bool `json:"has_config"`
Error string `json:"error,omitempty"`
}
type channelInfo struct {
@ -23,7 +24,9 @@ type channelInfo struct {
Label string `json:"label"`
}
// apps answers GET /api/apps: which providers exist under modules/.
// 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")
@ -33,13 +36,27 @@ func (h *Handler) apps(w http.ResponseWriter, r *http.Request) {
return
}
out := []appInfo{}
listed, err := modhost.ListAll(repo.Root())
mods, err := modhost.Discover(repo.Root())
if err != nil {
writeErr(w, http.StatusInternalServerError, err.Error())
return
}
for _, L := range listed {
d := L.Desc
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})

View file

@ -11,9 +11,9 @@ import (
"strings"
"time"
"drmdecryption/apps/streamd/internal/auth"
"drmdecryption/apps/streamd/internal/db"
"drmdecryption/mpd"
"streamd/apps/streamd/internal/auth"
"streamd/apps/streamd/internal/db"
"streamd/mpd"
)
// MountControl adds the bulk, duplicate, probe, settings and schedule routes.

View file

@ -10,9 +10,9 @@ import (
"strings"
"time"
"drmdecryption/apps/streamd/internal/auth"
"drmdecryption/apps/streamd/internal/db"
"drmdecryption/apps/streamd/internal/logfile"
"streamd/apps/streamd/internal/auth"
"streamd/apps/streamd/internal/db"
"streamd/apps/streamd/internal/logfile"
)
// logSources maps a caller-supplied source name to the log file suffix the

View file

@ -1,93 +1,160 @@
package api
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"io"
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"time"
"drmdecryption/apps/streamd/internal/auth"
"drmdecryption/modhost"
"drmdecryption/repo"
"streamd/apps/streamd/internal/auth"
"streamd/apps/streamd/internal/modstore"
)
// moduleInfo is one modules/<name>/ entry for agent sync.
type moduleInfo struct {
Name string `json:"name"`
HasYAML bool `json:"has_yaml"`
YAMLSHA256 string `json:"yaml_sha256,omitempty"`
// ModulesNotifier pushes module change events to agents and the dashboard.
type ModulesNotifier interface {
NotifyModulesChanged(name, reason string)
}
var moduleNameRe = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$`)
func (h *Handler) modStore() *modstore.Store {
if h.Modules != nil {
return h.Modules
}
root := filepath.Join(h.DataDir, "modules")
return modstore.New(root)
}
func (h *Handler) notifyModules(name, reason string) {
if h.ModulesNotify != nil {
h.ModulesNotify.NotifyModulesChanged(name, reason)
return
}
// Hub also implements Notifier; prefer the dedicated method when available.
if n, ok := h.Notifier.(ModulesNotifier); ok {
n.NotifyModulesChanged(name, reason)
}
}
func (h *Handler) modules(w http.ResponseWriter, r *http.Request) {
path := strings.TrimPrefix(r.URL.Path, "/api/modules")
path = strings.Trim(path, "/")
// Module metadata describes the provider plugins installed on this host,
// so even reading it needs a principal.
if _, ok := auth.Guard(w, r, auth.RoleViewer); !ok {
return
}
switch {
case path == "" && r.Method == http.MethodGet:
if _, ok := auth.Guard(w, r, auth.RoleViewer); !ok {
return
}
h.listModules(w, r)
case path == "upload" && r.Method == http.MethodPost:
h.uploadModule(w, r)
case path != "" && !strings.Contains(path, "/") && r.Method == http.MethodGet:
if _, ok := auth.Guard(w, r, auth.RoleViewer); !ok {
return
}
h.getModule(w, r, path)
case path != "" && !strings.Contains(path, "/") && r.Method == http.MethodPut:
h.putModule(w, r, path)
case path != "" && !strings.Contains(path, "/") && r.Method == http.MethodDelete:
h.deleteModule(w, r, path)
case strings.HasSuffix(path, "/yaml") && r.Method == http.MethodGet:
name := strings.TrimSuffix(path, "/yaml")
name = strings.Trim(name, "/")
h.getModuleYAML(w, r, name)
case strings.HasSuffix(path, "/package") && r.Method == http.MethodGet:
name := strings.TrimSuffix(path, "/package")
name = strings.Trim(name, "/")
h.getModulePackage(w, r, name)
default:
writeErr(w, http.StatusMethodNotAllowed, "method not allowed")
}
}
func (h *Handler) listModules(w http.ResponseWriter, r *http.Request) {
root := repo.Root()
dir := modhost.ModulesDir(root)
ents, err := os.ReadDir(dir)
list, err := h.modStore().List()
if err != nil {
if os.IsNotExist(err) {
writeJSON(w, http.StatusOK, map[string]any{"modules": []moduleInfo{}})
return
}
writeErr(w, http.StatusInternalServerError, err.Error())
return
}
out := []moduleInfo{}
for _, e := range ents {
if !e.IsDir() || strings.HasPrefix(e.Name(), ".") {
continue
}
info := moduleYAMLInfo(filepath.Join(dir, e.Name()), e.Name())
out = append(out, info)
}
writeJSON(w, http.StatusOK, map[string]any{"modules": out})
writeJSON(w, http.StatusOK, map[string]any{"modules": list})
}
func (h *Handler) getModule(w http.ResponseWriter, r *http.Request, name string) {
if !moduleNameRe.MatchString(name) {
if !modstore.NameRe.MatchString(name) {
writeErr(w, http.StatusBadRequest, "invalid module name")
return
}
info := moduleYAMLInfo(filepath.Join(modhost.ModulesDir(repo.Root()), name), name)
writeJSON(w, http.StatusOK, info)
info := h.modStore().Info(name)
if !info.HasYAML && !info.HasPackage {
writeErr(w, http.StatusNotFound, "module not found")
return
}
out := map[string]any{"module": info}
if r.URL.Query().Get("include") == "yaml" {
// YAML may hold secrets — operator+.
if _, ok := auth.Guard(w, r, auth.RoleOperator); !ok {
return
}
raw, err := h.modStore().ReadYAML(name)
if err != nil {
writeErr(w, http.StatusNotFound, err.Error())
return
}
out["yaml"] = string(raw)
}
writeJSON(w, http.StatusOK, out)
}
func (h *Handler) getModuleYAML(w http.ResponseWriter, r *http.Request, name string) {
if _, ok := auth.Guard(w, r, auth.RoleOperator); !ok {
return
}
if !modstore.NameRe.MatchString(name) {
writeErr(w, http.StatusBadRequest, "invalid module name")
return
}
raw, err := h.modStore().ReadYAML(name)
if err != nil {
writeErr(w, http.StatusNotFound, err.Error())
return
}
w.Header().Set("Content-Type", "text/yaml; charset=utf-8")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.WriteHeader(http.StatusOK)
_, _ = w.Write(raw)
}
func (h *Handler) getModulePackage(w http.ResponseWriter, r *http.Request, name string) {
if _, ok := auth.Guard(w, r, auth.RoleOperator); !ok {
return
}
if !modstore.NameRe.MatchString(name) {
writeErr(w, http.StatusBadRequest, "invalid module name")
return
}
f, _, err := h.modStore().OpenPackage(name)
if err != nil {
writeErr(w, http.StatusNotFound, err.Error())
return
}
defer f.Close()
modTime := time.Time{}
if st, err := f.Stat(); err == nil {
modTime = st.ModTime()
}
w.Header().Set("Content-Type", "application/zip")
w.Header().Set("Content-Disposition", `attachment; filename="`+name+`.zip"`)
w.Header().Set("X-Content-Type-Options", "nosniff")
http.ServeContent(w, r, name+".zip", modTime, f)
}
func (h *Handler) putModule(w http.ResponseWriter, r *http.Request, name string) {
// Writing a module.yaml changes how streams are captured on this host:
// operator, and recorded.
p, ok := auth.Guard(w, r, auth.RoleOperator)
if !ok {
return
}
if !moduleNameRe.MatchString(name) {
if !modstore.NameRe.MatchString(name) {
writeErr(w, http.StatusBadRequest, "invalid module name")
return
}
@ -104,47 +171,84 @@ func (h *Handler) putModule(w http.ResponseWriter, r *http.Request, name string)
writeErr(w, http.StatusBadRequest, err.Error())
return
}
if len(strings.TrimSpace(string(yamlBytes))) == 0 {
writeErr(w, http.StatusBadRequest, "empty module.yaml")
info, err := h.modStore().WriteYAML(name, yamlBytes)
if err != nil {
writeErr(w, http.StatusBadRequest, err.Error())
return
}
modDir := filepath.Join(modhost.ModulesDir(repo.Root()), name)
if err := os.MkdirAll(modDir, 0o755); err != nil {
writeErr(w, http.StatusInternalServerError, err.Error())
return
}
dest := filepath.Join(modDir, "module.yaml")
tmp := dest + ".tmp"
if err := os.WriteFile(tmp, yamlBytes, 0o644); err != nil {
writeErr(w, http.StatusInternalServerError, err.Error())
return
}
if err := os.Rename(tmp, dest); err != nil {
_ = os.Remove(tmp)
writeErr(w, http.StatusInternalServerError, err.Error())
return
}
info := moduleYAMLInfo(modDir, name)
h.audit(r, p, http.StatusOK, "uploaded module.yaml for "+name)
h.audit(r, p, http.StatusOK, "updated module.yaml for "+name)
h.logger().Info("module.yaml updated", "module", name, "by", p.Actor(), "sha256", info.YAMLSHA256)
h.notifyModules(name, "yaml_updated")
writeJSON(w, http.StatusOK, map[string]any{
"ok": true,
"module": info,
})
}
func moduleYAMLInfo(modDir, name string) moduleInfo {
info := moduleInfo{Name: name}
b, err := os.ReadFile(filepath.Join(modDir, "module.yaml"))
if err != nil {
return info
func (h *Handler) deleteModule(w http.ResponseWriter, r *http.Request, name string) {
p, ok := auth.Guard(w, r, auth.RoleOperator)
if !ok {
return
}
sum := sha256.Sum256(b)
info.HasYAML = true
info.YAMLSHA256 = hex.EncodeToString(sum[:])
return info
if !modstore.NameRe.MatchString(name) {
writeErr(w, http.StatusBadRequest, "invalid module name")
return
}
if err := h.modStore().Delete(name); err != nil {
writeErr(w, http.StatusNotFound, err.Error())
return
}
h.audit(r, p, http.StatusOK, "deleted module "+name)
h.logger().Info("module deleted", "module", name, "by", p.Actor())
h.notifyModules(name, "deleted")
writeJSON(w, http.StatusOK, map[string]any{"ok": true})
}
func (h *Handler) uploadModule(w http.ResponseWriter, r *http.Request) {
p, ok := auth.Guard(w, r, auth.RoleOperator)
if !ok {
return
}
if err := r.ParseMultipartForm(modstore.MaxPackageBytes + (1 << 20)); err != nil {
writeErr(w, http.StatusBadRequest, "multipart: "+err.Error())
return
}
name := strings.TrimSpace(r.FormValue("name"))
file, hdr, err := r.FormFile("file")
if err != nil {
writeErr(w, http.StatusBadRequest, "missing file field")
return
}
defer file.Close()
if hdr.Size > modstore.MaxPackageBytes {
writeErr(w, http.StatusBadRequest, "zip too large")
return
}
raw, err := io.ReadAll(io.LimitReader(file, modstore.MaxPackageBytes+1))
if err != nil {
writeErr(w, http.StatusBadRequest, err.Error())
return
}
if int64(len(raw)) > modstore.MaxPackageBytes {
writeErr(w, http.StatusBadRequest, "zip too large")
return
}
info, err := h.modStore().InstallZip(raw, name)
if err != nil {
writeErr(w, http.StatusBadRequest, err.Error())
return
}
h.audit(r, p, http.StatusOK, "uploaded module package "+info.Name)
h.logger().Info("module package uploaded",
"module", info.Name, "by", p.Actor(),
"package_sha256", info.PackageSHA256, "arches", info.Arches)
h.notifyModules(info.Name, "uploaded")
writeJSON(w, http.StatusOK, map[string]any{
"ok": true,
"module": info,
})
}
// extractModuleYAML accepts raw YAML or JSON {"yaml":"..."}.
@ -163,7 +267,6 @@ func extractModuleYAML(contentType string, body []byte) ([]byte, error) {
}
return []byte(wrap.YAML), nil
default:
// text/yaml, application/x-yaml, or bare body
return body, nil
}
}

View file

@ -6,7 +6,7 @@ import (
"strings"
"time"
"drmdecryption/apps/streamd/internal/db"
"streamd/apps/streamd/internal/db"
)
// stalePlaylistS is how old a playlist may get before the output counts as