2021-05-24 14:19:37 +00:00
|
|
|
import {DecryptResult} from "@/decrypt/entity";
|
|
|
|
|
|
|
|
export function DownloadBlobMusic(data: DecryptResult, format: string) {//todo: use enum
|
2020-02-06 08:01:35 +00:00
|
|
|
const a = document.createElement('a');
|
|
|
|
a.href = data.file;
|
|
|
|
switch (format) {
|
2020-02-23 05:45:30 +00:00
|
|
|
default:
|
2020-02-06 08:01:35 +00:00
|
|
|
case "1":
|
2020-02-23 05:45:30 +00:00
|
|
|
a.download = data.artist + " - " + data.title + "." + data.ext;
|
2020-02-06 08:01:35 +00:00
|
|
|
break;
|
|
|
|
case "2":
|
2020-02-23 05:45:30 +00:00
|
|
|
a.download = data.title + "." + data.ext;
|
2020-02-06 08:01:35 +00:00
|
|
|
break;
|
|
|
|
case "3":
|
|
|
|
a.download = data.title + " - " + data.artist + "." + data.ext;
|
|
|
|
break;
|
2020-02-23 05:45:30 +00:00
|
|
|
case "4":
|
|
|
|
a.download = data.rawFilename + "." + data.ext;
|
|
|
|
break;
|
2020-02-06 08:01:35 +00:00
|
|
|
}
|
|
|
|
document.body.append(a);
|
|
|
|
a.click();
|
|
|
|
a.remove();
|
|
|
|
}
|
|
|
|
|
2021-05-24 14:19:37 +00:00
|
|
|
export function RemoveBlobMusic(data: DecryptResult) {
|
2020-02-06 08:01:35 +00:00
|
|
|
URL.revokeObjectURL(data.file);
|
2021-05-24 14:19:37 +00:00
|
|
|
if (data.picture?.startsWith("blob:")) {
|
2020-04-05 04:28:59 +00:00
|
|
|
URL.revokeObjectURL(data.picture);
|
|
|
|
}
|
2021-05-24 14:19:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class DecryptQueue {
|
|
|
|
private readonly pending: (() => Promise<void>)[];
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.pending = []
|
|
|
|
}
|
|
|
|
|
|
|
|
queue(fn: () => Promise<void>) {
|
|
|
|
this.pending.push(fn)
|
|
|
|
this.consume()
|
|
|
|
}
|
2020-04-05 04:28:59 +00:00
|
|
|
|
2021-05-24 14:19:37 +00:00
|
|
|
private consume() {
|
|
|
|
const fn = this.pending.shift()
|
|
|
|
if (fn) fn().then(() => this.consume).catch(console.error)
|
|
|
|
}
|
2020-02-06 08:01:35 +00:00
|
|
|
}
|