APリファクタとLD-Signatureの検証に対応 (#6300)
* DbResolver * inbox types * 認証順を変更 * User/Keyあたりをまとめる * LD-Signatue * Validate contexts url * LD-Signature DocumentLoaderにProxyとTimeout
This commit is contained in:
parent
234294d564
commit
070f1f3c6e
20 changed files with 1052 additions and 233 deletions
|
|
@ -3,19 +3,39 @@ import { IRemoteUser } from '../../../../models/entities/user';
|
|||
import { createNote, fetchNote } from '../../models/note';
|
||||
import { getApId, IObject, ICreate } from '../../type';
|
||||
import { getApLock } from '../../../../misc/app-lock';
|
||||
import { extractDbHost } from '../../../../misc/convert-host';
|
||||
|
||||
/**
|
||||
* 投稿作成アクティビティを捌きます
|
||||
*/
|
||||
export default async function(resolver: Resolver, actor: IRemoteUser, note: IObject, silent = false, activity?: ICreate): Promise<void> {
|
||||
export default async function(resolver: Resolver, actor: IRemoteUser, note: IObject, silent = false, activity?: ICreate): Promise<string> {
|
||||
const uri = getApId(note);
|
||||
|
||||
if (typeof note === 'object') {
|
||||
if (actor.uri !== note.attributedTo) {
|
||||
return `skip: actor.uri !== note.attributedTo`;
|
||||
}
|
||||
|
||||
if (typeof note.id === 'string') {
|
||||
if (extractDbHost(actor.uri) !== extractDbHost(note.id)) {
|
||||
return `skip: host in actor.uri !== note.id`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const unlock = await getApLock(uri);
|
||||
|
||||
try {
|
||||
const exist = await fetchNote(note);
|
||||
if (exist == null) {
|
||||
await createNote(note, resolver, silent);
|
||||
if (exist) return 'skip: note exists';
|
||||
|
||||
await createNote(note, resolver, silent);
|
||||
return 'ok';
|
||||
} catch (e) {
|
||||
if (e.statusCode >= 400 && e.statusCode < 500) {
|
||||
return `skip ${e.statusCode}`;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
unlock();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue