parent
59dc929431
commit
63b1689155
1 changed files with 30 additions and 18 deletions
|
@ -28,29 +28,41 @@ export async function importFollowing(job: Bull.Job, done: any): Promise<void> {
|
||||||
|
|
||||||
const csv = await downloadTextFile(url);
|
const csv = await downloadTextFile(url);
|
||||||
|
|
||||||
|
let linenum = 0;
|
||||||
|
|
||||||
for (const line of csv.trim().split('\n')) {
|
for (const line of csv.trim().split('\n')) {
|
||||||
const { username, host } = parseAcct(line.trim());
|
linenum++;
|
||||||
|
|
||||||
let target = isSelfHost(host) ? await User.findOne({
|
try {
|
||||||
host: null,
|
const { username, host } = parseAcct(line.trim());
|
||||||
usernameLower: username.toLowerCase()
|
|
||||||
}) : await User.findOne({
|
|
||||||
host: toDbHost(host),
|
|
||||||
usernameLower: username.toLowerCase()
|
|
||||||
});
|
|
||||||
|
|
||||||
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) {
|
if (host == null && target == null) continue;
|
||||||
target = await resolveUser(username, host);
|
|
||||||
|
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');
|
logger.succ('Imported');
|
||||||
|
|
Loading…
Reference in a new issue