Merge branch 'develop' of https://github.com/syuilo/misskey into develop

This commit is contained in:
syuilo 2019-03-13 23:27:21 +09:00
commit b157e9535e
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
5 changed files with 38 additions and 1 deletions

View file

@ -14,6 +14,7 @@ const merge = (...args) => args.reduce((a, c) => ({
}), {}); }), {});
const languages = [ const languages = [
'cs-CZ',
'de-DE', 'de-DE',
'en-US', 'en-US',
'es-ES', 'es-ES',
@ -24,9 +25,11 @@ const languages = [
'nl-NL', 'nl-NL',
'pl-PL', 'pl-PL',
'zh-CN', 'zh-CN',
'zh-TW',
]; ];
const primaries = { const primaries = {
'en': 'US',
'ja': 'JP', 'ja': 'JP',
'zh': 'CN', 'zh': 'CN',
}; };

View file

@ -1,5 +1,6 @@
import config from '../config'; import config from '../config';
import { toUnicode, toASCII } from 'punycode'; import { toUnicode, toASCII } from 'punycode';
import { URL } from 'url';
export function getFullApAccount(username: string, host: string) { export function getFullApAccount(username: string, host: string) {
return host ? `${username}@${toApHost(host)}` : `${username}@${toApHost(config.host)}`; return host ? `${username}@${toApHost(host)}` : `${username}@${toApHost(config.host)}`;
@ -10,6 +11,11 @@ export function isSelfHost(host: string) {
return toApHost(config.host) === toApHost(host); return toApHost(config.host) === toApHost(host);
} }
export function extractDbHost(uri: string) {
const url = new URL(uri);
return toDbHost(url.hostname);
}
export function toDbHost(host: string) { export function toDbHost(host: string) {
if (host == null) return null; if (host == null) return null;
return toUnicode(host.toLowerCase()); return toUnicode(host.toLowerCase());

View file

@ -5,6 +5,8 @@ import { IAnnounce, INote } from '../../type';
import { fetchNote, resolveNote } from '../../models/note'; import { fetchNote, resolveNote } from '../../models/note';
import { resolvePerson } from '../../models/person'; import { resolvePerson } from '../../models/person';
import { apLogger } from '../../logger'; import { apLogger } from '../../logger';
import { extractDbHost } from '../../../../misc/convert-host';
import Instance from '../../../../models/instance';
const logger = apLogger; const logger = apLogger;
@ -23,6 +25,11 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity:
throw new Error('invalid announce'); throw new Error('invalid announce');
} }
// アナウンス先をブロックしてたら中断
// TODO: いちいちデータベースにアクセスするのはコスト高そうなのでどっかにキャッシュしておく
const instance = await Instance.findOne({ host: extractDbHost(uri) });
if (instance && instance.isBlocked) return;
// 既に同じURIを持つものが登録されていないかチェック // 既に同じURIを持つものが登録されていないかチェック
const exist = await fetchNote(uri); const exist = await fetchNote(uri);
if (exist) { if (exist) {

View file

@ -19,6 +19,8 @@ import vote from '../../../services/note/polls/vote';
import { apLogger } from '../logger'; import { apLogger } from '../logger';
import { IDriveFile } from '../../../models/drive-file'; import { IDriveFile } from '../../../models/drive-file';
import { deliverQuestionUpdate } from '../../../services/note/polls/update'; import { deliverQuestionUpdate } from '../../../services/note/polls/update';
import Instance from '../../../models/instance';
import { extractDbHost } from '../../../misc/convert-host';
const logger = apLogger; const logger = apLogger;
@ -132,7 +134,15 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
let quote: INote; let quote: INote;
if (note._misskey_quote && typeof note._misskey_quote == 'string') { if (note._misskey_quote && typeof note._misskey_quote == 'string') {
quote = await resolveNote(note._misskey_quote).catch(() => null); quote = await resolveNote(note._misskey_quote).catch(e => {
// 4xxの場合は引用してないことにする
if (e.statusCode >= 400 && e.statusCode < 500) {
logger.warn(`Ignored quote target ${note.inReplyTo} - ${e.statusCode} `);
return null;
}
logger.warn(`Error in quote target ${note.inReplyTo} - ${e.statusCode || e}`);
throw e;
});
} }
const cw = note.summary === '' ? null : note.summary; const cw = note.summary === '' ? null : note.summary;
@ -214,6 +224,11 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
export async function resolveNote(value: string | IObject, resolver?: Resolver): Promise<INote> { export async function resolveNote(value: string | IObject, resolver?: Resolver): Promise<INote> {
const uri = typeof value == 'string' ? value : value.id; const uri = typeof value == 'string' ? value : value.id;
// ブロックしてたら中断
// TODO: いちいちデータベースにアクセスするのはコスト高そうなのでどっかにキャッシュしておく
const instance = await Instance.findOne({ host: extractDbHost(uri) });
if (instance && instance.isBlocked) throw { statusCode: 451 };
//#region このサーバーに既に登録されていたらそれを返す //#region このサーバーに既に登録されていたらそれを返す
const exist = await fetchNote(uri); const exist = await fetchNote(uri);

View file

@ -8,6 +8,8 @@ import Note, { pack as packNote, INote } from '../../../../models/note';
import { createNote } from '../../../../remote/activitypub/models/note'; import { createNote } from '../../../../remote/activitypub/models/note';
import Resolver from '../../../../remote/activitypub/resolver'; import Resolver from '../../../../remote/activitypub/resolver';
import { ApiError } from '../../error'; import { ApiError } from '../../error';
import Instance from '../../../../models/instance';
import { extractDbHost } from '../../../../misc/convert-host';
export const meta = { export const meta = {
tags: ['federation'], tags: ['federation'],
@ -61,6 +63,10 @@ async function fetchAny(uri: string) {
if (packed !== null) return packed; if (packed !== null) return packed;
} }
// ブロックしてたら中断
const instance = await Instance.findOne({ host: extractDbHost(uri) });
if (instance && instance.isBlocked) return null;
// URI(AP Object id)としてDB検索 // URI(AP Object id)としてDB検索
{ {
const [user, note] = await Promise.all([ const [user, note] = await Promise.all([