Use backend download key in frontend queue/done maps
This commit is contained in:
parent
b0fa114663
commit
3c32421b2a
1 changed files with 13 additions and 5 deletions
|
|
@ -44,6 +44,11 @@ export class DownloadsService {
|
||||||
configuration: Record<string, unknown> = {};
|
configuration: Record<string, unknown> = {};
|
||||||
customDirs: Record<string, string[]> = {};
|
customDirs: Record<string, string[]> = {};
|
||||||
|
|
||||||
|
private getDownloadKey(download: Download): string {
|
||||||
|
const maybeKey = (download as Download & { key?: string }).key;
|
||||||
|
return maybeKey && maybeKey.length > 0 ? maybeKey : download.url;
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.socket.fromEvent('all')
|
this.socket.fromEvent('all')
|
||||||
.pipe(takeUntilDestroyed())
|
.pipe(takeUntilDestroyed())
|
||||||
|
|
@ -61,25 +66,28 @@ export class DownloadsService {
|
||||||
.pipe(takeUntilDestroyed())
|
.pipe(takeUntilDestroyed())
|
||||||
.subscribe((strdata: string) => {
|
.subscribe((strdata: string) => {
|
||||||
const data: Download = JSON.parse(strdata);
|
const data: Download = JSON.parse(strdata);
|
||||||
this.queue.set(data.url, data);
|
const key = this.getDownloadKey(data);
|
||||||
|
this.queue.set(key, data);
|
||||||
this.queueChanged.next();
|
this.queueChanged.next();
|
||||||
});
|
});
|
||||||
this.socket.fromEvent('updated')
|
this.socket.fromEvent('updated')
|
||||||
.pipe(takeUntilDestroyed())
|
.pipe(takeUntilDestroyed())
|
||||||
.subscribe((strdata: string) => {
|
.subscribe((strdata: string) => {
|
||||||
const data: Download = JSON.parse(strdata);
|
const data: Download = JSON.parse(strdata);
|
||||||
const dl: Download | undefined = this.queue.get(data.url);
|
const key = this.getDownloadKey(data);
|
||||||
|
const dl: Download | undefined = this.queue.get(key);
|
||||||
data.checked = !!dl?.checked;
|
data.checked = !!dl?.checked;
|
||||||
data.deleting = !!dl?.deleting;
|
data.deleting = !!dl?.deleting;
|
||||||
this.queue.set(data.url, data);
|
this.queue.set(key, data);
|
||||||
this.updated.next();
|
this.updated.next();
|
||||||
});
|
});
|
||||||
this.socket.fromEvent('completed')
|
this.socket.fromEvent('completed')
|
||||||
.pipe(takeUntilDestroyed())
|
.pipe(takeUntilDestroyed())
|
||||||
.subscribe((strdata: string) => {
|
.subscribe((strdata: string) => {
|
||||||
const data: Download = JSON.parse(strdata);
|
const data: Download = JSON.parse(strdata);
|
||||||
this.queue.delete(data.url);
|
const key = this.getDownloadKey(data);
|
||||||
this.done.set(data.url, data);
|
this.queue.delete(key);
|
||||||
|
this.done.set(key, data);
|
||||||
this.queueChanged.next();
|
this.queueChanged.next();
|
||||||
this.doneChanged.next();
|
this.doneChanged.next();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue