From 155c3ccfd9135ff18fca8780bf80e1a3f8987ae1 Mon Sep 17 00:00:00 2001 From: Akhil Gupta Date: Tue, 30 Mar 2021 05:55:54 +0530 Subject: [PATCH] try fix breaking downloads --- controllers/podcast.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/controllers/podcast.go b/controllers/podcast.go index 5dba90a..8900fd0 100644 --- a/controllers/podcast.go +++ b/controllers/podcast.go @@ -5,11 +5,11 @@ import ( "log" "net/http" "os" + "path" "strings" "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" @@ -235,9 +235,11 @@ func GetPodcastItemFileById(c *gin.Context) { 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) + c.Header("Content-Description", "File Transfer") + c.Header("Content-Transfer-Encoding", "binary") + c.Header("Content-Disposition", "attachment; filename="+path.Base(podcast.DownloadPath)) + c.Header("Content-Type", "application/octet-stream") + c.File(podcast.DownloadPath) } else { c.Redirect(302, fmt.Sprintf("/%s", podcast.FileURL)) }