Ignore 4xx references in AP (#4463)
* Ignore 4xx references * remove unnecessary comment
This commit is contained in:
parent
0fff2e4f16
commit
c6cdfa2f5a
|
@ -29,7 +29,19 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity:
|
|||
return;
|
||||
}
|
||||
|
||||
const renote = await resolveNote(note);
|
||||
// Announce対象をresolve
|
||||
let renote;
|
||||
try {
|
||||
renote = await resolveNote(note);
|
||||
} catch (e) {
|
||||
// 対象が4xxならスキップ
|
||||
if (e.statusCode >= 400 && e.statusCode < 500) {
|
||||
logger.warn(`Ignored announce target ${note.inReplyTo} - ${e.statusCode}`);
|
||||
return;
|
||||
}
|
||||
logger.warn(`Error in announce target ${note.inReplyTo} - ${e.statusCode || e}`);
|
||||
throw e;
|
||||
}
|
||||
|
||||
logger.info(`Creating the (Re)Note: ${uri}`);
|
||||
|
||||
|
|
|
@ -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で登録されていたということなので、
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import * as request from 'request-promise-native';
|
||||
import { IObject } from './type';
|
||||
import config from '../../config';
|
||||
import { apLogger } from './logger';
|
||||
|
||||
export const logger = apLogger.createSubLogger('resolver');
|
||||
|
||||
export default class Resolver {
|
||||
private history: Set<string>;
|
||||
|
@ -34,7 +31,6 @@ export default class Resolver {
|
|||
}
|
||||
|
||||
default: {
|
||||
logger.error(`unknown collection type: ${collection.type}`);
|
||||
throw new Error(`unknown collection type: ${collection.type}`);
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +40,6 @@ export default class Resolver {
|
|||
|
||||
public async resolve(value: any): Promise<IObject> {
|
||||
if (value == null) {
|
||||
logger.error('resolvee is null (or undefined)');
|
||||
throw new Error('resolvee is null (or undefined)');
|
||||
}
|
||||
|
||||
|
@ -53,7 +48,6 @@ export default class Resolver {
|
|||
}
|
||||
|
||||
if (this.history.has(value)) {
|
||||
logger.error(`cannot resolve already resolved one: ${value}`);
|
||||
throw new Error('cannot resolve already resolved one');
|
||||
}
|
||||
|
||||
|
@ -68,12 +62,6 @@ export default class Resolver {
|
|||
Accept: 'application/activity+json, application/ld+json'
|
||||
},
|
||||
json: true
|
||||
}).catch(e => {
|
||||
logger.error(`request error: ${value}: ${e.message}`, {
|
||||
url: value,
|
||||
e: e
|
||||
});
|
||||
throw new Error(`request error: ${e.message}`);
|
||||
});
|
||||
|
||||
if (object === null || (
|
||||
|
@ -81,10 +69,6 @@ export default class Resolver {
|
|||
!object['@context'].includes('https://www.w3.org/ns/activitystreams') :
|
||||
object['@context'] !== 'https://www.w3.org/ns/activitystreams'
|
||||
)) {
|
||||
logger.error(`invalid response: ${value}`, {
|
||||
url: value,
|
||||
object: object
|
||||
});
|
||||
throw new Error('invalid response');
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ export default async (
|
|||
const writable = fs.createWriteStream(path);
|
||||
|
||||
writable.on('finish', () => {
|
||||
logger.succ(`Download succeeded: ${chalk.cyan(url)}`);
|
||||
logger.succ(`Download finished: ${chalk.cyan(url)}`);
|
||||
res();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue