From b74b55fa4aa71ea0259d2f79c9d8e0870e335384 Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Sat, 17 Sep 2022 21:33:39 +0800 Subject: [PATCH] feat: support custom `bundle-identifier` by filename --- server/handles/helper.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/server/handles/helper.go b/server/handles/helper.go index 230a0d2c..57b92b73 100644 --- a/server/handles/helper.go +++ b/server/handles/helper.go @@ -10,7 +10,6 @@ import ( "github.com/alist-org/alist/v3/internal/setting" "github.com/alist-org/alist/v3/server/common" "github.com/gin-gonic/gin" - log "github.com/sirupsen/logrus" ) func Favicon(c *gin.Context) { @@ -38,10 +37,18 @@ func Plist(c *gin.Context) { common.ErrorResp(c, err, 500) return } - name := c.Param("name") - log.Debug("name", name) + fullName := c.Param("name") Url := uUrl.String() - name = strings.TrimSuffix(name, ".plist") + fullName = strings.TrimSuffix(fullName, ".plist") + name := fullName + identifier := fmt.Sprintf("ci.nn.%s", url.PathEscape(fullName)) + + if strings.Contains(fullName, "_") { + ss := strings.Split(fullName, "_") + name = strings.Join(ss[:len(ss)-1], "_") + identifier = ss[len(ss)-1] + } + name = strings.ReplaceAll(name, "<", "[") name = strings.ReplaceAll(name, ">", "]") plist := fmt.Sprintf(` @@ -56,13 +63,13 @@ func Plist(c *gin.Context) { kind software-package url - %s + metadata bundle-identifier - ci.nn.%s + %s bundle-version 4.4 kind @@ -73,7 +80,7 @@ func Plist(c *gin.Context) { -`, Url, url.PathEscape(name), name) +`, Url, identifier, name) c.Header("Content-Type", "application/xml;charset=utf-8") c.Status(200) _, _ = c.Writer.WriteString(plist)