Fix filename download
This commit is contained in:
parent
55d95b1e58
commit
3d4777bcf4
3 changed files with 3 additions and 3 deletions
|
@ -47,7 +47,7 @@ func status(c *gin.Context, downloader youtube.Downloader) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveFile(c *gin.Context, filename string) 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")
|
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", filename))
|
||||||
return nil
|
return nil
|
||||||
|
@ -78,8 +78,6 @@ func main() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// r.Static("/data", "./data")
|
|
||||||
|
|
||||||
r.GET("/download", func(c *gin.Context) {
|
r.GET("/download", func(c *gin.Context) {
|
||||||
if err := download(c, youtube_dl.NewYoutubeDlDownloader(c.Query("url"), "yt-dlp")); err != nil {
|
if err := download(c, youtube_dl.NewYoutubeDlDownloader(c.Query("url"), "yt-dlp")); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -11,4 +11,5 @@ type Tasks map[string]*Task
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Status int
|
Status int
|
||||||
DownloadPath string
|
DownloadPath string
|
||||||
|
Filename string
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ func (d *YoutubeDlDownloader) StartDownload(video *youtube.Video, tasks task.Tas
|
||||||
tasks[video.ID] = &task.Task{
|
tasks[video.ID] = &task.Task{
|
||||||
Status: task.StatusCompleted,
|
Status: task.StatusCompleted,
|
||||||
DownloadPath: filepath.Join("data", video.ID+filepath.Ext(video.Filename)),
|
DownloadPath: filepath.Join("data", video.ID+filepath.Ext(video.Filename)),
|
||||||
|
Filename: video.Filename,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue