streamd: optional keys, per-stream proxy, auto deps; agent module.yaml sync; RTE AutoPlay; Telegram release announces
All checks were successful
release / build-and-upload (push) Successful in 6m20s
modules-release / build-and-upload (push) Successful in 4m51s

- streamd: MPD-only start, proxy field, ffmpeg/NRE/mp4decrypt auto-install
- GET/PUT /api/modules for module.yaml sync; agent sync_modules
- RTE Live-tab AutoPlay fixes; modules zip named bbc/rte/tg4.zip
- Telegram notify scripts wired into Forgejo release workflows
This commit is contained in:
404errordeveloper 2026-10-09 00:17:23 +02:00
parent f9c28be3f1
commit ac8701b5a6
36 changed files with 1460 additions and 143 deletions

View file

@ -10,6 +10,7 @@ import (
"time"
"drmdecryption/apps/streamd/internal/db"
"drmdecryption/apps/streamd/internal/deps"
)
type Supervisor interface {
@ -23,6 +24,7 @@ type Handler struct {
Token string
Supervisor Supervisor
StartedAt time.Time
Deps deps.Status
}
func (h *Handler) Mount(mux *http.ServeMux) {
@ -30,6 +32,8 @@ func (h *Handler) Mount(mux *http.ServeMux) {
mux.HandleFunc("/api/streams", h.streams)
mux.HandleFunc("/api/streams/", h.streamAction)
mux.HandleFunc("/api/apps", h.apps)
mux.HandleFunc("/api/modules", h.modules)
mux.HandleFunc("/api/modules/", h.modules)
}
func (h *Handler) auth(w http.ResponseWriter, r *http.Request) bool {
@ -64,6 +68,7 @@ func (h *Handler) health(w http.ResponseWriter, r *http.Request) {
"service": "streamd",
"uptime_s": time.Since(h.StartedAt).Seconds(),
"started_at": h.StartedAt.UTC().Format(time.RFC3339),
"deps": h.Deps,
})
}
@ -310,8 +315,8 @@ func writeErr(w http.ResponseWriter, code int, msg string) {
writeJSON(w, code, map[string]any{"error": msg})
}
// credentialsChanged is true when the patch touched mpd, key, or headers that
// the live NRE/ffmpeg worker is already using.
// credentialsChanged is true when the patch touched mpd, key, headers, or proxy
// that the live NRE/ffmpeg worker is already using.
func credentialsChanged(before, after db.Stream, in db.PatchStream) bool {
if in.MPD != nil && strings.TrimSpace(before.MPD) != strings.TrimSpace(after.MPD) {
return true
@ -322,5 +327,8 @@ func credentialsChanged(before, after db.Stream, in db.PatchStream) bool {
if in.HeadersJSON != nil && strings.TrimSpace(before.HeadersJSON) != strings.TrimSpace(after.HeadersJSON) {
return true
}
if in.Proxy != nil && strings.TrimSpace(before.Proxy) != strings.TrimSpace(after.Proxy) {
return true
}
return false
}

View file

@ -0,0 +1,157 @@
package api
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"io"
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"drmdecryption/modhost"
"drmdecryption/repo"
)
// 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"`
}
var moduleNameRe = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$`)
func (h *Handler) modules(w http.ResponseWriter, r *http.Request) {
path := strings.TrimPrefix(r.URL.Path, "/api/modules")
path = strings.Trim(path, "/")
switch {
case path == "" && r.Method == http.MethodGet:
h.listModules(w, r)
case path != "" && !strings.Contains(path, "/") && r.Method == http.MethodGet:
h.getModule(w, r, path)
case path != "" && !strings.Contains(path, "/") && r.Method == http.MethodPut:
h.putModule(w, r, path)
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)
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})
}
func (h *Handler) getModule(w http.ResponseWriter, r *http.Request, name string) {
if !moduleNameRe.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)
}
func (h *Handler) putModule(w http.ResponseWriter, r *http.Request, name string) {
if !h.auth(w, r) {
return
}
if !moduleNameRe.MatchString(name) {
writeErr(w, http.StatusBadRequest, "invalid module name")
return
}
body, err := io.ReadAll(io.LimitReader(r.Body, 2<<20))
if err != nil {
writeErr(w, http.StatusBadRequest, err.Error())
return
}
defer r.Body.Close()
yamlBytes, err := extractModuleYAML(r.Header.Get("Content-Type"), body)
if err != nil {
writeErr(w, http.StatusBadRequest, err.Error())
return
}
if len(strings.TrimSpace(string(yamlBytes))) == 0 {
writeErr(w, http.StatusBadRequest, "empty module.yaml")
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)
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
}
sum := sha256.Sum256(b)
info.HasYAML = true
info.YAMLSHA256 = hex.EncodeToString(sum[:])
return info
}
// extractModuleYAML accepts raw YAML or JSON {"yaml":"..."}.
func extractModuleYAML(contentType string, body []byte) ([]byte, error) {
ct := strings.ToLower(strings.TrimSpace(strings.Split(contentType, ";")[0]))
switch ct {
case "application/json", "text/json":
var wrap struct {
YAML string `json:"yaml"`
}
if err := json.Unmarshal(body, &wrap); err != nil {
return nil, err
}
if strings.TrimSpace(wrap.YAML) == "" {
return nil, errors.New("empty yaml field")
}
return []byte(wrap.YAML), nil
default:
// text/yaml, application/x-yaml, or bare body
return body, nil
}
}