feat(webui): concurrent downloading
This commit is contained in:
parent
51834cc7e6
commit
c2203943e2
@ -73,18 +73,20 @@ getLessonButton.addEventListener('click', async () => {
|
||||
<br>`;
|
||||
}
|
||||
let videoDlResult = null;
|
||||
const promises = [];
|
||||
const downloadSelectedButton = document.createElement("button");
|
||||
downloadSelectedButton.innerHTML = "Download Selected";
|
||||
downloadSelectedButton.addEventListener('click', async () => {
|
||||
for (const [id, video] of Object.entries(ids)) {
|
||||
promises.push(async () => {
|
||||
const checkbox = document.querySelector(`#${id}`);
|
||||
if (!checkbox.checked) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
const videoRsp = await fetch(`/api/v1/videos/${video.id}`);
|
||||
if (videoRsp.status !== 200) {
|
||||
console.error(`Failed to get video ${video.name}`);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
const videoData = await videoRsp.json();
|
||||
if (videoDlResult === null) {
|
||||
@ -115,7 +117,9 @@ getLessonButton.addEventListener('click', async () => {
|
||||
if (rsp.status !== 200) {
|
||||
console.error(`Failed to download ${video.name}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
await Promise.all(promises.map(p => p()));
|
||||
});
|
||||
result.appendChild(downloadSelectedButton);
|
||||
// result.innerHTML += "<button>Download All</button>";
|
||||
|
Loading…
Reference in New Issue
Block a user