Put stream in downloading map on click rather than on dl start
prevents network issue race conditions
This commit is contained in:
@@ -18,6 +18,10 @@ if (browser) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function download(stream: StreamSummary) {
|
export async function download(stream: StreamSummary) {
|
||||||
|
if (downloading.has(stream.id) || cached.has(stream.id)) return;
|
||||||
|
downloading.set(stream.id, 0);
|
||||||
|
|
||||||
|
try {
|
||||||
const res = await fetch(`/media/tracks/${stream.filename}`);
|
const res = await fetch(`/media/tracks/${stream.filename}`);
|
||||||
if (!res.ok || !res.body) throw new Error('Download failed');
|
if (!res.ok || !res.body) throw new Error('Download failed');
|
||||||
|
|
||||||
@@ -26,8 +30,6 @@ export async function download(stream: StreamSummary) {
|
|||||||
const chunks: Uint8Array[] = [];
|
const chunks: Uint8Array[] = [];
|
||||||
let received = 0;
|
let received = 0;
|
||||||
|
|
||||||
downloading.set(stream.id, 0);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const { done, value } = await reader.read();
|
const { done, value } = await reader.read();
|
||||||
if (done) break;
|
if (done) break;
|
||||||
@@ -42,8 +44,10 @@ export async function download(stream: StreamSummary) {
|
|||||||
await writable.write(new Blob(chunks));
|
await writable.write(new Blob(chunks));
|
||||||
await writable.close();
|
await writable.close();
|
||||||
|
|
||||||
downloading.delete(stream.id);
|
|
||||||
cached.add(stream.id);
|
cached.add(stream.id);
|
||||||
|
} finally {
|
||||||
|
downloading.delete(stream.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function remove(streamId: string) {
|
export async function remove(streamId: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user