summaryrefslogtreecommitdiff
path: root/src/queue/processors/db/import-following.ts
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2019-04-06 00:41:08 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2019-04-06 00:41:08 +0900
commit63b1689155f2bf81f6d034a78ab0aad609e76fd2 (patch)
treec70ec5625bdfacea9d377139f95b5aeabcaa1038 /src/queue/processors/db/import-following.ts
parentフォローインポートで自分をスキップするように (#4614) (diff)
downloadsharkey-63b1689155f2bf81f6d034a78ab0aad609e76fd2.tar.gz
sharkey-63b1689155f2bf81f6d034a78ab0aad609e76fd2.tar.bz2
sharkey-63b1689155f2bf81f6d034a78ab0aad609e76fd2.zip
Fix #4556 (#4558)
Diffstat (limited to 'src/queue/processors/db/import-following.ts')
-rw-r--r--src/queue/processors/db/import-following.ts44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/queue/processors/db/import-following.ts b/src/queue/processors/db/import-following.ts
index a1242b71c8..069afa74c4 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<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');