mirror of
https://github.com/alexta69/metube.git
synced 2026-06-13 16:40:05 +00:00
Updated import and fixed race condition
This commit is contained in:
+4
-2
@@ -1140,9 +1140,11 @@ class DownloadQueue:
|
|||||||
if not self.queue.exists(id):
|
if not self.queue.exists(id):
|
||||||
log.warning(f'requested cancel for non-existent download {id}')
|
log.warning(f'requested cancel for non-existent download {id}')
|
||||||
continue
|
continue
|
||||||
if self.queue.get(id).started():
|
dl = self.queue.get(id)
|
||||||
self.queue.get(id).cancel()
|
if dl.started():
|
||||||
|
dl.cancel()
|
||||||
else:
|
else:
|
||||||
|
dl.canceled = True
|
||||||
self.queue.delete(id)
|
self.queue.delete(id)
|
||||||
await self.notifier.canceled(id)
|
await self.notifier.canceled(id)
|
||||||
return {'status': 'ok'}
|
return {'status': 'ok'}
|
||||||
|
|||||||
@@ -608,6 +608,17 @@
|
|||||||
@if (batchImportStatus) {
|
@if (batchImportStatus) {
|
||||||
<small>{{ batchImportStatus }}</small>
|
<small>{{ batchImportStatus }}</small>
|
||||||
}
|
}
|
||||||
|
@if (importInProgress) {
|
||||||
|
<div class="progress mt-2" style="height: 20px;">
|
||||||
|
<div class="progress-bar" role="progressbar"
|
||||||
|
[style.width.%]="batchImportTotal > 0 ? (batchImportCount / batchImportTotal) * 100 : 0"
|
||||||
|
[attr.aria-valuenow]="batchImportCount"
|
||||||
|
[attr.aria-valuemin]="0"
|
||||||
|
[attr.aria-valuemax]="batchImportTotal">
|
||||||
|
{{ batchImportCount }} / {{ batchImportTotal }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|||||||
+28
-34
@@ -104,6 +104,8 @@ export class App implements AfterViewInit, OnInit, OnDestroy {
|
|||||||
batchImportModalOpen = false;
|
batchImportModalOpen = false;
|
||||||
batchImportText = '';
|
batchImportText = '';
|
||||||
batchImportStatus = '';
|
batchImportStatus = '';
|
||||||
|
batchImportCount = 0;
|
||||||
|
batchImportTotal = 0;
|
||||||
importInProgress = false;
|
importInProgress = false;
|
||||||
cancelImportFlag = false;
|
cancelImportFlag = false;
|
||||||
ytDlpOptionsUpdateTime: string | null = null;
|
ytDlpOptionsUpdateTime: string | null = null;
|
||||||
@@ -1200,41 +1202,33 @@ export class App implements AfterViewInit, OnInit, OnDestroy {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.importInProgress = true;
|
this.importInProgress = true;
|
||||||
this.cancelImportFlag = false;
|
this.batchImportCount = 0;
|
||||||
this.batchImportStatus = `Starting to import ${urls.length} URLs...`;
|
this.batchImportTotal = urls.length;
|
||||||
let index = 0;
|
this.batchImportStatus = `Sending ${urls.length} URLs to server...`;
|
||||||
const delayBetween = 1000;
|
|
||||||
const processNext = () => {
|
const promises = urls.map(url =>
|
||||||
if (this.cancelImportFlag) {
|
new Promise<void>((resolve) => {
|
||||||
this.batchImportStatus = `Import cancelled after ${index} of ${urls.length} URLs.`;
|
this.downloads.add(this.buildAddPayload({ url })).subscribe({
|
||||||
this.importInProgress = false;
|
next: (status: Status) => {
|
||||||
return;
|
if (status.status === 'error') {
|
||||||
}
|
console.error(`Error adding URL ${url}: ${status.msg}`);
|
||||||
if (index >= urls.length) {
|
}
|
||||||
this.batchImportStatus = `Finished importing ${urls.length} URLs.`;
|
this.batchImportCount++;
|
||||||
this.importInProgress = false;
|
resolve();
|
||||||
return;
|
},
|
||||||
}
|
error: (err) => {
|
||||||
const url = urls[index];
|
console.error(`Error importing URL ${url}:`, err);
|
||||||
this.batchImportStatus = `Importing URL ${index + 1} of ${urls.length}: ${url}`;
|
this.batchImportCount++;
|
||||||
// Pass current selection options to backend
|
resolve();
|
||||||
this.downloads.add(this.buildAddPayload({ url }))
|
|
||||||
.subscribe({
|
|
||||||
next: (status: Status) => {
|
|
||||||
if (status.status === 'error') {
|
|
||||||
alert(`Error adding URL ${url}: ${status.msg}`);
|
|
||||||
}
|
}
|
||||||
index++;
|
});
|
||||||
setTimeout(processNext, delayBetween);
|
})
|
||||||
},
|
);
|
||||||
error: (err) => {
|
|
||||||
console.error(`Error importing URL ${url}:`, err);
|
Promise.all(promises).then(() => {
|
||||||
index++;
|
this.batchImportStatus = `All ${urls.length} URLs sent to server.`;
|
||||||
setTimeout(processNext, delayBetween);
|
this.importInProgress = false;
|
||||||
}
|
});
|
||||||
});
|
|
||||||
};
|
|
||||||
processNext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel the batch import process
|
// Cancel the batch import process
|
||||||
|
|||||||
Reference in New Issue
Block a user