Add config.js
This commit is contained in:
parent
3d4777bcf4
commit
d9909a0f41
4 changed files with 16 additions and 14 deletions
|
@ -46,10 +46,10 @@ func status(c *gin.Context, downloader youtube.Downloader) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveFile(c *gin.Context, filename string) error {
|
func data(c *gin.Context, id string) error {
|
||||||
c.Writer.Header().Set("Content-Disposition", "attachment; filename="+strconv.Quote(tasks[filepath.Base(filename)].Filename))
|
c.Writer.Header().Set("Content-Disposition", "attachment; filename="+strconv.Quote(tasks[id].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", tasks[id].Filename))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ func main() {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
r.GET("/data/:filename", func(c *gin.Context) {
|
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)
|
panic(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,7 +9,7 @@ const (
|
||||||
type Tasks map[string]*Task
|
type Tasks map[string]*Task
|
||||||
|
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Status int
|
Id string
|
||||||
DownloadPath string
|
Status int
|
||||||
Filename string
|
Filename string
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,9 @@ func (d *YoutubeDlDownloader) StartDownload(video *youtube.Video, tasks task.Tas
|
||||||
|
|
||||||
log.Printf("Download of video ID %s COMPLETED.", video.ID)
|
log.Printf("Download of video ID %s COMPLETED.", video.ID)
|
||||||
tasks[video.ID] = &task.Task{
|
tasks[video.ID] = &task.Task{
|
||||||
Status: task.StatusCompleted,
|
Id: video.ID,
|
||||||
DownloadPath: filepath.Join("data", video.ID+filepath.Ext(video.Filename)),
|
Status: task.StatusCompleted,
|
||||||
Filename: video.Filename,
|
Filename: video.Filename,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
|
import { config } from './config.js';
|
||||||
|
|
||||||
export let url;
|
export let url;
|
||||||
|
|
||||||
let video_info = {};
|
let video_info = {};
|
||||||
|
@ -11,7 +13,7 @@
|
||||||
let download_path = "#";
|
let download_path = "#";
|
||||||
|
|
||||||
async function startDownload() {
|
async function startDownload() {
|
||||||
const res = await fetch(`https://yt-dls-api.andreafazzi.eu/download?url=${url}`);
|
const res = await fetch(`${config.endpoint}/download?url=${url}`);
|
||||||
video_info = await res.json();
|
video_info = await res.json();
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
|
@ -23,12 +25,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getStatus() {
|
async function getStatus() {
|
||||||
const res = await fetch(`https://yt-dls-api.andreafazzi.eu/status?url=${url}`);
|
const res = await fetch(`${config.endpoint}/status?url=${url}`);
|
||||||
status = await res.json();
|
status = await res.json();
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
if (status.DownloadPath) {
|
if (status.DownloadPath) {
|
||||||
download_path = `https://yt-dls-api.andreafazzi.eu/${status.DownloadPath}`;
|
download_path = `${config.endpoint}/data/${status.Id}`;
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
} else {
|
} else {
|
||||||
|
@ -38,7 +40,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const interval = setInterval(() => { getStatus(); }, 1000);
|
const interval = setInterval(() => { getStatus(); }, 1000);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#await startDownload()}
|
{#await startDownload()}
|
||||||
|
|
Loading…
Reference in a new issue