diff --git a/README.md b/README.md index fbf96cffb2..58e41b02ca 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Please see the [Contribution Guide](./CONTRIBUTING.md). Atsuko Tominaga - + @@ -154,7 +154,7 @@ Please see the [Contribution Guide](./CONTRIBUTING.md).
natalienatalie Hiratake @Hekovic@gyutte.site dansupTakashi Shibuya
-**Last updated:** Thu, 07 Mar 2019 11:30:05 UTC +**Last updated:** Sun, 10 Mar 2019 22:17:05 UTC :four_leaf_clover: Copyright diff --git a/src/remote/activitypub/kernel/announce/note.ts b/src/remote/activitypub/kernel/announce/note.ts index 128ca6da81..8d090902c0 100644 --- a/src/remote/activitypub/kernel/announce/note.ts +++ b/src/remote/activitypub/kernel/announce/note.ts @@ -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}`); 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; diff --git a/src/remote/activitypub/resolver.ts b/src/remote/activitypub/resolver.ts index 6291d133e9..05152993e4 100644 --- a/src/remote/activitypub/resolver.ts +++ b/src/remote/activitypub/resolver.ts @@ -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; @@ -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 { 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'); } diff --git a/src/server/proxy/proxy-media.ts b/src/server/proxy/proxy-media.ts index 842dbff29e..2eec2012f3 100644 --- a/src/server/proxy/proxy-media.ts +++ b/src/server/proxy/proxy-media.ts @@ -6,7 +6,7 @@ import * as request from 'request'; import fileType from 'file-type'; import { serverLogger } from '..'; import config from '../../config'; -import { IImage, ConvertToPng } from '../../services/drive/image-processor'; +import { IImage, ConvertToPng, ConvertToJpeg } from '../../services/drive/image-processor'; import checkSvg from '../../misc/check-svg'; export async function proxyMedia(ctx: Koa.BaseContext) { @@ -29,6 +29,8 @@ export async function proxyMedia(ctx: Koa.BaseContext) { if ('static' in ctx.query && ['image/png', 'image/gif'].includes(type)) { image = await ConvertToPng(path, 498, 280); + } else if ('preview' in ctx.query && ['image/jpeg', 'image/png', 'image/gif'].includes(type)) { + image = await ConvertToJpeg(path, 200, 200); } else { image = { data: fs.readFileSync(path), diff --git a/src/server/web/url-preview.ts b/src/server/web/url-preview.ts index 90c1a4930a..aed475e6ff 100644 --- a/src/server/web/url-preview.ts +++ b/src/server/web/url-preview.ts @@ -3,6 +3,8 @@ import * as request from 'request-promise-native'; import summaly from 'summaly'; import fetchMeta from '../../misc/fetch-meta'; import Logger from '../../services/logger'; +import config from '../../config'; +import { query } from '../../prelude/url'; const logger = new Logger('url-preview'); @@ -44,7 +46,10 @@ module.exports = async (ctx: Koa.BaseContext) => { function wrap(url: string): string { return url != null ? url.match(/^https?:\/\//) - ? `https://images.weserv.nl/?url=${encodeURIComponent(url.replace(/^http:\/\//, '').replace(/^https:\/\//, 'ssl:'))}&w=200&h=200` + ? `${config.url}/proxy/preview.jpg?${query({ + url, + preview: '1' + })}` : url : null; } diff --git a/src/services/drive/upload-from-url.ts b/src/services/drive/upload-from-url.ts index 558f020a34..89efe8a50e 100644 --- a/src/services/drive/upload-from-url.ts +++ b/src/services/drive/upload-from-url.ts @@ -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(); });