package handles import ( "fmt" "net/url" "strings" "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/setting" "github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/server/common" "github.com/gin-gonic/gin" ) func Favicon(c *gin.Context) { c.Redirect(302, setting.GetStr(conf.Favicon)) } func Plist(c *gin.Context) { linkNameB64 := strings.TrimSuffix(c.Param("link_name"), ".plist") linkName, err := utils.SafeAtob(linkNameB64) if err != nil { common.ErrorResp(c, err, 400) return } linkNameSplit := strings.Split(linkName, "/") if len(linkNameSplit) != 2 { common.ErrorStrResp(c, "malformed link", 400) return } linkEncode := linkNameSplit[0] linkStr, err := url.PathUnescape(linkEncode) if err != nil { common.ErrorResp(c, err, 400) return } link, err := url.Parse(linkStr) if err != nil { common.ErrorResp(c, err, 400) return } fullName := c.Param("name") Url := link.String() nameEncode := linkNameSplit[1] fullName, err = url.PathUnescape(nameEncode) if err != nil { common.ErrorResp(c, err, 400) return } name := fullName identifier := fmt.Sprintf("ci.nn.%s", url.PathEscape(fullName)) sep := "@" if strings.Contains(fullName, sep) { ss := strings.Split(fullName, sep) name = strings.Join(ss[:len(ss)-1], sep) identifier = ss[len(ss)-1] } name = strings.ReplaceAll(name, "<", "[") name = strings.ReplaceAll(name, ">", "]") plist := fmt.Sprintf(` items assets kind software-package url metadata bundle-identifier %s bundle-version 4.4 kind software title %s `, Url, identifier, name) c.Header("Content-Type", "application/xml;charset=utf-8") c.Status(200) _, _ = c.Writer.WriteString(plist) }