Skip to content
Snippets Groups Projects
Commit 63b16891 authored by MeiMei's avatar MeiMei Committed by syuilo
Browse files

Fix #4556 (#4558)

parent 59dc9294
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
// skip myself
if (target._id.equals(job.data.user._id)) continue;
if (target == null) {
throw `cannot resolve user: @${username}@${host}`;
}
logger.info(`Follow ${target._id} ...`);
// skip myself
if (target._id.equals(job.data.user._id)) continue;
follow(user, target);
logger.info(`Follow[${linenum}] ${target._id} ...`);
follow(user, target);
} catch (e) {
logger.warn(`Error in line:${linenum} ${e}`);
}
}
logger.succ('Imported');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment