Add new settings download_timeout_check_interval

This commit is contained in:
2024-02-04 11:24:03 +08:00
parent c9c92f0bd9
commit 1e72c057ab
3 changed files with 11 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ export type ConfigType = {
download_timeout: number; download_timeout: number;
ffprobe_path: string; ffprobe_path: string;
redirect_to_flutter: boolean; redirect_to_flutter: boolean;
download_timeout_check_interval: number;
}; };
export enum ThumbnailMethod { export enum ThumbnailMethod {
@@ -190,6 +191,9 @@ export class Config {
get redirect_to_flutter() { get redirect_to_flutter() {
return this._return_bool("redirect_to_flutter") ?? true; 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 { to_json(): ConfigType {
return { return {
cookies: typeof this.cookies === "string", cookies: typeof this.cookies === "string",
@@ -220,6 +224,8 @@ export class Config {
download_timeout: this.download_timeout, download_timeout: this.download_timeout,
ffprobe_path: this.ffprobe_path, ffprobe_path: this.ffprobe_path,
redirect_to_flutter: this.redirect_to_flutter, redirect_to_flutter: this.redirect_to_flutter,
download_timeout_check_interval:
this.download_timeout_check_interval,
}; };
} }
} }

View File

@@ -346,6 +346,7 @@ export async function download_task(
const pr = new ProgressReadable( const pr = new ProgressReadable(
re.body, re.body,
cfg.download_timeout, cfg.download_timeout,
cfg.download_timeout_check_interval,
force_abort, force_abort,
); );
pr.addEventListener("progress", (e) => { pr.addEventListener("progress", (e) => {

View File

@@ -8,6 +8,7 @@ export class ProgressReadable extends EventTarget {
readed: number; readed: number;
error?: unknown; error?: unknown;
timeout: number; timeout: number;
interval: number;
get signal() { get signal() {
return this.#controller.signal; return this.#controller.signal;
} }
@@ -21,11 +22,13 @@ export class ProgressReadable extends EventTarget {
constructor( constructor(
readable: ReadableStream<Uint8Array>, readable: ReadableStream<Uint8Array>,
timeout: number, timeout: number,
interval: number,
originalSignal?: AbortSignal, originalSignal?: AbortSignal,
) { ) {
super(); super();
this.readed = 0; this.readed = 0;
this.timeout = timeout; this.timeout = timeout;
this.interval = interval;
this.#is_timeout = false; this.#is_timeout = false;
this.#last_readed = Date.now(); this.#last_readed = Date.now();
const reader = readable.getReader(); const reader = readable.getReader();
@@ -91,7 +94,7 @@ export class ProgressReadable extends EventTarget {
this.#controller.abort(); this.#controller.abort();
this.#clearInterval(); this.#clearInterval();
} }
}, 1); }, this.interval);
} }
// @ts-ignore Checked type // @ts-ignore Checked type
addEventListener<T extends keyof EventMap>( addEventListener<T extends keyof EventMap>(