diff --git a/backend/main.go b/backend/main.go index 84f04d6..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(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,13 +73,11 @@ 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) } }) - // 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..2f97490 100644 --- a/backend/task/task.go +++ b/backend/task/task.go @@ -9,6 +9,7 @@ const ( type Tasks map[string]*Task type Task struct { - Status int - DownloadPath 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 1bd2cac..8f0639e 100644 --- a/backend/youtube/youtube-dl/youtube-dl.go +++ b/backend/youtube/youtube-dl/youtube-dl.go @@ -51,8 +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)), + 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()} 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" +}