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

Fix #5611 (#5612)

parent 43f3f8a0
No related branches found
Tags 12.24.1
No related merge requests found
...@@ -30,40 +30,48 @@ export async function importUserLists(job: Bull.Job, done: any): Promise<void> { ...@@ -30,40 +30,48 @@ export async function importUserLists(job: Bull.Job, done: any): Promise<void> {
const csv = await downloadTextFile(file.url); const csv = await downloadTextFile(file.url);
let linenum = 0;
for (const line of csv.trim().split('\n')) { for (const line of csv.trim().split('\n')) {
const listName = line.split(',')[0].trim(); linenum++;
const { username, host } = parseAcct(line.split(',')[1].trim());
try {
let list = await UserLists.findOne({ const listName = line.split(',')[0].trim();
userId: user.id, const { username, host } = parseAcct(line.split(',')[1].trim());
name: listName
}); let list = await UserLists.findOne({
if (list == null) {
list = await UserLists.save({
id: genId(),
createdAt: new Date(),
userId: user.id, userId: user.id,
name: listName, name: listName
userIds: []
}); });
}
let target = isSelfHost(host!) ? await Users.findOne({ if (list == null) {
host: null, list = await UserLists.save({
usernameLower: username.toLowerCase() id: genId(),
}) : await Users.findOne({ createdAt: new Date(),
host: toPuny(host!), userId: user.id,
usernameLower: username.toLowerCase() name: listName,
}); userIds: []
});
}
if (target == null) { let target = isSelfHost(host!) ? await Users.findOne({
target = await resolveUser(username, host); 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'); 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