AP featured collectionの修正 / Collection Activityの対応 / typeの修正など (#5460)

* resolver type / fix updateFeatured

* type ApObject

* fix strange type

* AP Activity

* Collection Activityが失敗したらとりあえず無視
This commit is contained in:
MeiMei
2019-09-27 04:58:28 +09:00
committed by syuilo
parent 3a093f8bd7
commit e14509574d
10 changed files with 85 additions and 106 deletions

View File

@@ -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<ICollection | IOrderedCollection> {
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<IObject> {
public async resolve(value: string | IObject): Promise<IObject> {
if (value == null) {
throw new Error('resolvee is null (or undefined)');
}