diff --git a/backend/main.go b/backend/main.go index 84f04d6..dbb52cb 100644 --- a/backend/main.go +++ b/backend/main.go @@ -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) diff --git a/backend/task/task.go b/backend/task/task.go index 90a2f49..e524c46 100644 --- a/backend/task/task.go +++ b/backend/task/task.go @@ -11,4 +11,5 @@ type Tasks map[string]*Task type Task struct { Status int DownloadPath string + Filename string } diff --git a/backend/youtube/youtube-dl/youtube-dl.go b/backend/youtube/youtube-dl/youtube-dl.go index 7b13f80..94fe84f 100644 --- a/backend/youtube/youtube-dl/youtube-dl.go +++ b/backend/youtube/youtube-dl/youtube-dl.go @@ -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, } }