From c6cdfa2f5a0fe3b83acf25d5e27f5b6b80a3540c Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sun, 10 Mar 2019 22:27:25 +0900 Subject: Ignore 4xx references in AP (#4463) * Ignore 4xx references * remove unnecessary comment --- src/remote/activitypub/models/image.ts | 12 +++++++++++- src/remote/activitypub/models/note.ts | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) (limited to 'src/remote/activitypub/models') diff --git a/src/remote/activitypub/models/image.ts b/src/remote/activitypub/models/image.ts index ef0b24e890..bd97d13d27 100644 --- a/src/remote/activitypub/models/image.ts +++ b/src/remote/activitypub/models/image.ts @@ -27,7 +27,17 @@ export async function createImage(actor: IRemoteUser, value: any): Promise= 400 && e < 500) { + logger.warn(`Ignored image: ${image.url} - ${e}`); + return null; + } + throw e; + } if (file.metadata.isRemote) { // URLが異なっている場合、同じ画像が以前に異なるURLで登録されていたということなので、 diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index a87257dffc..7078eb2ce1 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -111,11 +111,22 @@ export async function createNote(value: any, resolver?: Resolver, silent = false note.attachment = Array.isArray(note.attachment) ? note.attachment : note.attachment ? [note.attachment] : []; const files = note.attachment .map(attach => attach.sensitive = note.sensitive) - ? await Promise.all(note.attachment.map(x => limit(() => resolveImage(actor, x)) as Promise)) + ? (await Promise.all(note.attachment.map(x => limit(() => resolveImage(actor, x)) as Promise))) + .filter(image => image != null) : []; // リプライ - const reply = note.inReplyTo ? await resolveNote(note.inReplyTo, resolver) : null; + const reply = note.inReplyTo + ? await resolveNote(note.inReplyTo, resolver).catch(e => { + // 4xxの場合はリプライしてないことにする + if (e.statusCode >= 400 && e.statusCode < 500) { + logger.warn(`Ignored inReplyTo ${note.inReplyTo} - ${e.statusCode} `); + return null; + } + logger.warn(`Error in inReplyTo ${note.inReplyTo} - ${e.statusCode || e}`); + throw e; + }) + : null; // 引用 let quote: INote; -- cgit v1.2.3-freya