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;
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,
};
}
}

View File

@@ -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) => {

View File

@@ -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>(