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) # Upload or download file size limits (bytes)
#maxFileSize: 262144000 #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 # PID File of master process
#pidFile: /tmp/misskey.pid #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; deactivateAntennaThreshold?: number;
pidFile: string; pidFile: string;
avatarDecorationAllowedHosts: string[] | undefined; avatarDecorationAllowedHosts: string[] | undefined;
import?: {
downloadTimeout: number;
maxFileSize: number;
};
}; };
export type Config = { export type Config = {
@ -186,6 +191,10 @@ export type Config = {
deactivateAntennaThreshold: number; deactivateAntennaThreshold: number;
pidFile: string; pidFile: string;
avatarDecorationAllowedHosts: string[] | undefined; avatarDecorationAllowedHosts: string[] | undefined;
import: {
downloadTimeout: number;
maxFileSize: number;
} | undefined;
}; };
const _filename = fileURLToPath(import.meta.url); const _filename = fileURLToPath(import.meta.url);
@ -299,6 +308,7 @@ export function loadConfig(): Config {
deactivateAntennaThreshold: config.deactivateAntennaThreshold ?? (1000 * 60 * 60 * 24 * 7), deactivateAntennaThreshold: config.deactivateAntennaThreshold ?? (1000 * 60 * 60 * 24 * 7),
pidFile: config.pidFile, pidFile: config.pidFile,
avatarDecorationAllowedHosts: config.avatarDecorationAllowedHosts, avatarDecorationAllowedHosts: config.avatarDecorationAllowedHosts,
import: config.import,
}; };
} }

View file

@ -35,14 +35,14 @@ export class DownloadService {
} }
@bindThis @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; filename: string;
}> { }> {
this.logger.info(`Downloading ${chalk.cyan(url)} to ${chalk.cyanBright(path)} ...`); this.logger.info(`Downloading ${chalk.cyan(url)} to ${chalk.cyanBright(path)} ...`);
const timeout = 30 * 1000; const timeout = options.timeout ?? 30 * 1000;
const operationTimeout = 60 * 1000; const operationTimeout = options.operationTimeout ?? 60 * 1000;
const maxSize = this.config.maxFileSize; const maxSize = options.maxSize ?? this.config.maxFileSize ?? 262144000;
const urlObj = new URL(url); const urlObj = new URL(url);
let filename = urlObj.pathname.split('/').pop() ?? 'untitled'; let filename = urlObj.pathname.split('/').pop() ?? 'untitled';