mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-09-19 08:23:03 +00:00
enhancements
This commit is contained in:
parent
10025ffa66
commit
3ac1d7f546
3 changed files with 19 additions and 24 deletions
|
@ -3,6 +3,7 @@ package sub
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"strings"
|
"strings"
|
||||||
|
"x-ui/config"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
@ -67,10 +68,6 @@ func (a *SUBController) subs(c *gin.Context) {
|
||||||
result += sub + "\n"
|
result += sub + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add headers via service
|
|
||||||
a.subService.ApplyCommonHeaders(c, header, a.updateInterval, a.subTitle)
|
|
||||||
a.subService.ApplyBase64ContentHeader(c, result)
|
|
||||||
|
|
||||||
// If the request expects HTML (e.g., browser) or explicitly asked (?html=1 or ?view=html), render the info page here
|
// If the request expects HTML (e.g., browser) or explicitly asked (?html=1 or ?view=html), render the info page here
|
||||||
accept := c.GetHeader("Accept")
|
accept := c.GetHeader("Accept")
|
||||||
if strings.Contains(strings.ToLower(accept), "text/html") || c.Query("html") == "1" || strings.EqualFold(c.Query("view"), "html") {
|
if strings.Contains(strings.ToLower(accept), "text/html") || c.Query("html") == "1" || strings.EqualFold(c.Query("view"), "html") {
|
||||||
|
@ -79,6 +76,7 @@ func (a *SUBController) subs(c *gin.Context) {
|
||||||
page := a.subService.BuildPageData(subId, hostHeader, header, lastOnline, subs, subURL, subJsonURL)
|
page := a.subService.BuildPageData(subId, hostHeader, header, lastOnline, subs, subURL, subJsonURL)
|
||||||
c.HTML(200, "subscription.html", gin.H{
|
c.HTML(200, "subscription.html", gin.H{
|
||||||
"title": "subscription.title",
|
"title": "subscription.title",
|
||||||
|
"cur_ver": config.GetVersion(),
|
||||||
"host": page.Host,
|
"host": page.Host,
|
||||||
"base_path": page.BasePath,
|
"base_path": page.BasePath,
|
||||||
"sId": page.SId,
|
"sId": page.SId,
|
||||||
|
@ -100,6 +98,9 @@ func (a *SUBController) subs(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add headers
|
||||||
|
a.ApplyCommonHeaders(c, header, a.updateInterval, a.subTitle)
|
||||||
|
|
||||||
if a.subEncrypt {
|
if a.subEncrypt {
|
||||||
c.String(200, base64.StdEncoding.EncodeToString([]byte(result)))
|
c.String(200, base64.StdEncoding.EncodeToString([]byte(result)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,11 +117,15 @@ func (a *SUBController) subJsons(c *gin.Context) {
|
||||||
c.String(400, "Error!")
|
c.String(400, "Error!")
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Add headers via service
|
// Add headers
|
||||||
a.subService.ApplyCommonHeaders(c, header, a.updateInterval, a.subTitle)
|
a.ApplyCommonHeaders(c, header, a.updateInterval, a.subTitle)
|
||||||
|
|
||||||
c.String(200, jsonSub)
|
c.String(200, jsonSub)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: host parsing and page data preparation moved to SubService
|
func (a *SUBController) ApplyCommonHeaders(c *gin.Context, header, updateInterval, profileTitle string) {
|
||||||
|
c.Writer.Header().Set("Subscription-Userinfo", header)
|
||||||
|
c.Writer.Header().Set("Profile-Update-Interval", updateInterval)
|
||||||
|
c.Writer.Header().Set("Profile-Title", "base64:"+base64.StdEncoding.EncodeToString([]byte(profileTitle)))
|
||||||
|
}
|
||||||
|
|
|
@ -1178,15 +1178,3 @@ func parseInt64(s string) (int64, error) {
|
||||||
n, err := strconv.ParseInt(s, 10, 64)
|
n, err := strconv.ParseInt(s, 10, 64)
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyCommonHeaders sets standard subscription headers on the response writer.
|
|
||||||
func (s *SubService) ApplyCommonHeaders(c *gin.Context, header, updateInterval, profileTitle string) {
|
|
||||||
c.Writer.Header().Set("Subscription-Userinfo", header)
|
|
||||||
c.Writer.Header().Set("Profile-Update-Interval", updateInterval)
|
|
||||||
c.Writer.Header().Set("Profile-Title", "base64:"+base64.StdEncoding.EncodeToString([]byte(profileTitle)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyBase64ContentHeader adds the full subscription content as base64 header for convenience.
|
|
||||||
func (s *SubService) ApplyBase64ContentHeader(c *gin.Context, content string) {
|
|
||||||
c.Writer.Header().Set("Subscription-Content-Base64", base64.StdEncoding.EncodeToString([]byte(content)))
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
{{ template "page/head_start" .}}
|
{{ template "page/head_start" .}}
|
||||||
|
<script src="{{ .base_path }}assets/moment/moment.min.js"></script>
|
||||||
|
<script src="{{ .base_path }}assets/moment/moment-jalali.min.js?{{ .cur_ver }}"></script>
|
||||||
|
<script src="{{ .base_path }}assets/vue/vue.min.js?{{ .cur_ver }}"></script>
|
||||||
|
<script src="{{ .base_path }}assets/ant-design-vue/antd.min.js"></script>
|
||||||
|
<script src="{{ .base_path }}assets/js/util/index.js?{{ .cur_ver }}"></script>
|
||||||
|
<script src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script>
|
||||||
{{ template "page/head_end" .}}
|
{{ template "page/head_end" .}}
|
||||||
|
|
||||||
{{ template "page/body_start" .}}
|
{{ template "page/body_start" .}}
|
||||||
|
@ -262,11 +268,7 @@
|
||||||
style="display:none">{{ range .result }}{{ . }}
|
style="display:none">{{ range .result }}{{ . }}
|
||||||
{{ end }}</textarea>
|
{{ end }}</textarea>
|
||||||
|
|
||||||
{{template "page/body_scripts" .}}
|
|
||||||
<script
|
|
||||||
src="{{ .base_path }}assets/moment/moment-jalali.min.js?{{ .cur_ver }}"></script>
|
|
||||||
<script
|
|
||||||
src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script>
|
|
||||||
{{template "component/aThemeSwitch" .}}
|
{{template "component/aThemeSwitch" .}}
|
||||||
<script src="{{ .base_path }}assets/js/subscription.js?{{ .cur_ver }}"></script>
|
<script src="{{ .base_path }}assets/js/subscription.js?{{ .cur_ver }}"></script>
|
||||||
|
|
||||||
{{ template "page/body_end" .}}
|
{{ template "page/body_end" .}}
|
Loading…
Reference in a new issue