From 5ab5cc327f4770c3144536ed846a7331dd8341ca Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Sun, 28 Aug 2022 15:23:00 +0800 Subject: [PATCH] feat: generate plist for ipa --- server/handles/helper.go | 69 ++++++++++++++++++++++++++++++++++++++++ server/router.go | 2 ++ 2 files changed, 71 insertions(+) create mode 100644 server/handles/helper.go diff --git a/server/handles/helper.go b/server/handles/helper.go new file mode 100644 index 00000000000..09e450abaa7 --- /dev/null +++ b/server/handles/helper.go @@ -0,0 +1,69 @@ +package handles + +import ( + "fmt" + "github.com/alist-org/alist/v3/internal/conf" + "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" + "net/url" + "strings" +) + +func Favicon(c *gin.Context) { + c.Redirect(302, setting.GetByKey(conf.Favicon)) +} + +func Plist(c *gin.Context) { + link := c.Param("link") + u, err := url.PathUnescape(link) + if err != nil { + common.ErrorResp(c, err, 500) + return + } + uUrl, err := url.Parse(u) + if err != nil { + common.ErrorResp(c, err, 500) + return + } + name := c.Param("name") + log.Debug("name", name) + u = uUrl.String() + name = strings.TrimSuffix(name, ".plist") + name = strings.ReplaceAll(name, "<", "[") + name = strings.ReplaceAll(name, ">", "]") + plist := fmt.Sprintf(` + + + items + + + assets + + + kind + software-package + url + %s + + + metadata + + bundle-identifier + ci.nn.%s + bundle-version + 4.4 + kind + software + title + %s + + + + +`, u, url.PathEscape(name), name) + c.Header("Content-Type", "application/xml;charset=utf-8") + c.Status(200) + _, _ = c.Writer.WriteString(plist) +} diff --git a/server/router.go b/server/router.go index 2e976cbccc6..505a3276b5d 100644 --- a/server/router.go +++ b/server/router.go @@ -17,6 +17,8 @@ func Init(r *gin.Engine) { r.Use(middlewares.StoragesLoaded) WebDav(r) + r.GET("/favicon.ico", handles.Favicon) + r.GET("/i/:link/:name", handles.Plist) r.GET("/d/*path", middlewares.Down, handles.Down) r.GET("/p/*path", middlewares.Down, handles.Proxy)