Fix url type of AP object #6231 (#6234)

This commit is contained in:
MeiMei 2020-04-11 18:27:58 +09:00 committed by GitHub
parent aa34000f0b
commit 9fcf94b197
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View file

@ -17,7 +17,7 @@ import { deliverQuestionUpdate } from '../../../services/note/polls/update';
import { extractDbHost, toPuny } from '../../../misc/convert-host'; import { extractDbHost, toPuny } from '../../../misc/convert-host';
import { Notes, Emojis, Polls, MessagingMessages } from '../../../models'; import { Notes, Emojis, Polls, MessagingMessages } from '../../../models';
import { Note } from '../../../models/entities/note'; import { Note } from '../../../models/entities/note';
import { IObject, getOneApId, getApId, validPost, IPost, isEmoji } from '../type'; import { IObject, getOneApId, getApId, getOneApHrefNullable, validPost, IPost, isEmoji } from '../type';
import { Emoji } from '../../../models/entities/emoji'; import { Emoji } from '../../../models/entities/emoji';
import { genId } from '../../../misc/gen-id'; import { genId } from '../../../misc/gen-id';
import { fetchMeta } from '../../../misc/fetch-meta'; import { fetchMeta } from '../../../misc/fetch-meta';
@ -282,7 +282,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
apEmojis, apEmojis,
poll, poll,
uri: note.id, uri: note.id,
url: note.url, url: getOneApHrefNullable(note.url),
}, silent); }, silent);
} }

View file

@ -3,7 +3,7 @@ import * as promiseLimit from 'promise-limit';
import config from '../../../config'; import config from '../../../config';
import Resolver from '../resolver'; import Resolver from '../resolver';
import { resolveImage } from './image'; import { resolveImage } from './image';
import { isCollectionOrOrderedCollection, isCollection, IPerson, getApId, IObject, isPropertyValue, IApPropertyValue } from '../type'; import { isCollectionOrOrderedCollection, isCollection, IPerson, getApId, getOneApHrefNullable, IObject, isPropertyValue, IApPropertyValue } from '../type';
import { fromHtml } from '../../../mfm/fromHtml'; import { fromHtml } from '../../../mfm/fromHtml';
import { htmlToMfm } from '../misc/html-to-mfm'; import { htmlToMfm } from '../misc/html-to-mfm';
import { resolveNote, extractEmojis } from './note'; import { resolveNote, extractEmojis } from './note';
@ -166,7 +166,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
await transactionalEntityManager.save(new UserProfile({ await transactionalEntityManager.save(new UserProfile({
userId: user.id, userId: user.id,
description: person.summary ? htmlToMfm(person.summary, person.tag) : null, description: person.summary ? htmlToMfm(person.summary, person.tag) : null,
url: person.url, url: getOneApHrefNullable(person.url),
fields, fields,
userHost: host userHost: host
})); }));
@ -353,7 +353,7 @@ export async function updatePerson(uri: string, resolver?: Resolver | null, hint
}); });
await UserProfiles.update({ userId: exist.id }, { await UserProfiles.update({ userId: exist.id }, {
url: person.url, url: getOneApHrefNullable(person.url),
fields, fields,
description: person.summary ? htmlToMfm(person.summary, person.tag) : null, description: person.summary ? htmlToMfm(person.summary, person.tag) : null,
}); });

View file

@ -19,7 +19,7 @@ export interface IObject {
endTime?: Date; endTime?: Date;
icon?: any; icon?: any;
image?: any; image?: any;
url?: string; url?: ApObject;
href?: string; href?: string;
tag?: IObject | IObject[]; tag?: IObject | IObject[];
sensitive?: boolean; sensitive?: boolean;
@ -51,6 +51,17 @@ export function getApId(value: string | IObject): string {
throw new Error(`cannot detemine id`); throw new Error(`cannot detemine id`);
} }
export function getOneApHrefNullable(value: ApObject | undefined): string | undefined {
const firstOne = Array.isArray(value) ? value[0] : value;
return getApHrefNullable(firstOne);
}
export function getApHrefNullable(value: string | IObject | undefined): string | undefined {
if (typeof value === 'string') return value;
if (typeof value?.href === 'string') return value.href;
return undefined;
}
export interface IActivity extends IObject { export interface IActivity extends IObject {
//type: 'Activity'; //type: 'Activity';
actor: IObject | string; actor: IObject | string;