diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2019-03-10 22:27:25 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2019-03-10 22:27:25 +0900 |
| commit | c6cdfa2f5a0fe3b83acf25d5e27f5b6b80a3540c (patch) | |
| tree | b5589f3a0c362ae4315a892d72e467adc5376ef1 /src/remote/activitypub/models | |
| parent | Remove debug code (diff) | |
| download | sharkey-c6cdfa2f5a0fe3b83acf25d5e27f5b6b80a3540c.tar.gz sharkey-c6cdfa2f5a0fe3b83acf25d5e27f5b6b80a3540c.tar.bz2 sharkey-c6cdfa2f5a0fe3b83acf25d5e27f5b6b80a3540c.zip | |
Ignore 4xx references in AP (#4463)
* Ignore 4xx references
* remove unnecessary comment
Diffstat (limited to 'src/remote/activitypub/models')
| -rw-r--r-- | src/remote/activitypub/models/image.ts | 12 | ||||
| -rw-r--r-- | src/remote/activitypub/models/note.ts | 15 |
2 files changed, 24 insertions, 3 deletions
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<IDriv const instance = await fetchMeta(); const cache = instance.cacheRemoteFiles; - let file = await uploadFromUrl(image.url, actor, null, image.url, image.sensitive, false, !cache); + let file; + try { + file = await uploadFromUrl(image.url, actor, null, image.url, image.sensitive, false, !cache); + } catch (e) { + // 4xxの場合は添付されてなかったことにする + if (e >= 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<IDriveFile>)) + ? (await Promise.all(note.attachment.map(x => limit(() => resolveImage(actor, x)) as Promise<IDriveFile>))) + .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; |