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
|
|
@ -5,6 +5,7 @@ import (
|
|||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -27,22 +28,28 @@ type Primer interface {
|
|||
type LocalServer struct {
|
||||
URL string
|
||||
Upstream string
|
||||
Key string // KID:KEY
|
||||
Key string // KID:KEY (optional for clear streams)
|
||||
Headers map[string]string
|
||||
Proxy string // optional socks5:// or http:// for upstream fetch
|
||||
|
||||
rw Rewriter
|
||||
kidHint string
|
||||
ln net.Listener
|
||||
httpServer *http.Server
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
// StartLocal starts the rewrite proxy. rw must not be nil; pass Passthrough{}
|
||||
// to serve upstream unchanged.
|
||||
func StartLocal(upstream, key string, headers map[string]string, rw Rewriter) (*LocalServer, error) {
|
||||
// to serve upstream unchanged. proxyURL may be empty, or socks5:// / http://.
|
||||
func StartLocal(upstream, key string, headers map[string]string, rw Rewriter, proxyURL ...string) (*LocalServer, error) {
|
||||
if rw == nil {
|
||||
rw = Passthrough{}
|
||||
}
|
||||
s := &LocalServer{Upstream: upstream, Key: key, Headers: headers, rw: rw}
|
||||
proxy := ""
|
||||
if len(proxyURL) > 0 {
|
||||
proxy = strings.TrimSpace(proxyURL[0])
|
||||
}
|
||||
s := &LocalServer{Upstream: upstream, Key: key, Headers: headers, Proxy: proxy, rw: rw}
|
||||
if key != "" && strings.Contains(key, ":") {
|
||||
s.kidHint = strings.SplitN(key, ":", 2)[0]
|
||||
if r, ok := rw.(KIDResolver); ok {
|
||||
|
|
@ -53,6 +60,11 @@ func StartLocal(upstream, key string, headers map[string]string, rw Rewriter) (*
|
|||
}
|
||||
}
|
||||
}
|
||||
client, err := httpClientWithProxy(proxy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.client = client
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -66,6 +78,18 @@ func StartLocal(upstream, key string, headers map[string]string, rw Rewriter) (*
|
|||
return s, nil
|
||||
}
|
||||
|
||||
func httpClientWithProxy(proxyURL string) (*http.Client, error) {
|
||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
if proxyURL != "" {
|
||||
u, err := url.Parse(proxyURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("proxy URL: %w", err)
|
||||
}
|
||||
transport.Proxy = http.ProxyURL(u)
|
||||
}
|
||||
return &http.Client{Timeout: 20 * time.Second, Transport: transport}, nil
|
||||
}
|
||||
|
||||
func (s *LocalServer) Close() {
|
||||
if s.httpServer != nil {
|
||||
_ = s.httpServer.Close()
|
||||
|
|
@ -82,7 +106,10 @@ func (s *LocalServer) handle(w http.ResponseWriter, r *http.Request) {
|
|||
for k, v := range s.Headers {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
client := &http.Client{Timeout: 20 * time.Second}
|
||||
client := s.client
|
||||
if client == nil {
|
||||
client = &http.Client{Timeout: 20 * time.Second}
|
||||
}
|
||||
if resp, err := client.Do(req); err == nil {
|
||||
b, _ := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
|
||||
_ = resp.Body.Close()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue