refactor: fix type

This commit is contained in:
syuilo 2022-04-17 13:26:31 +09:00
parent 1ee757cc5f
commit 2d2b3edaaf
2 changed files with 6 additions and 6 deletions

View File

@ -2,10 +2,10 @@ import config from '@/config/index.js';
import { getJson } from '@/misc/fetch.js'; import { getJson } from '@/misc/fetch.js';
import { ILocalUser } from '@/models/entities/user.js'; import { ILocalUser } from '@/models/entities/user.js';
import { getInstanceActor } from '@/services/instance-actor.js'; import { getInstanceActor } from '@/services/instance-actor.js';
import { signedGet } from './request.js';
import { IObject, isCollectionOrOrderedCollection, ICollection, IOrderedCollection } from './type.js';
import { fetchMeta } from '@/misc/fetch-meta.js'; import { fetchMeta } from '@/misc/fetch-meta.js';
import { extractDbHost } from '@/misc/convert-host.js'; import { extractDbHost } from '@/misc/convert-host.js';
import { signedGet } from './request.js';
import { IObject, isCollectionOrOrderedCollection, ICollection, IOrderedCollection } from './type.js';
export default class Resolver { export default class Resolver {
private history: Set<string>; private history: Set<string>;
@ -56,13 +56,13 @@ export default class Resolver {
this.user = await getInstanceActor(); this.user = await getInstanceActor();
} }
const object = this.user const object = (this.user
? await signedGet(value, this.user) ? await signedGet(value, this.user)
: await getJson(value, 'application/activity+json, application/ld+json'); : await getJson(value, 'application/activity+json, application/ld+json')) as IObject;
if (object == null || ( if (object == null || (
Array.isArray(object['@context']) ? Array.isArray(object['@context']) ?
!object['@context'].includes('https://www.w3.org/ns/activitystreams') : !(object['@context'] as unknown[]).includes('https://www.w3.org/ns/activitystreams') :
object['@context'] !== 'https://www.w3.org/ns/activitystreams' object['@context'] !== 'https://www.w3.org/ns/activitystreams'
)) { )) {
throw new Error('invalid response'); throw new Error('invalid response');

View File

@ -2,7 +2,7 @@ export type obj = { [x: string]: any };
export type ApObject = IObject | string | (IObject | string)[]; export type ApObject = IObject | string | (IObject | string)[];
export interface IObject { export interface IObject {
'@context': string | obj | obj[]; '@context': string | string[] | obj | obj[];
type: string | string[]; type: string | string[];
id?: string; id?: string;
summary?: string; summary?: string;