diff --git a/config.ts b/config.ts index b7a4c10..9775de5 100644 --- a/config.ts +++ b/config.ts @@ -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, }; } } diff --git a/tasks/download.ts b/tasks/download.ts index c75cd50..5a4c53a 100644 --- a/tasks/download.ts +++ b/tasks/download.ts @@ -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) => { diff --git a/utils/progress_readable.ts b/utils/progress_readable.ts index c2bd20a..9fd3e51 100644 --- a/utils/progress_readable.ts +++ b/utils/progress_readable.ts @@ -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, 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(