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
|
|
@ -85,6 +85,50 @@ func (c *Client) PostCredentials(id int64, cred Credentials) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// ModuleInfo is one modules/<name>/ entry from GET /api/modules.
|
||||
type ModuleInfo struct {
|
||||
Name string `json:"name"`
|
||||
HasYAML bool `json:"has_yaml"`
|
||||
YAMLSHA256 string `json:"yaml_sha256,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) ListModules() ([]ModuleInfo, error) {
|
||||
body, err := c.do(http.MethodGet, "/api/modules", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var wrap struct {
|
||||
Modules []ModuleInfo `json:"modules"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &wrap); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wrap.Modules, nil
|
||||
}
|
||||
|
||||
// PutModuleYAML uploads raw module.yaml bytes for name (Content-Type text/yaml).
|
||||
func (c *Client) PutModuleYAML(name string, yamlBytes []byte) error {
|
||||
req, err := http.NewRequest(http.MethodPut, c.BaseURL+"/api/modules/"+name, bytes.NewReader(yamlBytes))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "text/yaml")
|
||||
req.Header.Set("User-Agent", c.UserAgent)
|
||||
if c.Token != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+c.Token)
|
||||
}
|
||||
resp, err := c.HTTP.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
if resp.StatusCode >= 300 {
|
||||
return fmt.Errorf("PUT /api/modules/%s: %s — %s", name, resp.Status, strings.TrimSpace(string(body)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) do(method, path string, payload any) ([]byte, error) {
|
||||
var rdr io.Reader
|
||||
if payload != nil {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ type Config struct {
|
|||
WVD string `yaml:"wvd"` // path to .wvd device file (required for key fetch)
|
||||
UserAgent string `yaml:"user_agent"`
|
||||
AgentID string `yaml:"agent_id"`
|
||||
// SyncModules pushes local modules/<name>/module.yaml to streamd when missing/stale.
|
||||
SyncModules bool `yaml:"sync_modules"`
|
||||
ModulesDir string `yaml:"modules_dir"` // empty = repo modules/
|
||||
ModulesSyncIntervalSec int `yaml:"modules_sync_interval_sec"`
|
||||
}
|
||||
|
||||
func (c Config) PollInterval() time.Duration {
|
||||
|
|
@ -100,5 +104,18 @@ func applyDefaults(cfg Config, root string) Config {
|
|||
if cfg.WVD != "" && !filepath.IsAbs(cfg.WVD) {
|
||||
cfg.WVD = filepath.Join(root, cfg.WVD)
|
||||
}
|
||||
if cfg.ModulesDir != "" && !filepath.IsAbs(cfg.ModulesDir) {
|
||||
cfg.ModulesDir = filepath.Join(root, cfg.ModulesDir)
|
||||
}
|
||||
if cfg.ModulesSyncIntervalSec <= 0 {
|
||||
cfg.ModulesSyncIntervalSec = 300
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (c Config) ModulesSyncInterval() time.Duration {
|
||||
if c.ModulesSyncIntervalSec <= 0 {
|
||||
return 5 * time.Minute
|
||||
}
|
||||
return time.Duration(c.ModulesSyncIntervalSec) * time.Second
|
||||
}
|
||||
|
|
|
|||
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