* Fix #4484

* import order
This commit is contained in:
MeiMei 2019-03-12 23:38:11 +09:00 committed by syuilo
parent c56b94ae96
commit 0a0aa0e2db
7 changed files with 35 additions and 14 deletions

21
src/misc/convert-host.ts Normal file
View file

@ -0,0 +1,21 @@
import config from '../config';
import { toUnicode, toASCII } from 'punycode';
export function getFullApAccount(username: string, host: string) {
return host ? `${username}@${toApHost(host)}` : `${username}@${toApHost(config.host)}`;
}
export function isSelfHost(host: string) {
if (host == null) return true;
return toApHost(config.host) === toApHost(host);
}
export function toDbHost(host: string) {
if (host == null) return null;
return toUnicode(host.toLowerCase());
}
export function toApHost(host: string) {
if (host == null) return null;
return toASCII(host.toLowerCase());
}

View file

@ -8,7 +8,7 @@ import addFile from '../../../services/drive/add-file';
import User from '../../../models/user'; import User from '../../../models/user';
import dateFormat = require('dateformat'); import dateFormat = require('dateformat');
import Blocking from '../../../models/blocking'; import Blocking from '../../../models/blocking';
import config from '../../../config'; import { getFullApAccount } from '../../../misc/convert-host';
const logger = queueLogger.createSubLogger('export-blocking'); const logger = queueLogger.createSubLogger('export-blocking');
@ -56,7 +56,7 @@ export async function exportBlocking(job: Bull.Job, done: any): Promise<void> {
for (const block of blockings) { for (const block of blockings) {
const u = await User.findOne({ _id: block.blockeeId }, { fields: { username: true, host: true } }); const u = await User.findOne({ _id: block.blockeeId }, { fields: { username: true, host: true } });
const content = u.host ? `${u.username}@${u.host}` : `${u.username}@${config.host}`; const content = getFullApAccount(u.username, u.host);
await new Promise((res, rej) => { await new Promise((res, rej) => {
stream.write(content + '\n', err => { stream.write(content + '\n', err => {
if (err) { if (err) {

View file

@ -8,7 +8,7 @@ import addFile from '../../../services/drive/add-file';
import User from '../../../models/user'; import User from '../../../models/user';
import dateFormat = require('dateformat'); import dateFormat = require('dateformat');
import Following from '../../../models/following'; import Following from '../../../models/following';
import config from '../../../config'; import { getFullApAccount } from '../../../misc/convert-host';
const logger = queueLogger.createSubLogger('export-following'); const logger = queueLogger.createSubLogger('export-following');
@ -56,7 +56,7 @@ export async function exportFollowing(job: Bull.Job, done: any): Promise<void> {
for (const following of followings) { for (const following of followings) {
const u = await User.findOne({ _id: following.followeeId }, { fields: { username: true, host: true } }); const u = await User.findOne({ _id: following.followeeId }, { fields: { username: true, host: true } });
const content = u.host ? `${u.username}@${u.host}` : `${u.username}@${config.host}`; const content = getFullApAccount(u.username, u.host);
await new Promise((res, rej) => { await new Promise((res, rej) => {
stream.write(content + '\n', err => { stream.write(content + '\n', err => {
if (err) { if (err) {

View file

@ -8,7 +8,7 @@ import addFile from '../../../services/drive/add-file';
import User from '../../../models/user'; import User from '../../../models/user';
import dateFormat = require('dateformat'); import dateFormat = require('dateformat');
import Mute from '../../../models/mute'; import Mute from '../../../models/mute';
import config from '../../../config'; import { getFullApAccount } from '../../../misc/convert-host';
const logger = queueLogger.createSubLogger('export-mute'); const logger = queueLogger.createSubLogger('export-mute');
@ -56,7 +56,7 @@ export async function exportMute(job: Bull.Job, done: any): Promise<void> {
for (const mute of mutes) { for (const mute of mutes) {
const u = await User.findOne({ _id: mute.muteeId }, { fields: { username: true, host: true } }); const u = await User.findOne({ _id: mute.muteeId }, { fields: { username: true, host: true } });
const content = u.host ? `${u.username}@${u.host}` : `${u.username}@${config.host}`; const content = getFullApAccount(u.username, u.host);
await new Promise((res, rej) => { await new Promise((res, rej) => {
stream.write(content + '\n', err => { stream.write(content + '\n', err => {
if (err) { if (err) {

View file

@ -7,8 +7,8 @@ import { queueLogger } from '../../logger';
import addFile from '../../../services/drive/add-file'; import addFile from '../../../services/drive/add-file';
import User from '../../../models/user'; import User from '../../../models/user';
import dateFormat = require('dateformat'); import dateFormat = require('dateformat');
import config from '../../../config';
import UserList from '../../../models/user-list'; import UserList from '../../../models/user-list';
import { getFullApAccount } from '../../../misc/convert-host';
const logger = queueLogger.createSubLogger('export-user-lists'); const logger = queueLogger.createSubLogger('export-user-lists');
@ -46,7 +46,7 @@ export async function exportUserLists(job: Bull.Job, done: any): Promise<void> {
}); });
for (const u of users) { for (const u of users) {
const acct = u.host ? `${u.username}@${u.host}` : `${u.username}@${config.host}`; const acct = getFullApAccount(u.username, u.host);
const content = `${list.title},${acct}`; const content = `${list.title},${acct}`;
await new Promise((res, rej) => { await new Promise((res, rej) => {
stream.write(content + '\n', err => { stream.write(content + '\n', err => {

View file

@ -3,13 +3,13 @@ import * as mongo from 'mongodb';
import { queueLogger } from '../../logger'; import { queueLogger } from '../../logger';
import User from '../../../models/user'; import User from '../../../models/user';
import config from '../../../config';
import follow from '../../../services/following/create'; import follow from '../../../services/following/create';
import DriveFile from '../../../models/drive-file'; import DriveFile from '../../../models/drive-file';
import { getOriginalUrl } from '../../../misc/get-drive-file-url'; import { getOriginalUrl } from '../../../misc/get-drive-file-url';
import parseAcct from '../../../misc/acct/parse'; import parseAcct from '../../../misc/acct/parse';
import resolveUser from '../../../remote/resolve-user'; import resolveUser from '../../../remote/resolve-user';
import { downloadTextFile } from '../../../misc/download-text-file'; import { downloadTextFile } from '../../../misc/download-text-file';
import { isSelfHost, toDbHost } from '../../../misc/convert-host';
const logger = queueLogger.createSubLogger('import-following'); const logger = queueLogger.createSubLogger('import-following');
@ -31,11 +31,11 @@ export async function importFollowing(job: Bull.Job, done: any): Promise<void> {
for (const line of csv.trim().split('\n')) { for (const line of csv.trim().split('\n')) {
const { username, host } = parseAcct(line.trim()); const { username, host } = parseAcct(line.trim());
let target = host === config.host ? await User.findOne({ let target = isSelfHost(host) ? await User.findOne({
host: null, host: null,
usernameLower: username.toLowerCase() usernameLower: username.toLowerCase()
}) : await User.findOne({ }) : await User.findOne({
host: host, host: toDbHost(host),
usernameLower: username.toLowerCase() usernameLower: username.toLowerCase()
}); });

View file

@ -3,7 +3,6 @@ import * as mongo from 'mongodb';
import { queueLogger } from '../../logger'; import { queueLogger } from '../../logger';
import User from '../../../models/user'; import User from '../../../models/user';
import config from '../../../config';
import UserList from '../../../models/user-list'; import UserList from '../../../models/user-list';
import DriveFile from '../../../models/drive-file'; import DriveFile from '../../../models/drive-file';
import { getOriginalUrl } from '../../../misc/get-drive-file-url'; import { getOriginalUrl } from '../../../misc/get-drive-file-url';
@ -11,6 +10,7 @@ import parseAcct from '../../../misc/acct/parse';
import resolveUser from '../../../remote/resolve-user'; import resolveUser from '../../../remote/resolve-user';
import { pushUserToUserList } from '../../../services/user-list/push'; import { pushUserToUserList } from '../../../services/user-list/push';
import { downloadTextFile } from '../../../misc/download-text-file'; import { downloadTextFile } from '../../../misc/download-text-file';
import { isSelfHost, toDbHost } from '../../../misc/convert-host';
const logger = queueLogger.createSubLogger('import-user-lists'); const logger = queueLogger.createSubLogger('import-user-lists');
@ -47,11 +47,11 @@ export async function importUserLists(job: Bull.Job, done: any): Promise<void> {
}); });
} }
let target = host === config.host ? await User.findOne({ let target = isSelfHost(host) ? await User.findOne({
host: null, host: null,
usernameLower: username.toLowerCase() usernameLower: username.toLowerCase()
}) : await User.findOne({ }) : await User.findOne({
host: host, host: toDbHost(host),
usernameLower: username.toLowerCase() usernameLower: username.toLowerCase()
}); });