From 785a5f6f68565037223f4e796ccc4a79fd4c56c1 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 19:15:45 +0900 Subject: [PATCH] WIP(`ApPersonService.ts`): `analyzeAttachments` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Field型を事前に定義しておくように - `attachments`が`IObject`だった場合、返り値が`{ fields: [] }`になるようだが構わないのか? - `toArray()`を通すべきでは? --- .../src/core/activitypub/models/ApPersonService.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 43a2142120..fae4ffbac3 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -48,6 +48,8 @@ import type { IActor, IObject } from '../type.js'; const nameLength = 128; const summaryLength = 2048; +type Field = Record<'name' | 'value', string>; + @Injectable() export class ApPersonService implements OnModuleInit { private utilityService: UtilityService; @@ -576,11 +578,10 @@ export class ApPersonService implements OnModuleInit { } @bindThis - public analyzeAttachments(attachments: IObject | IObject[] | undefined) { - const fields: { - name: string, - value: string - }[] = []; + // TODO: `attachments`が`IObject`だった場合、返り値が`{ fields: [] }`になるようだが構わないのか? + public analyzeAttachments(attachments: IObject | IObject[] | undefined): { fields: Field[] } { + const fields: Field[] = []; + if (Array.isArray(attachments)) { for (const attachment of attachments.filter(isPropertyValue)) { fields.push({