This commit is contained in:
MeiMei 2019-04-06 00:41:08 +09:00 committed by syuilo
parent c0927a24be
commit 949ed1e48a

View file

@ -28,29 +28,41 @@ export async function importFollowing(job: Bull.Job, done: any): Promise<void> {
const csv = await downloadTextFile(url);
let linenum = 0;
for (const line of csv.trim().split('\n')) {
const { username, host } = parseAcct(line.trim());
linenum++;
let target = isSelfHost(host) ? await User.findOne({
host: null,
usernameLower: username.toLowerCase()
}) : await User.findOne({
host: toDbHost(host),
usernameLower: username.toLowerCase()
});
try {
const { username, host } = parseAcct(line.trim());
if (host == null && target == null) continue;
let target = isSelfHost(host) ? await User.findOne({
host: null,
usernameLower: username.toLowerCase()
}) : await User.findOne({
host: toDbHost(host),
usernameLower: username.toLowerCase()
});
if (target == null) {
target = await resolveUser(username, host);
if (host == null && target == null) continue;
if (target == null) {
target = await resolveUser(username, host);
}
if (target == null) {
throw `cannot resolve user: @${username}@${host}`;
}
// skip myself
if (target._id.equals(job.data.user._id)) continue;
logger.info(`Follow[${linenum}] ${target._id} ...`);
follow(user, target);
} catch (e) {
logger.warn(`Error in line:${linenum} ${e}`);
}
// skip myself
if (target._id.equals(job.data.user._id)) continue;
logger.info(`Follow ${target._id} ...`);
follow(user, target);
}
logger.succ('Imported');