This commit is contained in:
MeiMei 2019-04-06 00:41:08 +09:00 committed by syuilo
parent 59dc929431
commit 63b1689155
1 changed files with 30 additions and 18 deletions

View File

@ -28,7 +28,12 @@ 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')) {
linenum++;
try {
const { username, host } = parseAcct(line.trim());
let target = isSelfHost(host) ? await User.findOne({
@ -45,12 +50,19 @@ export async function importFollowing(job: Bull.Job, done: any): Promise<void> {
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 ${target._id} ...`);
logger.info(`Follow[${linenum}] ${target._id} ...`);
follow(user, target);
} catch (e) {
logger.warn(`Error in line:${linenum} ${e}`);
}
}
logger.succ('Imported');