From 3d4777bcf4ec87a4b7ebd58bd7289cca4b863db8 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Thu, 4 Nov 2021 11:41:38 +0100 Subject: [PATCH 1/3] Fix filename download --- backend/main.go | 4 +--- backend/task/task.go | 1 + backend/youtube/youtube-dl/youtube-dl.go | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) 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, } } From d9909a0f414e36a35bf260480b14ab47e17e6467 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Mon, 8 Nov 2021 09:24:49 +0100 Subject: [PATCH 2/3] Add config.js --- backend/main.go | 8 ++++---- backend/task/task.go | 6 +++--- backend/youtube/youtube-dl/youtube-dl.go | 6 +++--- frontend/src/Task.svelte | 10 ++++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/backend/main.go b/backend/main.go index dbb52cb..53a2b45 100644 --- a/backend/main.go +++ b/backend/main.go @@ -46,10 +46,10 @@ func status(c *gin.Context, downloader youtube.Downloader) error { return nil } -func serveFile(c *gin.Context, filename string) error { - c.Writer.Header().Set("Content-Disposition", "attachment; filename="+strconv.Quote(tasks[filepath.Base(filename)].Filename)) +func data(c *gin.Context, id string) error { + c.Writer.Header().Set("Content-Disposition", "attachment; filename="+strconv.Quote(tasks[id].Filename)) c.Writer.Header().Set("Content-Type", "application/octet-stream") - http.ServeFile(c.Writer, c.Request, filepath.Join("data", filename)) + http.ServeFile(c.Writer, c.Request, filepath.Join("data", tasks[id].Filename)) return nil } @@ -73,7 +73,7 @@ func main() { })) r.GET("/data/:filename", func(c *gin.Context) { - if err := serveFile(c, c.Param("filename")); err != nil { + if err := data(c, c.Param("filename")); err != nil { panic(err) } }) diff --git a/backend/task/task.go b/backend/task/task.go index e524c46..2f97490 100644 --- a/backend/task/task.go +++ b/backend/task/task.go @@ -9,7 +9,7 @@ const ( type Tasks map[string]*Task type Task struct { - Status int - DownloadPath string - Filename string + Id string + Status int + Filename string } diff --git a/backend/youtube/youtube-dl/youtube-dl.go b/backend/youtube/youtube-dl/youtube-dl.go index 94fe84f..4a00473 100644 --- a/backend/youtube/youtube-dl/youtube-dl.go +++ b/backend/youtube/youtube-dl/youtube-dl.go @@ -51,9 +51,9 @@ func (d *YoutubeDlDownloader) StartDownload(video *youtube.Video, tasks task.Tas log.Printf("Download of video ID %s COMPLETED.", video.ID) tasks[video.ID] = &task.Task{ - Status: task.StatusCompleted, - DownloadPath: filepath.Join("data", video.ID+filepath.Ext(video.Filename)), - Filename: video.Filename, + Id: video.ID, + Status: task.StatusCompleted, + Filename: video.Filename, } } diff --git a/frontend/src/Task.svelte b/frontend/src/Task.svelte index b3c2ab9..efb4eac 100644 --- a/frontend/src/Task.svelte +++ b/frontend/src/Task.svelte @@ -1,4 +1,6 @@ {#await startDownload()} From 17b571669e97b4e4bed6834abd8fee11fcd584f4 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Mon, 8 Nov 2021 09:24:57 +0100 Subject: [PATCH 3/3] Add config.js --- frontend/src/config.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 frontend/src/config.js diff --git a/frontend/src/config.js b/frontend/src/config.js new file mode 100644 index 0000000..4e672c0 --- /dev/null +++ b/frontend/src/config.js @@ -0,0 +1,3 @@ +export const config = { + endpoint: "http://localhost:8080" +}