mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
Fix timeout not works
This commit is contained in:
@@ -52,7 +52,7 @@ export class Client {
|
||||
return t ? t : undefined;
|
||||
} else return undefined;
|
||||
}
|
||||
request(
|
||||
async request(
|
||||
url: string | Request | URL,
|
||||
method: string | undefined = undefined,
|
||||
options: RequestInit | undefined = undefined,
|
||||
@@ -81,7 +81,7 @@ export class Client {
|
||||
url.headers.set(v[0], v[1]);
|
||||
}
|
||||
try {
|
||||
return fetch(url);
|
||||
return await fetch(url);
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError) {
|
||||
throw new RecoverableError(e.message, { cause: e.cause });
|
||||
@@ -112,7 +112,7 @@ export class Client {
|
||||
});
|
||||
d.signal = abortController.signal;
|
||||
try {
|
||||
return fetch(url, d);
|
||||
return await fetch(url, d);
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError) {
|
||||
throw new RecoverableError(e.message, { cause: e.cause });
|
||||
|
||||
@@ -280,7 +280,10 @@ export async function download_task(
|
||||
if (load_times >= max_retry_count) reject(errors);
|
||||
i.load().then(resolve).catch((e) => {
|
||||
if (force_abort.aborted) {
|
||||
throw Error("aborted.");
|
||||
console.log("Aborted when loading image:", i);
|
||||
errors.push(e);
|
||||
reject(errors);
|
||||
return;
|
||||
}
|
||||
errors.push(e);
|
||||
load_times += 1;
|
||||
@@ -392,7 +395,13 @@ export async function download_task(
|
||||
}
|
||||
download().then(resolve).catch((e) => {
|
||||
if (force_abort.aborted) {
|
||||
throw Error("aborted.");
|
||||
console.log(
|
||||
"Aborted when downloading image:",
|
||||
i,
|
||||
);
|
||||
errors.push(e);
|
||||
reject(errors);
|
||||
return;
|
||||
}
|
||||
if (e instanceof DOMException) {
|
||||
if (e.name == "AbortError") {
|
||||
@@ -422,6 +431,10 @@ export async function download_task(
|
||||
function try_() {
|
||||
load().then(() => {
|
||||
deal_with_img().then(resolve).catch((e) => {
|
||||
if (force_abort.aborted) {
|
||||
reject(e);
|
||||
return;
|
||||
}
|
||||
console.log("Failed to download, retry: ", e);
|
||||
retry += 1;
|
||||
if (retry >= max_retry_count) {
|
||||
|
||||
@@ -46,10 +46,11 @@ export class ProgressReadable extends EventTarget {
|
||||
this.#clearInterval();
|
||||
return;
|
||||
} else {
|
||||
this.readed += v.value.byteLength;
|
||||
const len = v.value.byteLength;
|
||||
this.readed += len;
|
||||
this.dispatchEvent("progress", this.readed);
|
||||
c.enqueue(v.value);
|
||||
if (v.value.byteLength != 0) {
|
||||
if (len != 0) {
|
||||
this.#last_readed = Date.now();
|
||||
}
|
||||
}
|
||||
@@ -83,7 +84,7 @@ export class ProgressReadable extends EventTarget {
|
||||
}
|
||||
}
|
||||
#setInterval() {
|
||||
this.#timeout = setTimeout(() => {
|
||||
this.#timeout = setInterval(() => {
|
||||
const now = Date.now();
|
||||
if (now - this.#last_readed > this.timeout) {
|
||||
this.#is_timeout = true;
|
||||
|
||||
Reference in New Issue
Block a user