diff --git a/src/queue/processors/db/import-user-lists.ts b/src/queue/processors/db/import-user-lists.ts index 1e852be945b29435705c62d80ab744f77ab47d74..4692d8cf49ec2f994286ac5b8713041d99ebab4b 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<void> { 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()); - - let list = await UserLists.findOne({ - userId: user.id, - name: listName - }); - - if (list == null) { - list = await UserLists.save({ - id: genId(), - createdAt: new Date(), + linenum++; + + try { + const listName = line.split(',')[0].trim(); + const { username, host } = parseAcct(line.split(',')[1].trim()); + + let list = await UserLists.findOne({ userId: user.id, - name: listName, - userIds: [] + name: listName }); - } - let target = isSelfHost(host!) ? await Users.findOne({ - host: null, - usernameLower: username.toLowerCase() - }) : await Users.findOne({ - host: toPuny(host!), - usernameLower: username.toLowerCase() - }); + if (list == null) { + list = await UserLists.save({ + id: genId(), + createdAt: new Date(), + userId: user.id, + name: listName, + userIds: [] + }); + } - if (target == null) { - target = await resolveUser(username, host); - } + let target = isSelfHost(host!) ? await Users.findOne({ + host: null, + usernameLower: username.toLowerCase() + }) : await Users.findOne({ + host: toPuny(host!), + usernameLower: username.toLowerCase() + }); - if (await UserListJoinings.findOne({ userListId: list.id, userId: target.id }) != null) continue; + if (target == null) { + target = await resolveUser(username, host); + } - pushUserToUserList(target, list); + if (await UserListJoinings.findOne({ userListId: list.id, userId: target.id }) != null) continue; + + pushUserToUserList(target, list); + } catch (e) { + logger.warn(`Error in line:${linenum} ${e}`); + } } logger.succ('Imported');