From 5518c2b7d4bb617cfddc120c206e6d87f237f8f6 Mon Sep 17 00:00:00 2001 From: Hazel Koehler Date: Fri, 3 May 2024 01:01:56 -0400 Subject: [PATCH] fix: cover duplicated block --- .../core/activitypub/models/ApNoteService.ts | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 41046c163..2569c22dd 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -214,15 +214,7 @@ export class ApNoteService { } // 添付ファイル - // TODO: attachmentは必ずしもImageではない - // TODO: attachmentは必ずしも配列ではない - const limit = promiseLimit(2); - const files = (await Promise.all(toArray(note.attachment).map(attach => ( - limit(() => this.apImageService.resolveImage(actor, { - ...attach, - sensitive: note.sensitive, // Noteがsensitiveなら添付もsensitiveにする - })) - )))); + const files = await this.getNoteFiles(note, actor); // リプライ const reply: MiNote | null = note.inReplyTo @@ -441,21 +433,7 @@ export class ApNoteService { } // 添付ファイル - const attachments = toArray(note.attachment); - if (note.image) - for (const image of toArray(note.image)) - attachments.push(image); - - const limit = promiseLimit(2); - const filePromises = attachments - .filter(attach => typeof(attach.url) === 'string') - .map(attach => ( - limit(() => this.apImageService.resolveImage(actor, { - ...attach, - sensitive: note.sensitive, // Noteがsensitiveなら添付もsensitiveにする - })) - )); - const files = await Promise.all(filePromises); + const files = await this.getNoteFiles(note, actor); // リプライ const reply: MiNote | null = note.inReplyTo @@ -566,6 +544,28 @@ export class ApNoteService { } } + /** + * Downloads all attachments from the note. + */ + private async getNoteFiles(note: IPost, actor: MiRemoteUser): Promise { + const attachments = toArray(note.attachment); + if (note.image) + for (const image of toArray(note.image)) + attachments.push(image); + + const limit = promiseLimit(2); + const filePromises = attachments + .filter(attach => typeof (attach.url) === 'string') + .map(attach => ( + limit(() => this.apImageService.resolveImage(actor, { + ...attach, + sensitive: note.sensitive, // Noteがsensitiveなら添付もsensitiveにする + })) + )); + + return await Promise.all(filePromises); + } + /** * Noteを解決します。 *