streamd: optional keys, per-stream proxy, auto deps; agent module.yaml sync; RTE AutoPlay; Telegram release announces
- 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:
parent
f9c28be3f1
commit
ac8701b5a6
36 changed files with 1460 additions and 143 deletions
121
apps/agent/internal/modsync/sync.go
Normal file
121
apps/agent/internal/modsync/sync.go
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
// Package modsync pushes local modules/<name>/module.yaml to streamd
|
||||
// when the remote copy is missing or the SHA-256 differs.
|
||||
package modsync
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"drmdecryption/apps/agent/internal/client"
|
||||
"drmdecryption/modhost"
|
||||
"drmdecryption/repo"
|
||||
)
|
||||
|
||||
// Syncer compares local module.yaml files to streamd and PUTs updates.
|
||||
type Syncer struct {
|
||||
API *client.Client
|
||||
ModulesDir string // empty = modhost.ModulesDir(repo.Root())
|
||||
Interval time.Duration
|
||||
Log *log.Logger
|
||||
}
|
||||
|
||||
func (s *Syncer) modulesDir() string {
|
||||
if strings.TrimSpace(s.ModulesDir) != "" {
|
||||
return s.ModulesDir
|
||||
}
|
||||
return modhost.ModulesDir(repo.Root())
|
||||
}
|
||||
|
||||
// Once uploads every local module.yaml that is missing or stale on streamd.
|
||||
func (s *Syncer) Once() error {
|
||||
dir := s.modulesDir()
|
||||
ents, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
s.logf("modules sync: no local dir %s", dir)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
remote, err := s.API.ListModules()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
byName := make(map[string]client.ModuleInfo, len(remote))
|
||||
for _, m := range remote {
|
||||
byName[m.Name] = m
|
||||
}
|
||||
|
||||
for _, e := range ents {
|
||||
if !e.IsDir() || strings.HasPrefix(e.Name(), ".") {
|
||||
continue
|
||||
}
|
||||
name := e.Name()
|
||||
yamlPath := filepath.Join(dir, name, "module.yaml")
|
||||
raw, err := os.ReadFile(yamlPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
s.logf("modules sync: read %s: %v", yamlPath, err)
|
||||
continue
|
||||
}
|
||||
sum := sha256.Sum256(raw)
|
||||
localSHA := hex.EncodeToString(sum[:])
|
||||
rm, ok := byName[name]
|
||||
if ok && rm.HasYAML && strings.EqualFold(rm.YAMLSHA256, localSHA) {
|
||||
continue
|
||||
}
|
||||
if err := s.API.PutModuleYAML(name, raw); err != nil {
|
||||
s.logf("modules sync: PUT %s: %v", name, err)
|
||||
continue
|
||||
}
|
||||
if !ok || !rm.HasYAML {
|
||||
s.logf("modules sync: uploaded %s (new)", name)
|
||||
} else {
|
||||
s.logf("modules sync: updated %s", name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Loop runs Once immediately, then on Interval until stop closes.
|
||||
func (s *Syncer) Loop(stop <-chan struct{}) {
|
||||
interval := s.Interval
|
||||
if interval <= 0 {
|
||||
interval = 5 * time.Minute
|
||||
}
|
||||
_ = s.runLogged()
|
||||
t := time.NewTicker(interval)
|
||||
defer t.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
return
|
||||
case <-t.C:
|
||||
_ = s.runLogged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Syncer) runLogged() error {
|
||||
if err := s.Once(); err != nil {
|
||||
s.logf("modules sync error: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Syncer) logf(format string, args ...any) {
|
||||
if s.Log != nil {
|
||||
s.Log.Printf(format, args...)
|
||||
return
|
||||
}
|
||||
log.Printf(format, args...)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue