parent
43f3f8a058
commit
2a9de356db
|
@ -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());
|
|
||||||
|
|
||||||
let list = await UserLists.findOne({
|
try {
|
||||||
userId: user.id,
|
const listName = line.split(',')[0].trim();
|
||||||
name: listName
|
const { username, host } = parseAcct(line.split(',')[1].trim());
|
||||||
});
|
|
||||||
|
|
||||||
if (list == null) {
|
let list = await UserLists.findOne({
|
||||||
list = await UserLists.save({
|
|
||||||
id: genId(),
|
|
||||||
createdAt: new Date(),
|
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
name: listName,
|
name: listName
|
||||||
userIds: []
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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');
|
logger.succ('Imported');
|
||||||
|
|
Loading…
Reference in New Issue