Add types and stop the timer after download completed

This commit is contained in:
Andrea Fazzi 2022-02-17 09:43:41 +01:00
parent 156bde4c6b
commit 76294c73ea

View file

@ -5,19 +5,39 @@
export let url: string
let intervalID: NodeJS.Timer
let task
let videoInfo
let task: {
ID: string,
Status: number,
Filename: string
}
let videoInfo: {
ID: string,
Title: string,
Duration: number,
Thumbnails: any[],
Filename: string,
DownloadPath: string
}
onMount(startDownload)
async function startDownload() {
const res = await fetch(`${endpoint}/task`, {method: 'POST', body: new URLSearchParams({'url': url})})
videoInfo = await res.json()
if (res.ok) {
intervalID = setInterval(async () => {
const res = await fetch(`${endpoint}/task/${videoInfo.ID}`);
task = await res.json();
const res = await fetch(`${endpoint}/task/${videoInfo.ID}`)
task = await res.json()
if (res.ok) {
if (task.Status == 2) {
clearInterval(intervalID)
}
}
}, 2000)
}