From 2a9de356db0c0c7cae38c8235299821f7ff64509 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Thu, 12 Dec 2019 00:46:10 +0900 Subject: [PATCH] Fix #5611 (#5612) --- src/queue/processors/db/import-user-lists.ts | 64 +++++++++++--------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/src/queue/processors/db/import-user-lists.ts b/src/queue/processors/db/import-user-lists.ts index 1e852be94..4692d8cf4 100644 --- a/src/queue/processors/db/import-user-lists.ts +++ b/src/queue/processors/db/import-user-lists.ts @@ -30,40 +30,48 @@ export async function importUserLists(job: Bull.Job, done: any): Promise { const csv = await downloadTextFile(file.url); + let linenum = 0; + for (const line of csv.trim().split('\n')) { - const listName = line.split(',')[0].trim(); - const { username, host } = parseAcct(line.split(',')[1].trim()); + linenum++; - let list = await UserLists.findOne({ - userId: user.id, - name: listName - }); + try { + const listName = line.split(',')[0].trim(); + const { username, host } = parseAcct(line.split(',')[1].trim()); - if (list == null) { - list = await UserLists.save({ - id: genId(), - createdAt: new Date(), + let list = await UserLists.findOne({ userId: user.id, - name: listName, - userIds: [] + name: listName }); + + if (list == null) { + list = await UserLists.save({ + id: genId(), + createdAt: new Date(), + userId: user.id, + name: listName, + userIds: [] + }); + } + + let target = isSelfHost(host!) ? await Users.findOne({ + host: null, + usernameLower: username.toLowerCase() + }) : await Users.findOne({ + host: toPuny(host!), + usernameLower: username.toLowerCase() + }); + + if (target == null) { + target = await resolveUser(username, host); + } + + if (await UserListJoinings.findOne({ userListId: list.id, userId: target.id }) != null) continue; + + pushUserToUserList(target, list); + } catch (e) { + logger.warn(`Error in line:${linenum} ${e}`); } - - let target = isSelfHost(host!) ? await Users.findOne({ - host: null, - usernameLower: username.toLowerCase() - }) : await Users.findOne({ - host: toPuny(host!), - usernameLower: username.toLowerCase() - }); - - if (target == null) { - target = await resolveUser(username, host); - } - - if (await UserListJoinings.findOne({ userListId: list.id, userId: target.id }) != null) continue; - - pushUserToUserList(target, list); } logger.succ('Imported');