From dc291c593f755f2e926bb6d0ad4c714ab284f9f4 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:43:32 +0900 Subject: [PATCH] refactor(`ApNoteService.ts`): note.attachment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `toArray()`を使うように - よくわからない条件式を整理 - `as`をなくすために`promiseLimit()`でジェネリクスを使うように --- .../src/core/activitypub/models/ApNoteService.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 4d80f05fa1..9c543bf929 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -170,14 +170,11 @@ export class ApNoteService { // TODO: attachmentは必ずしもImageではない // TODO: attachmentは必ずしも配列ではない // Noteがsensitiveなら添付もsensitiveにする - const limit = promiseLimit(2); + const limit = promiseLimit(2); - note.attachment = Array.isArray(note.attachment) ? note.attachment : note.attachment ? [note.attachment] : []; - const files = note.attachment - .map(attach => attach.sensitive = note.sensitive) - ? (await Promise.all(note.attachment.map(x => limit(() => this.apImageService.resolveImage(actor, x)) as Promise))) - .filter(image => image != null) - : []; + note.attachment = toArray(note.attachment); + note.attachment.forEach(attach => attach.sensitive = note.sensitive); + const files = (await Promise.all(note.attachment.map(x => limit(() => this.apImageService.resolveImage(actor, x))))); // リプライ const reply: Note | null = note.inReplyTo