Add types and stop the timer after download completed
This commit is contained in:
parent
156bde4c6b
commit
76294c73ea
1 changed files with 25 additions and 5 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue