diff --git a/src/queue/processors/db/import-following.ts b/src/queue/processors/db/import-following.ts index a1242b71c..069afa74c 100644 --- a/src/queue/processors/db/import-following.ts +++ b/src/queue/processors/db/import-following.ts @@ -28,29 +28,41 @@ export async function importFollowing(job: Bull.Job, done: any): Promise { 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');