From 1ffb868fcbf8a6eb68dfdcae9b750f967f124898 Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Tue, 27 Apr 2021 11:38:40 +0300 Subject: [PATCH] add scheme to list --- server/utils/location.go | 14 ++++++++++++++ server/web/api/m3u.go | 8 ++++---- server/web/api/stream.go | 5 +++-- server/web/server.go | 3 ++- 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 server/utils/location.go diff --git a/server/utils/location.go b/server/utils/location.go new file mode 100644 index 0000000..24f600e --- /dev/null +++ b/server/utils/location.go @@ -0,0 +1,14 @@ +package utils + +import ( + "github.com/gin-contrib/location" + "github.com/gin-gonic/gin" +) + +func GetScheme(c *gin.Context) string { + url := location.Get(c) + if url == nil { + return "http" + } + return url.Scheme +} diff --git a/server/web/api/m3u.go b/server/web/api/m3u.go index d198e38..3252151 100644 --- a/server/web/api/m3u.go +++ b/server/web/api/m3u.go @@ -10,13 +10,13 @@ import ( "strings" "time" + "github.com/anacrolix/missinggo/httptoo" + sets "server/settings" "server/torr" "server/torr/state" "server/utils" - "github.com/anacrolix/missinggo/httptoo" - "github.com/gin-gonic/gin" "github.com/pkg/errors" ) @@ -24,7 +24,7 @@ import ( func allPlayList(c *gin.Context) { torrs := torr.ListTorrent() - host := "http://" + c.Request.Host + host := utils.GetScheme(c) + "://" + c.Request.Host list := "#EXTM3U\n" hash := "" // fn=file.m3u fix forkplayer bug with end .m3u in link @@ -61,7 +61,7 @@ func playList(c *gin.Context) { } } - host := "http://" + c.Request.Host + host := utils.GetScheme(c) + "://" + c.Request.Host list := getM3uList(tor.Status(), host, fromlast) list = "#EXTM3U\n" + list diff --git a/server/web/api/stream.go b/server/web/api/stream.go index 65253f2..ff3226c 100644 --- a/server/web/api/stream.go +++ b/server/web/api/stream.go @@ -7,6 +7,7 @@ import ( "server/torr" "server/torr/state" + utils2 "server/utils" "server/web/api/utils" "github.com/gin-gonic/gin" @@ -119,7 +120,7 @@ func stream(c *gin.Context) { } else // return m3u if query if m3u { - m3ulist := "#EXTM3U\n" + getM3uList(tor.Status(), "http://"+c.Request.Host, fromlast) + m3ulist := "#EXTM3U\n" + getM3uList(tor.Status(), utils2.GetScheme(c)+"://"+c.Request.Host, fromlast) sendM3U(c, tor.Name()+".m3u", tor.Hash().HexString(), m3ulist) return } else @@ -199,7 +200,7 @@ func streamNoAuth(c *gin.Context) { // return m3u if query if m3u { - m3ulist := "#EXTM3U\n" + getM3uList(tor.Status(), "http://"+c.Request.Host, fromlast) + m3ulist := "#EXTM3U\n" + getM3uList(tor.Status(), utils2.GetScheme(c)+"://"+c.Request.Host, fromlast) sendM3U(c, tor.Name()+".m3u", tor.Hash().HexString(), m3ulist) return } else diff --git a/server/web/server.go b/server/web/server.go index f679b1d..5468854 100644 --- a/server/web/server.go +++ b/server/web/server.go @@ -4,6 +4,7 @@ import ( "net" "github.com/gin-contrib/cors" + "github.com/gin-contrib/location" "github.com/gin-gonic/gin" "server/log" @@ -38,7 +39,7 @@ func Start(port string) { corsCfg.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "X-Requested-With", "Accept", "Authorization"} route := gin.New() - route.Use(log.WebLogger(), blocker.Blocker(), gin.Recovery(), cors.New(corsCfg)) + route.Use(log.WebLogger(), blocker.Blocker(), gin.Recovery(), cors.New(corsCfg), location.Default()) route.GET("/echo", echo)