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()}