mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
migrate: add randomMail option
This commit is contained in:
3 files changed
+9
-2
No files matched your search
@@ -31,6 +31,7 @@ export function apply(ctx: Context) {
|
|||||||
password: Schema.string().required(),
|
password: Schema.string().required(),
|
||||||
domainId: Schema.string().default('system'),
|
domainId: Schema.string().default('system'),
|
||||||
dataDir: Schema.string().default('/opt/syzoj/web/uploads'),
|
dataDir: Schema.string().default('/opt/syzoj/web/uploads'),
|
||||||
|
randomMail: Schema.union(['never', 'needed', 'always']).default('never'),
|
||||||
}),
|
}),
|
||||||
(...args) => require('./scripts/syzoj').run(...args),
|
(...args) => require('./scripts/syzoj').run(...args),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ const langMap = {
|
|||||||
export async function run({
|
export async function run({
|
||||||
host = 'localhost', port = 3306, name = 'syzoj',
|
host = 'localhost', port = 3306, name = 'syzoj',
|
||||||
username, password, domainId, dataDir,
|
username, password, domainId, dataDir,
|
||||||
rerun = true, randomMail = false,
|
rerun = true, randomMail = 'never',
|
||||||
}, report: Function) {
|
}, report: Function) {
|
||||||
const src = await mariadb.createConnection({
|
const src = await mariadb.createConnection({
|
||||||
host,
|
host,
|
||||||
@@ -114,9 +114,13 @@ export async function run({
|
|||||||
const precheck = await UserModel.getMulti({ unameLower: { $in: udocs.map((u) => u.username.toLowerCase()) } }).toArray();
|
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(', ')}`);
|
if (precheck.length) throw new Error(`Conflict username: ${precheck.map((u) => u.unameLower).join(', ')}`);
|
||||||
for (const udoc of udocs) {
|
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`);
|
let current = await UserModel.getByEmail(domainId, udoc.email || `${udoc.username}@syzoj.local`);
|
||||||
current ||= await UserModel.getByUname(domainId, udoc.username);
|
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) {
|
if (current) {
|
||||||
report({ message: `duplicate user with email ${udoc.email}: ${current.uname},${udoc.username}` });
|
report({ message: `duplicate user with email ${udoc.email}: ${current.uname},${udoc.username}` });
|
||||||
uidMap[udoc.id] = current._id;
|
uidMap[udoc.id] = current._id;
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
{% if rdoc['time'] %}
|
{% if rdoc['time'] %}
|
||||||
<dt>{{ _('Total Time') }}</dt>
|
<dt>{{ _('Total Time') }}</dt>
|
||||||
<dd>{% if _ge %}≥{% endif %}{{ rdoc.time|round(0) }}ms</dd>
|
<dd>{% if _ge %}≥{% endif %}{{ rdoc.time|round(0) }}ms</dd>
|
||||||
|
{% endif %}
|
||||||
|
{% if rdoc.testCases.length %}
|
||||||
<dt>{{ _('Peak Time') }}</dt>
|
<dt>{{ _('Peak Time') }}</dt>
|
||||||
<dd>{% if _ge %}≥{% endif %}{{ (rdoc.testCases|sort(true, true, "time")|first)["time"]|round(0) }}ms</dd>
|
<dd>{% if _ge %}≥{% endif %}{{ (rdoc.testCases|sort(true, true, "time")|first)["time"]|round(0) }}ms</dd>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in new issue
Block a user