From 59aa6b15096909c479cc559be2e710b55bcb39c6 Mon Sep 17 00:00:00 2001 From: fly_mc Date: Mon, 11 Nov 2024 22:06:04 +0800 Subject: [PATCH] allow setting separate timeout / max size for imports --- .config/docker_example.yml | 6 ++++++ .config/example.yml | 6 ++++++ packages/backend/src/config.ts | 10 ++++++++++ packages/backend/src/core/DownloadService.ts | 8 ++++---- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.config/docker_example.yml b/.config/docker_example.yml index 7d51ab044..5c20894cd 100644 --- a/.config/docker_example.yml +++ b/.config/docker_example.yml @@ -225,3 +225,9 @@ signToActivityPubGet: true # Upload or download file size limits (bytes) #maxFileSize: 262144000 + + +# timeout and maximum size for imports (e.g. note imports) +#import: +# downloadTimeout: 30 +# maxFileSize: 262144000 diff --git a/.config/example.yml b/.config/example.yml index ce336d9f7..e91f96c86 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -327,3 +327,9 @@ signToActivityPubGet: true # PID File of master process #pidFile: /tmp/misskey.pid + + +# timeout and maximum size for imports (e.g. note imports) +#import: +# downloadTimeout: 30 +# maxFileSize: 262144000 diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index e3abb583c..ee91bd094 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -101,6 +101,11 @@ type Source = { deactivateAntennaThreshold?: number; pidFile: string; avatarDecorationAllowedHosts: string[] | undefined; + + import?: { + downloadTimeout: number; + maxFileSize: number; + }; }; export type Config = { @@ -186,6 +191,10 @@ export type Config = { deactivateAntennaThreshold: number; pidFile: string; avatarDecorationAllowedHosts: string[] | undefined; + import: { + downloadTimeout: number; + maxFileSize: number; + } | undefined; }; const _filename = fileURLToPath(import.meta.url); @@ -299,6 +308,7 @@ export function loadConfig(): Config { deactivateAntennaThreshold: config.deactivateAntennaThreshold ?? (1000 * 60 * 60 * 24 * 7), pidFile: config.pidFile, avatarDecorationAllowedHosts: config.avatarDecorationAllowedHosts, + import: config.import, }; } diff --git a/packages/backend/src/core/DownloadService.ts b/packages/backend/src/core/DownloadService.ts index 93f4a3824..83452845d 100644 --- a/packages/backend/src/core/DownloadService.ts +++ b/packages/backend/src/core/DownloadService.ts @@ -35,14 +35,14 @@ export class DownloadService { } @bindThis - public async downloadUrl(url: string, path: string): Promise<{ + public async downloadUrl(url: string, path: string, options: { timeout?: number, operationTimeout?: number, maxSize?: number} = {} ): Promise<{ filename: string; }> { this.logger.info(`Downloading ${chalk.cyan(url)} to ${chalk.cyanBright(path)} ...`); - const timeout = 30 * 1000; - const operationTimeout = 60 * 1000; - const maxSize = this.config.maxFileSize; + const timeout = options.timeout ?? 30 * 1000; + const operationTimeout = options.operationTimeout ?? 60 * 1000; + const maxSize = options.maxSize ?? this.config.maxFileSize ?? 262144000; const urlObj = new URL(url); let filename = urlObj.pathname.split('/').pop() ?? 'untitled';