From 1f254951fa7c34cf6efbf90ad65fb96cc68013f8 Mon Sep 17 00:00:00 2001 From: Ian Jessen Date: Fri, 3 Jan 2025 15:13:51 -0500 Subject: [PATCH] add PlaybackBaseURL --- internal/conf/conf.go | 10 ++++++++++ internal/core/core.go | 1 + internal/playback/on_list.go | 17 ++++++++++++----- internal/playback/server.go | 1 + 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/internal/conf/conf.go b/internal/conf/conf.go index bc1e13c2a20..9536eb1e8cf 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -209,6 +209,7 @@ type Conf struct { // Playback Playback bool `json:"playback"` PlaybackAddress string `json:"playbackAddress"` + PlaybackBaseUrl string `json:"playbackBaseUrl"` PlaybackEncryption bool `json:"playbackEncryption"` PlaybackServerKey string `json:"playbackServerKey"` PlaybackServerCert string `json:"playbackServerCert"` @@ -350,6 +351,7 @@ func (conf *Conf) setDefaults() { // Playback server conf.PlaybackAddress = ":9996" + conf.PlaybackBaseUrl = "" conf.PlaybackServerKey = "server.key" conf.PlaybackServerCert = "server.crt" conf.PlaybackAllowOrigin = "*" @@ -641,6 +643,14 @@ func (conf *Conf) Validate(l logger.Writer) error { conf.RTSPServerKey = *conf.ServerKey } + // Playback + + if conf.PlaybackBaseUrl != "" && + !strings.HasPrefix(conf.PlaybackBaseUrl, "http://") && + !strings.HasPrefix(conf.PlaybackBaseUrl, "https://") { + return fmt.Errorf("'playbackBaseUrl' must be a HTTP(S) URL") + } + // RTMP if conf.RTMPDisable != nil { diff --git a/internal/core/core.go b/internal/core/core.go index 976173e4095..3bf078f40e3 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -318,6 +318,7 @@ func (p *Core) createResources(initial bool) error { p.playbackServer == nil { i := &playback.Server{ Address: p.conf.PlaybackAddress, + BaseUrl: p.conf.PlaybackBaseUrl, Encryption: p.conf.PlaybackEncryption, ServerKey: p.conf.PlaybackServerKey, ServerCert: p.conf.PlaybackServerCert, diff --git a/internal/playback/on_list.go b/internal/playback/on_list.go index 4a44c46b511..c84c0ee399a 100644 --- a/internal/playback/on_list.go +++ b/internal/playback/on_list.go @@ -212,12 +212,19 @@ func (s *Server) onList(ctx *gin.Context) { v.Add("path", pathName) v.Add("start", entries[i].Start.Format(time.RFC3339Nano)) v.Add("duration", strconv.FormatFloat(time.Duration(entries[i].Duration).Seconds(), 'f', -1, 64)) - u := &url.URL{ - Scheme: scheme, - Host: ctx.Request.Host, - Path: "/get", - RawQuery: v.Encode(), + + var u *url.URL + if s.BaseUrl != "" { + u, _ = url.Parse(s.BaseUrl) + u = u.JoinPath("get") + } else { + u = &url.URL{ + Scheme: scheme, + Host: ctx.Request.Host, + Path: "/get", + } } + u.RawQuery = v.Encode() entries[i].URL = u.String() } diff --git a/internal/playback/server.go b/internal/playback/server.go index 7874e49d40c..eb8f66bdc2a 100644 --- a/internal/playback/server.go +++ b/internal/playback/server.go @@ -22,6 +22,7 @@ type serverAuthManager interface { // Server is the playback server. type Server struct { Address string + BaseUrl string Encryption bool ServerKey string ServerCert string