mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
migrate: hustoj: update file upload
This commit is contained in:
1 parent
01fea3b6fa
commit
cdce227dad
2 files changed
+22
-15
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/migrate",
|
"name": "@hydrooj/migrate",
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
|
|||||||
@@ -59,11 +59,10 @@ const nameMap = {
|
|||||||
'test.in': 'test0.in',
|
'test.in': 'test0.in',
|
||||||
'test.out': 'test0.out',
|
'test.out': 'test0.out',
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function run({
|
export async function run({
|
||||||
host = 'localhost', port = 3306, name = 'jol',
|
host = 'localhost', port = 3306, name = 'jol',
|
||||||
username, password, domainId, contestType = 'oi',
|
username, password, domainId, contestType = 'oi',
|
||||||
dataDir, rerun = false,
|
dataDir, rerun = true, randomMail = false,
|
||||||
}, report: Function) {
|
}, report: Function) {
|
||||||
const src = mysql.createConnection({
|
const src = mysql.createConnection({
|
||||||
host,
|
host,
|
||||||
@@ -104,7 +103,9 @@ export async function run({
|
|||||||
const precheck = await user.getMulti({ unameLower: { $in: udocs.map((u) => u.user_id.toLowerCase()) } }).toArray();
|
const precheck = await user.getMulti({ unameLower: { $in: udocs.map((u) => u.user_id.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) {
|
||||||
const current = await user.getByEmail(domainId, udoc.email || `${udoc.user_id}@hustoj.local`);
|
if (randomMail) delete udoc.email;
|
||||||
|
let current = await user.getByEmail(domainId, udoc.email || `${udoc.user_id}@hustoj.local`);
|
||||||
|
if (!current) current = await user.getByUname(domainId, udoc.user_id);
|
||||||
if (current) {
|
if (current) {
|
||||||
report({ message: `duplicate user with email ${udoc.email}: ${current.uname},${udoc.user_id}` });
|
report({ message: `duplicate user with email ${udoc.email}: ${current.uname},${udoc.user_id}` });
|
||||||
uidMap[udoc.user_id] = current._id;
|
uidMap[udoc.user_id] = current._id;
|
||||||
@@ -119,6 +120,7 @@ export async function run({
|
|||||||
regat: udoc.reg_time,
|
regat: udoc.reg_time,
|
||||||
hash: udoc.password,
|
hash: udoc.password,
|
||||||
salt: udoc.password,
|
salt: udoc.password,
|
||||||
|
school: udoc.school || '',
|
||||||
hashType: 'hust',
|
hashType: 'hust',
|
||||||
});
|
});
|
||||||
await domain.setUserInDomain(domainId, uid, {
|
await domain.setUserInDomain(domainId, uid, {
|
||||||
@@ -133,6 +135,7 @@ export async function run({
|
|||||||
const [admins] = await query("SELECT * FROM `privilege` WHERE `rightstr` = 'administrator'");
|
const [admins] = await query("SELECT * FROM `privilege` WHERE `rightstr` = 'administrator'");
|
||||||
for (const admin of admins) await domain.setUserRole(domainId, uidMap[admin.user_id], 'root');
|
for (const admin of admins) await domain.setUserRole(domainId, uidMap[admin.user_id], 'root');
|
||||||
const adminUids = admins.map((admin) => uidMap[admin.user_id]);
|
const adminUids = admins.map((admin) => uidMap[admin.user_id]);
|
||||||
|
report({ message: 'user finished' });
|
||||||
|
|
||||||
/*
|
/*
|
||||||
problem_id int 11 N 题目编号,主键
|
problem_id int 11 N 题目编号,主键
|
||||||
@@ -198,6 +201,7 @@ export async function run({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
report({ message: 'problem finished' });
|
||||||
|
|
||||||
/*
|
/*
|
||||||
contest_id int 11 N 竞赛id(主键)
|
contest_id int 11 N 竞赛id(主键)
|
||||||
@@ -215,7 +219,7 @@ export async function run({
|
|||||||
const [tdocs] = await query('SELECT * FROM `contest`');
|
const [tdocs] = await query('SELECT * FROM `contest`');
|
||||||
for (const tdoc of tdocs) {
|
for (const tdoc of tdocs) {
|
||||||
const [pdocs] = await query(`SELECT * FROM \`contest_problem\` WHERE \`contest_id\` = ${tdoc.contest_id}`);
|
const [pdocs] = await query(`SELECT * FROM \`contest_problem\` WHERE \`contest_id\` = ${tdoc.contest_id}`);
|
||||||
const pids = pdocs.map((i) => pidMap[i.problem_id]);
|
const pids = pdocs.map((i) => pidMap[i.problem_id]).filter((i) => i);
|
||||||
const tid = await contest.add(
|
const tid = await contest.add(
|
||||||
domainId, tdoc.title, tdoc.description || 'Description',
|
domainId, tdoc.title, tdoc.description || 'Description',
|
||||||
adminUids[0], contestType, tdoc.start_time, tdoc.end_time, pids, true,
|
adminUids[0], contestType, tdoc.start_time, tdoc.end_time, pids, true,
|
||||||
@@ -223,6 +227,7 @@ export async function run({
|
|||||||
);
|
);
|
||||||
tidMap[tdoc.contest_id] = tid.toHexString();
|
tidMap[tdoc.contest_id] = tid.toHexString();
|
||||||
}
|
}
|
||||||
|
report({ message: 'contest finished' });
|
||||||
|
|
||||||
/*
|
/*
|
||||||
solution 程序运行结果记录
|
solution 程序运行结果记录
|
||||||
@@ -251,16 +256,16 @@ export async function run({
|
|||||||
const [rdocs] = await query(`SELECT * FROM \`solution\` LIMIT ${pageId * step}, ${step}`);
|
const [rdocs] = await query(`SELECT * FROM \`solution\` LIMIT ${pageId * step}, ${step}`);
|
||||||
for (const rdoc of rdocs) {
|
for (const rdoc of rdocs) {
|
||||||
const data: RecordDoc = {
|
const data: RecordDoc = {
|
||||||
status: statusMap[rdoc.result],
|
status: statusMap[rdoc.result] || 0,
|
||||||
_id: Time.getObjectID(rdoc.in_date, false),
|
_id: Time.getObjectID(rdoc.in_date, false),
|
||||||
uid: uidMap[rdoc.user_id],
|
uid: uidMap[rdoc.user_id] || 0,
|
||||||
code: "HustOJ didn't provide user code",
|
code: "HustOJ didn't provide user code",
|
||||||
lang: langMap[rdoc.language],
|
lang: langMap[rdoc.language] || '',
|
||||||
pid: pidMap[rdoc.problem_id],
|
pid: pidMap[rdoc.problem_id] || 0,
|
||||||
domainId,
|
domainId,
|
||||||
score: rdoc.pass_rate ? Math.ceil(rdoc.pass_rate * 100) : rdoc.result === 4 ? 100 : 0,
|
score: rdoc.pass_rate ? Math.ceil(rdoc.pass_rate * 100) : rdoc.result === 4 ? 100 : 0,
|
||||||
time: rdoc.time,
|
time: rdoc.time || 0,
|
||||||
memory: rdoc.memory,
|
memory: rdoc.memory || 0,
|
||||||
judgeTexts: [],
|
judgeTexts: [],
|
||||||
compilerTexts: [],
|
compilerTexts: [],
|
||||||
testCases: [],
|
testCases: [],
|
||||||
@@ -279,9 +284,10 @@ export async function run({
|
|||||||
await contest.attend(domainId, data.contest, uidMap[rdoc.user_id]).catch(noop);
|
await contest.attend(domainId, data.contest, uidMap[rdoc.user_id]).catch(noop);
|
||||||
}
|
}
|
||||||
await record.coll.insertOne(data);
|
await record.coll.insertOne(data);
|
||||||
await postJudge(data);
|
await postJudge(data).catch((err) => report({ message: err.message }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
report({ message: 'record finished' });
|
||||||
|
|
||||||
src.end();
|
src.end();
|
||||||
|
|
||||||
@@ -290,13 +296,14 @@ export async function run({
|
|||||||
const files = await fs.readdir(dataDir, { withFileTypes: true });
|
const files = await fs.readdir(dataDir, { withFileTypes: true });
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (!file.isDirectory()) continue;
|
if (!file.isDirectory()) continue;
|
||||||
const datas = await fs.readdir(`${dataDir}/${file.name}`);
|
const datas = await fs.readdir(`${dataDir}/${file.name}`, { withFileTypes: true });
|
||||||
const pdoc = await problem.get(domainId, `P${file.name}`, undefined, true);
|
const pdoc = await problem.get(domainId, `P${file.name}`, undefined, true);
|
||||||
if (!pdoc) continue;
|
if (!pdoc) continue;
|
||||||
report({ message: `Syncing testdata for ${file.name}` });
|
report({ message: `Syncing testdata for ${file.name}` });
|
||||||
for (const data of datas) {
|
for (const data of datas) {
|
||||||
const filename = nameMap[data] || data;
|
if (data.isDirectory()) continue;
|
||||||
await problem.addTestdata(domainId, pdoc.docId, filename, `${dataDir}/${file.name}/${data}`);
|
const filename = nameMap[data.name] || data;
|
||||||
|
await problem.addTestdata(domainId, pdoc.docId, filename, `${dataDir}/${file.name}/${data.name}`);
|
||||||
}
|
}
|
||||||
await problem.addTestdata(domainId, pdoc.docId, 'config.yaml', Buffer.from(pdoc.config as string));
|
await problem.addTestdata(domainId, pdoc.docId, 'config.yaml', Buffer.from(pdoc.config as string));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user