Skip to content

Commit

Permalink
Add new settings download_timeout_check_interval
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc committed Feb 4, 2024
1 parent c9c92f0 commit 1e72c05
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
};
}
}
Expand Down
1 change: 1 addition & 0 deletions tasks/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
5 changes: 4 additions & 1 deletion utils/progress_readable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class ProgressReadable extends EventTarget {
readed: number;
error?: unknown;
timeout: number;
interval: number;
get signal() {
return this.#controller.signal;
}
Expand All @@ -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();
Expand Down Expand Up @@ -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>(
Expand Down

0 comments on commit 1e72c05

Please sign in to comment.