chore: update gotask to 1.0.3

This commit is contained in:
langhuihui
2025-11-26 11:15:11 +08:00
parent 9d5c01d3a0
commit b25fa38a6d
6 changed files with 36 additions and 12 deletions

2
go.mod
View File

@@ -25,7 +25,7 @@ require (
github.com/icholy/digest v1.1.0
github.com/jinzhu/copier v0.4.0
github.com/kerberos-io/onvif v1.0.0
github.com/langhuihui/gotask v1.0.2
github.com/langhuihui/gotask v1.0.3
github.com/mark3labs/mcp-go v0.27.0
github.com/mattn/go-sqlite3 v1.14.24
github.com/mcuadros/go-defaults v1.2.0

4
go.sum
View File

@@ -152,8 +152,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/langhuihui/gomem v0.0.0-20251001011839-023923cf7683 h1:lITBgMb71ad6OUU9gycsheCw9PpMbXy3/QA8T0V0dVM=
github.com/langhuihui/gomem v0.0.0-20251001011839-023923cf7683/go.mod h1:BTPq1+4YUP4i7w8VHzs5AUIdn3T5gXjIUXbxgHW9TIQ=
github.com/langhuihui/gotask v1.0.2 h1:vcQ/9yD0+x2DkSrDBkYpufOyJxXs7i5fd7wUD8gvLLs=
github.com/langhuihui/gotask v1.0.2/go.mod h1:2zNqwV8M1pHoO0b5JC/A37oYpdtXrfL10Qof9AvR5IE=
github.com/langhuihui/gotask v1.0.3 h1:QiL0YDkvJVPp44KkFYcTcj/GkYjGPW+0WxR0N/j1/JE=
github.com/langhuihui/gotask v1.0.3/go.mod h1:2zNqwV8M1pHoO0b5JC/A37oYpdtXrfL10Qof9AvR5IE=
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 h1:6Yzfa6GP0rIo/kULo2bwGEkFvCePZ3qHDDTC3/J9Swo=
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80/go.mod h1:imJHygn/1yfhB7XSJJKlFZKl/J+dCPAknuiaGOshXAs=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=

View File

@@ -47,12 +47,12 @@ func (plugin *FLVPlugin) Start() (err error) {
}
func (plugin *FLVPlugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
rawPath := strings.TrimPrefix(r.URL.Path, "/")
if plugin.Server != nil && plugin.Server.RedirectIfNeeded(w, r, "http", rawPath) {
plugin.Debug("redirect issued", "protocol", "http", "path", rawPath)
redirectPath := strings.TrimPrefix(r.URL.Path, "/")
if plugin.Server != nil && plugin.Server.RedirectIfNeeded(w, r, "flv", redirectPath) {
plugin.Debug("redirect issued", "protocol", "http", "path", redirectPath)
return
}
streamPath := strings.TrimSuffix(rawPath, ".flv")
streamPath := strings.TrimSuffix(redirectPath, ".flv")
var err error
defer func() {
if err != nil {

View File

@@ -208,7 +208,7 @@ func (config *HLSPlugin) vod(w http.ResponseWriter, r *http.Request) {
func (config *HLSPlugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
redirectPath := strings.TrimPrefix(r.URL.Path, "/")
if config.Server.RedirectIfNeeded(w, r, "http", redirectPath) {
if config.Server.RedirectIfNeeded(w, r, "hls", redirectPath) {
config.Debug("redirect issued", "protocol", "http", "path", redirectPath)
return
}

View File

@@ -99,7 +99,7 @@ func (p *MP4Plugin) Start() (err error) {
func (p *MP4Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
redirectPath := strings.TrimPrefix(r.URL.Path, "/")
if p.Server != nil && p.Server.RedirectIfNeeded(w, r, "http", redirectPath) {
if p.Server != nil && p.Server.RedirectIfNeeded(w, r, "mp4", redirectPath) {
p.Debug("redirect issued", "protocol", "http", "path", redirectPath)
return
}

View File

@@ -34,7 +34,10 @@ func (s *Server) GetRedirectAdvisor() RedirectAdvisor {
}
// RedirectIfNeeded evaluates redirect advice for HTTP-based protocols and issues redirects when appropriate.
func (s *Server) RedirectIfNeeded(w http.ResponseWriter, r *http.Request, protocol, redirectPath string) bool {
// The prefix parameter is the plugin name (e.g., "flv", "mp4", "hls", "webrtc") used to restore the path prefix.
// The redirectPath parameter is the stream path without prefix, used for matching redirect rules.
// This function automatically restores the path prefix (e.g., /flv/, /mp4/) for building the redirect URL.
func (s *Server) RedirectIfNeeded(w http.ResponseWriter, r *http.Request, prefix, redirectPath string) bool {
if s == nil {
return false
}
@@ -42,13 +45,35 @@ func (s *Server) RedirectIfNeeded(w http.ResponseWriter, r *http.Request, protoc
if advisor == nil {
return false
}
targetHost, statusCode, ok := advisor.GetRedirectTarget(protocol, redirectPath, r.Host)
// Save current path and restore it with the prefix for building redirect URL
currentPath := r.URL.Path
pathRestored := false
// Restore path with prefix if needed
if prefix != "" {
pathPrefix := "/" + prefix + "/"
if !strings.HasPrefix(currentPath, pathPrefix) {
r.URL.Path = pathPrefix + redirectPath
pathRestored = true
}
}
// Restore original path after redirect (if it was modified)
defer func() {
if pathRestored {
r.URL.Path = currentPath
}
}()
targetHost, statusCode, ok := advisor.GetRedirectTarget(prefix, redirectPath, r.Host)
if !ok || targetHost == "" {
return false
}
if statusCode == 0 {
statusCode = http.StatusFound
}
// Use r.URL.Path (which has been restored with prefix) to build redirect URL
redirectURL := buildRedirectURL(r, targetHost)
http.Redirect(w, r, redirectURL, statusCode)
return true
@@ -183,4 +208,3 @@ func (s *Server) annexB(w http.ResponseWriter, r *http.Request) {
return ctx.Flush()
})
}