1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00

Allow XML extension in feed links

This commit is contained in:
Maksym Pavlenko
2017-10-24 14:08:16 -07:00
parent 57f24bd137
commit 69019d6c01

View File

@@ -7,6 +7,7 @@ import (
"log" "log"
"net/http" "net/http"
"path" "path"
"strings"
"github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -21,6 +22,7 @@ import (
const ( const (
creatorID = "2822191" creatorID = "2822191"
identitySessionKey = "identity" identitySessionKey = "identity"
maxHashIDLength = 16
) )
type feed interface { type feed interface {
@@ -216,11 +218,15 @@ Host: www.podsync.net`)
r.NoRoute(func(c *gin.Context) { r.NoRoute(func(c *gin.Context) {
hashId := c.Request.URL.Path[1:] hashId := c.Request.URL.Path[1:]
if hashId == "" || len(hashId) > 12 { if hashId == "" || len(hashId) > maxHashIDLength {
c.String(http.StatusBadRequest, "invalid feed id") c.String(http.StatusBadRequest, "invalid feed id")
return return
} }
if strings.HasSuffix(hashId, ".xml") {
hashId = strings.TrimSuffix(hashId, ".xml")
}
podcast, err := feed.GetFeed(hashId) podcast, err := feed.GetFeed(hashId)
if err != nil { if err != nil {
code := http.StatusInternalServerError code := http.StatusInternalServerError
@@ -239,7 +245,7 @@ Host: www.podsync.net`)
r.GET("/api/metadata/:hashId", func(c *gin.Context) { r.GET("/api/metadata/:hashId", func(c *gin.Context) {
hashId := c.Param("hashId") hashId := c.Param("hashId")
if hashId == "" || len(hashId) > 12 { if hashId == "" || len(hashId) > maxHashIDLength {
c.String(http.StatusBadRequest, "invalid feed id") c.String(http.StatusBadRequest, "invalid feed id")
return return
} }