From e14509574d534a74fcebf9515146b028bbdec153 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 27 Sep 2019 04:58:28 +0900 Subject: AP featured collectionの修正 / Collection Activityの対応 / typeの修正など (#5460) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * resolver type / fix updateFeatured * type ApObject * fix strange type * AP Activity * Collection Activityが失敗したらとりあえず無視 --- src/remote/activitypub/resolver.ts | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'src/remote/activitypub/resolver.ts') diff --git a/src/remote/activitypub/resolver.ts b/src/remote/activitypub/resolver.ts index d656c1c5e5..5b82244536 100644 --- a/src/remote/activitypub/resolver.ts +++ b/src/remote/activitypub/resolver.ts @@ -1,5 +1,5 @@ import * as request from 'request-promise-native'; -import { IObject } from './type'; +import { IObject, isCollectionOrOrderedCollection, ICollection, IOrderedCollection } from './type'; import config from '../../config'; export default class Resolver { @@ -14,31 +14,19 @@ export default class Resolver { return Array.from(this.history); } - public async resolveCollection(value: any) { + public async resolveCollection(value: string | IObject): Promise { const collection = typeof value === 'string' ? await this.resolve(value) : value; - switch (collection.type) { - case 'Collection': { - collection.objects = collection.items; - break; - } - - case 'OrderedCollection': { - collection.objects = collection.orderedItems; - break; - } - - default: { - throw new Error(`unknown collection type: ${collection.type}`); - } + if (isCollectionOrOrderedCollection(collection)) { + return collection; + } else { + throw new Error(`unknown collection type: ${collection.type}`); } - - return collection; } - public async resolve(value: any): Promise { + public async resolve(value: string | IObject): Promise { if (value == null) { throw new Error('resolvee is null (or undefined)'); } -- cgit v1.2.3-freya