migrate: add randomMail option

This commit is contained in:
undefined committed 2024-05-14 23:24:47 +08:00
1 parent ffe06804a7
commit dcf16996c1
3 files changed
+9 -2

No files matched your search

+1
View File
@@ -31,6 +31,7 @@ export function apply(ctx: Context) {
password: Schema.string().required(),
domainId: Schema.string().default('system'),
dataDir: Schema.string().default('/opt/syzoj/web/uploads'),
randomMail: Schema.union(['never', 'needed', 'always']).default('never'),
}),
(...args) => require('./scripts/syzoj').run(...args),
);
+6 -2
View File
@@ -74,7 +74,7 @@ const langMap = {
export async function run({
host = 'localhost', port = 3306, name = 'syzoj',
username, password, domainId, dataDir,
rerun = true, randomMail = false,
rerun = true, randomMail = 'never',
}, report: Function) {
const src = await mariadb.createConnection({
host,
@@ -114,9 +114,13 @@ export async function run({
const precheck = await UserModel.getMulti({ unameLower: { $in: udocs.map((u) => u.username.toLowerCase()) } }).toArray();
if (precheck.length) throw new Error(`Conflict username: ${precheck.map((u) => u.unameLower).join(', ')}`);
for (const udoc of udocs) {
if (randomMail) delete udoc.email;
if (randomMail === 'always') delete udoc.email;
let current = await UserModel.getByEmail(domainId, udoc.email || `${udoc.username}@syzoj.local`);
current ||= await UserModel.getByUname(domainId, udoc.username);
if (current && randomMail === 'needed') {
delete udoc.email;
current = await UserModel.getByEmail(domainId, udoc.email || `${udoc.username}@syzoj.local`);
}
if (current) {
report({ message: `duplicate user with email ${udoc.email}: ${current.uname},${udoc.username}` });
uidMap[udoc.id] = current._id;
@@ -7,6 +7,8 @@
{% if rdoc['time'] %}
<dt>{{ _('Total Time') }}</dt>
<dd>{% if _ge %}&ge;{% endif %}{{ rdoc.time|round(0) }}ms</dd>
{% endif %}
{% if rdoc.testCases.length %}
<dt>{{ _('Peak Time') }}</dt>
<dd>{% if _ge %}&ge;{% endif %}{{ (rdoc.testCases|sort(true, true, "time")|first)["time"]|round(0) }}ms</dd>
{% endif %}