diff options
Diffstat (limited to 'sub')
| -rw-r--r-- | sub/sub.go | 8 | ||||
| -rw-r--r-- | sub/subController.go | 13 |
2 files changed, 17 insertions, 4 deletions
@@ -85,6 +85,12 @@ func (s *Server) initRouter() (*gin.Engine, error) { return nil, err } + // Determine if JSON subscription endpoint is enabled + subJsonEnable, err := s.settingService.GetSubJsonEnable() + if err != nil { + return nil, err + } + // Set base_path based on LinksPath for template rendering engine.Use(func(c *gin.Context) { c.Set("base_path", LinksPath) @@ -186,7 +192,7 @@ func (s *Server) initRouter() (*gin.Engine, error) { g := engine.Group("/") s.sub = NewSUBController( - g, LinksPath, JsonPath, Encrypt, ShowInfo, RemarkModel, SubUpdates, + g, LinksPath, JsonPath, subJsonEnable, Encrypt, ShowInfo, RemarkModel, SubUpdates, SubJsonFragment, SubJsonNoises, SubJsonMux, SubJsonRules, SubTitle) return engine, nil diff --git a/sub/subController.go b/sub/subController.go index 170cfa74..b29d019e 100644 --- a/sub/subController.go +++ b/sub/subController.go @@ -13,6 +13,7 @@ type SUBController struct { subTitle string subPath string subJsonPath string + jsonEnabled bool subEncrypt bool updateInterval string @@ -24,6 +25,7 @@ func NewSUBController( g *gin.RouterGroup, subPath string, jsonPath string, + jsonEnabled bool, encrypt bool, showInfo bool, rModel string, @@ -39,6 +41,7 @@ func NewSUBController( subTitle: subTitle, subPath: subPath, subJsonPath: jsonPath, + jsonEnabled: jsonEnabled, subEncrypt: encrypt, updateInterval: update, @@ -51,10 +54,11 @@ func NewSUBController( func (a *SUBController) initRouter(g *gin.RouterGroup) { gLink := g.Group(a.subPath) - gJson := g.Group(a.subJsonPath) - gLink.GET(":subid", a.subs) - gJson.GET(":subid", a.subJsons) + if a.jsonEnabled { + gJson := g.Group(a.subJsonPath) + gJson.GET(":subid", a.subJsons) + } } func (a *SUBController) subs(c *gin.Context) { @@ -74,6 +78,9 @@ func (a *SUBController) subs(c *gin.Context) { if strings.Contains(strings.ToLower(accept), "text/html") || c.Query("html") == "1" || strings.EqualFold(c.Query("view"), "html") { // Build page data in service subURL, subJsonURL := a.subService.BuildURLs(scheme, hostWithPort, a.subPath, a.subJsonPath, subId) + if !a.jsonEnabled { + subJsonURL = "" + } page := a.subService.BuildPageData(subId, hostHeader, traffic, lastOnline, subs, subURL, subJsonURL) c.HTML(200, "subpage.html", gin.H{ "title": "subscription.title", |
