summaryrefslogtreecommitdiff
path: root/packages/backend/src/queue/processors
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-06-03 16:29:19 +0000
committerAmelia Yukii <amelia.yukii@shourai.de>2024-06-03 16:29:19 +0000
commit082e1d1afb44cc866d75c37ab5e0f7ca8701796b (patch)
tree62cb28706906f18cf6a8ab2f2efe7838cc654972 /packages/backend/src/queue/processors
parentmerge: set the correct "marked an NSFW" when loading admin-user (!483) (diff)
downloadsharkey-082e1d1afb44cc866d75c37ab5e0f7ca8701796b.tar.gz
sharkey-082e1d1afb44cc866d75c37ab5e0f7ca8701796b.tar.bz2
sharkey-082e1d1afb44cc866d75c37ab5e0f7ca8701796b.zip
allow setting separate timeout / max size for imports - fixes #479
Diffstat (limited to 'packages/backend/src/queue/processors')
-rw-r--r--packages/backend/src/queue/processors/ImportNotesProcessorService.ts21
1 files changed, 15 insertions, 6 deletions
diff --git a/packages/backend/src/queue/processors/ImportNotesProcessorService.ts b/packages/backend/src/queue/processors/ImportNotesProcessorService.ts
index 7cef858c51..58a0ea10ad 100644
--- a/packages/backend/src/queue/processors/ImportNotesProcessorService.ts
+++ b/packages/backend/src/queue/processors/ImportNotesProcessorService.ts
@@ -19,12 +19,16 @@ import { IdService } from '@/core/IdService.js';
import { QueueLoggerService } from '../QueueLoggerService.js';
import type * as Bull from 'bullmq';
import type { DbNoteImportToDbJobData, DbNoteImportJobData, DbNoteWithParentImportToDbJobData } from '../types.js';
+import type { Config } from '@/config.js';
@Injectable()
export class ImportNotesProcessorService {
private logger: Logger;
constructor(
+ @Inject(DI.config)
+ private config: Config,
+
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
@@ -74,6 +78,11 @@ export class ImportNotesProcessorService {
}
@bindThis
+ private downloadUrl(url: string, path:string): Promise<{filename: string}> {
+ return this.downloadService.downloadUrl(url, path, { operationTimeout: this.config.import?.downloadTimeout, maxSize: this.config.import?.maxFileSize });
+ }
+
+ @bindThis
private async recreateChain(idFieldPath: string[], replyFieldPath: string[], arr: any[], includeOrphans: boolean): Promise<any[]> {
type NotesMap = {
[id: string]: any;
@@ -176,7 +185,7 @@ export class ImportNotesProcessorService {
try {
await fsp.writeFile(destPath, '', 'binary');
- await this.downloadService.downloadUrl(file.url, destPath);
+ await this.downloadUrl(file.url, destPath);
} catch (e) { // TODO: 何度か再試行
if (e instanceof Error || typeof e === 'string') {
this.logger.error(e);
@@ -206,7 +215,7 @@ export class ImportNotesProcessorService {
try {
await fsp.writeFile(destPath, '', 'binary');
- await this.downloadService.downloadUrl(file.url, destPath);
+ await this.downloadUrl(file.url, destPath);
} catch (e) { // TODO: 何度か再試行
if (e instanceof Error || typeof e === 'string') {
this.logger.error(e);
@@ -239,7 +248,7 @@ export class ImportNotesProcessorService {
try {
await fsp.writeFile(destPath, '', 'binary');
- await this.downloadService.downloadUrl(file.url, destPath);
+ await this.downloadUrl(file.url, destPath);
} catch (e) { // TODO: 何度か再試行
if (e instanceof Error || typeof e === 'string') {
this.logger.error(e);
@@ -297,7 +306,7 @@ export class ImportNotesProcessorService {
try {
await fsp.writeFile(path, '', 'utf-8');
- await this.downloadService.downloadUrl(file.url, path);
+ await this.downloadUrl(file.url, path);
} catch (e) { // TODO: 何度か再試行
if (e instanceof Error || typeof e === 'string') {
this.logger.error(e);
@@ -349,7 +358,7 @@ export class ImportNotesProcessorService {
if (!exists) {
try {
- await this.downloadService.downloadUrl(file.url, filePath);
+ await this.downloadUrl(file.url, filePath);
} catch (e) { // TODO: 何度か再試行
this.logger.error(e instanceof Error ? e : new Error(e as string));
}
@@ -488,7 +497,7 @@ export class ImportNotesProcessorService {
if (!exists) {
try {
- await this.downloadService.downloadUrl(file.url, filePath);
+ await this.downloadUrl(file.url, filePath);
} catch (e) { // TODO: 何度か再試行
this.logger.error(e instanceof Error ? e : new Error(e as string));
}