allow setting separate timeout / max size for imports

This commit is contained in:
fly_mc 2024-11-11 22:06:04 +08:00
parent edd83acaab
commit 59aa6b1509
4 changed files with 26 additions and 4 deletions

View file

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

View file

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

View file

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

View file

@ -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';