Fix filename download

This commit is contained in:
Andrea Fazzi 2021-11-04 11:41:38 +01:00
parent 55d95b1e58
commit 3d4777bcf4
3 changed files with 3 additions and 3 deletions

View file

@ -47,7 +47,7 @@ func status(c *gin.Context, downloader youtube.Downloader) error {
}
func serveFile(c *gin.Context, filename string) error {
c.Writer.Header().Set("Content-Disposition", "attachment; filename="+strconv.Quote(filename))
c.Writer.Header().Set("Content-Disposition", "attachment; filename="+strconv.Quote(tasks[filepath.Base(filename)].Filename))
c.Writer.Header().Set("Content-Type", "application/octet-stream")
http.ServeFile(c.Writer, c.Request, filepath.Join("data", filename))
return nil
@ -78,8 +78,6 @@ func main() {
}
})
// r.Static("/data", "./data")
r.GET("/download", func(c *gin.Context) {
if err := download(c, youtube_dl.NewYoutubeDlDownloader(c.Query("url"), "yt-dlp")); err != nil {
panic(err)

View file

@ -11,4 +11,5 @@ type Tasks map[string]*Task
type Task struct {
Status int
DownloadPath string
Filename string
}

View file

@ -53,6 +53,7 @@ func (d *YoutubeDlDownloader) StartDownload(video *youtube.Video, tasks task.Tas
tasks[video.ID] = &task.Task{
Status: task.StatusCompleted,
DownloadPath: filepath.Join("data", video.ID+filepath.Ext(video.Filename)),
Filename: video.Filename,
}
}