Merge pull request #60 from akhilrex/location

fix podcast url issue
pull/64/head
Akhil Gupta 4 years ago committed by GitHub
commit 09412f14ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -131,7 +131,7 @@
{{if .DownloadPath}}
<a
class="button"
href="/{{ .DownloadPath }}"
href="/podcastitems/{{.ID}}/file"
download
title="Download episode file"
><i class="fas fa-download"></i

@ -9,6 +9,7 @@ import (
"github.com/akhilrex/podgrab/model"
"github.com/akhilrex/podgrab/service"
"github.com/gin-contrib/location"
"github.com/akhilrex/podgrab/db"
"github.com/gin-gonic/gin"
@ -221,6 +222,28 @@ func GetPodcastItemImageById(c *gin.Context) {
}
}
func GetPodcastItemFileById(c *gin.Context) {
var searchByIdQuery SearchByIdQuery
if c.ShouldBindUri(&searchByIdQuery) == nil {
var podcast db.PodcastItem
err := db.GetPodcastItemById(searchByIdQuery.Id, &podcast)
if err == nil {
if _, err = os.Stat(podcast.DownloadPath); !os.IsNotExist(err) {
url := location.Get(c)
filePath := fmt.Sprintf("%s://%s/%s", url.Scheme, url.Host, podcast.DownloadPath)
c.Redirect(301, filePath)
} else {
c.Redirect(302, fmt.Sprintf("/%s", podcast.FileURL))
}
}
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
}
}
func MarkPodcastItemAsUnplayed(c *gin.Context) {
var searchByIdQuery SearchByIdQuery

@ -6,6 +6,7 @@ require (
github.com/TheHippo/podcastindex v1.0.0
github.com/antchfx/xmlquery v1.3.3
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-contrib/location v0.0.2
github.com/gin-gonic/gin v1.6.3
github.com/gobeam/stringy v0.0.0-20200717095810-8a3637503f62
github.com/gorilla/websocket v1.4.2

@ -19,6 +19,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumC
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gin-contrib/location v0.0.2 h1:QZKh1+K/LLR4KG/61eIO3b7MLuKi8tytQhV6texLgP4=
github.com/gin-contrib/location v0.0.2/go.mod h1:NGoidiRlf0BlA/VKSVp+g3cuSMeTmip/63PhEjRhUAc=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
@ -138,6 +140,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=

@ -11,6 +11,7 @@ import (
"github.com/akhilrex/podgrab/controllers"
"github.com/akhilrex/podgrab/db"
"github.com/akhilrex/podgrab/service"
"github.com/gin-contrib/location"
"github.com/gin-gonic/gin"
"github.com/jasonlvhit/gocron"
_ "github.com/joho/godotenv/autoload"
@ -30,6 +31,7 @@ func main() {
r.Static("/assets", dataPath)
r.Use(setupSettings())
r.Use(gin.Recovery())
r.Use(location.Default())
funcMap := template.FuncMap{
"isDateNull": func(raw time.Time) bool {
@ -117,6 +119,7 @@ func main() {
router.GET("/podcastitems", controllers.GetAllPodcastItems)
router.GET("/podcastitems/:id", controllers.GetPodcastItemById)
router.GET("/podcastitems/:id/image", controllers.GetPodcastItemImageById)
router.GET("/podcastitems/:id/file", controllers.GetPodcastItemFileById)
router.GET("/podcastitems/:id/markUnplayed", controllers.MarkPodcastItemAsUnplayed)
router.GET("/podcastitems/:id/markPlayed", controllers.MarkPodcastItemAsPlayed)
router.GET("/podcastitems/:id/bookmark", controllers.BookmarkPodcastItem)

Loading…
Cancel
Save