mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-06-06 05:38:44 +08:00
Add new settings download_timeout_check_interval
This commit is contained in:
@@ -31,6 +31,7 @@ export type ConfigType = {
|
||||
download_timeout: number;
|
||||
ffprobe_path: string;
|
||||
redirect_to_flutter: boolean;
|
||||
download_timeout_check_interval: number;
|
||||
};
|
||||
|
||||
export enum ThumbnailMethod {
|
||||
@@ -190,6 +191,9 @@ export class Config {
|
||||
get redirect_to_flutter() {
|
||||
return this._return_bool("redirect_to_flutter") ?? true;
|
||||
}
|
||||
get download_timeout_check_interval() {
|
||||
return this._return_number("download_timeout_check_interval") || 10;
|
||||
}
|
||||
to_json(): ConfigType {
|
||||
return {
|
||||
cookies: typeof this.cookies === "string",
|
||||
@@ -220,6 +224,8 @@ export class Config {
|
||||
download_timeout: this.download_timeout,
|
||||
ffprobe_path: this.ffprobe_path,
|
||||
redirect_to_flutter: this.redirect_to_flutter,
|
||||
download_timeout_check_interval:
|
||||
this.download_timeout_check_interval,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,6 +346,7 @@ export async function download_task(
|
||||
const pr = new ProgressReadable(
|
||||
re.body,
|
||||
cfg.download_timeout,
|
||||
cfg.download_timeout_check_interval,
|
||||
force_abort,
|
||||
);
|
||||
pr.addEventListener("progress", (e) => {
|
||||
|
||||
@@ -8,6 +8,7 @@ export class ProgressReadable extends EventTarget {
|
||||
readed: number;
|
||||
error?: unknown;
|
||||
timeout: number;
|
||||
interval: number;
|
||||
get signal() {
|
||||
return this.#controller.signal;
|
||||
}
|
||||
@@ -21,11 +22,13 @@ export class ProgressReadable extends EventTarget {
|
||||
constructor(
|
||||
readable: ReadableStream<Uint8Array>,
|
||||
timeout: number,
|
||||
interval: number,
|
||||
originalSignal?: AbortSignal,
|
||||
) {
|
||||
super();
|
||||
this.readed = 0;
|
||||
this.timeout = timeout;
|
||||
this.interval = interval;
|
||||
this.#is_timeout = false;
|
||||
this.#last_readed = Date.now();
|
||||
const reader = readable.getReader();
|
||||
@@ -91,7 +94,7 @@ export class ProgressReadable extends EventTarget {
|
||||
this.#controller.abort();
|
||||
this.#clearInterval();
|
||||
}
|
||||
}, 1);
|
||||
}, this.interval);
|
||||
}
|
||||
// @ts-ignore Checked type
|
||||
addEventListener<T extends keyof EventMap>(
|
||||
|
||||
Reference in New Issue
Block a user