mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-06-06 05:38:44 +08:00
Use better way to reload
This commit is contained in:
@@ -122,8 +122,7 @@ class Image {
|
||||
return re;
|
||||
}
|
||||
async load_image(reload = true) {
|
||||
if (!reload) return;
|
||||
await this.load();
|
||||
if (reload || !this.data) await this.load();
|
||||
const src2 = this.src;
|
||||
if (src2) return await this.#load_image(src2);
|
||||
}
|
||||
|
||||
@@ -172,8 +172,7 @@ class MPVImage {
|
||||
return re;
|
||||
}
|
||||
async load_image(reload = true) {
|
||||
if (!reload) return;
|
||||
await this.load();
|
||||
if (reload || !this.data) await this.load();
|
||||
const src2 = this.src;
|
||||
if (src2) return await this.#load_image(src2);
|
||||
}
|
||||
|
||||
@@ -287,6 +287,7 @@ export async function download_task(
|
||||
}
|
||||
}
|
||||
let load_times = 0;
|
||||
let reload = false;
|
||||
function load() {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const errors: unknown[] = [];
|
||||
@@ -343,10 +344,11 @@ export async function download_task(
|
||||
async function download() {
|
||||
const re = await (download_original
|
||||
? i.load_original_image()
|
||||
: i.load_image());
|
||||
: i.load_image(reload));
|
||||
if (re === undefined) {
|
||||
throw Error("Failed to fetch image.");
|
||||
}
|
||||
reload = false;
|
||||
m.set_details_started(i.index);
|
||||
const len = re.headers.get("Content-Length");
|
||||
if (len) {
|
||||
@@ -440,6 +442,7 @@ export async function download_task(
|
||||
if (e.name == "AbortError") {
|
||||
m.remove_details(i.index);
|
||||
reject(new TimeoutError());
|
||||
reload = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -449,6 +452,7 @@ export async function download_task(
|
||||
) {
|
||||
m.remove_details(i.index);
|
||||
reject(e);
|
||||
reload = true;
|
||||
return;
|
||||
}
|
||||
errors.push(e);
|
||||
|
||||
Reference in New Issue
Block a user