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

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');