mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: 导出比赛代码功能
This commit is contained in:
1 parent
cc08538bdb
commit
b062aa84bf
3 files changed
+8
-10
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.27.1",
|
"version": "2.27.2",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -372,15 +372,13 @@ class ContestCodeHandler extends Handler {
|
|||||||
const [tdoc, tsdocs] = await contest.getAndListStatus(domainId, tid);
|
const [tdoc, tsdocs] = await contest.getAndListStatus(domainId, tid);
|
||||||
const rnames = {};
|
const rnames = {};
|
||||||
for (const tsdoc of tsdocs) {
|
for (const tsdoc of tsdocs) {
|
||||||
for (const pdetail of tsdoc.detail || []) {
|
for (const pid in tsdoc.detail || {}) {
|
||||||
rnames[pdetail.rid] = `U${tsdoc.uid}_P${pdetail.pid}_R${pdetail.rid}`;
|
rnames[tsdoc.detail[pid].rid] = `U${tsdoc.uid}_P${pid}_R${tsdoc.detail[pid].rid}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const zip = new AdmZip();
|
const zip = new AdmZip();
|
||||||
const rdocs = await record.getMulti(domainId, {
|
const rdocs = await record.getMulti(domainId, {
|
||||||
_id: {
|
_id: { $in: Array.from(Object.keys(rnames)).map((id) => new ObjectID(id)) },
|
||||||
$in: Array.from(Object.keys(rnames)).map((id) => new ObjectID(id)),
|
|
||||||
},
|
|
||||||
}).toArray();
|
}).toArray();
|
||||||
for (const rdoc of rdocs) {
|
for (const rdoc of rdocs) {
|
||||||
zip.addFile(`${rnames[rdoc._id.toHexString()]}.${rdoc.lang}`, Buffer.from(rdoc.code));
|
zip.addFile(`${rnames[rdoc._id.toHexString()]}.${rdoc.lang}`, Buffer.from(rdoc.code));
|
||||||
@@ -393,7 +391,7 @@ class ContestCreateHandler extends Handler {
|
|||||||
async get() {
|
async get() {
|
||||||
this.response.template = 'contest_edit.html';
|
this.response.template = 'contest_edit.html';
|
||||||
const rules = {};
|
const rules = {};
|
||||||
for (const i in contest.RULES) { rules[i] = contest.RULES[i].TEXT; }
|
for (const i in contest.RULES) rules[i] = contest.RULES[i].TEXT;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
let ts = now.getTime();
|
let ts = now.getTime();
|
||||||
ts = ts - (ts % (15 * 60 * 1000)) + 15 * 60 * 1000;
|
ts = ts - (ts % (15 * 60 * 1000)) + 15 * 60 * 1000;
|
||||||
|
|||||||
@@ -405,8 +405,8 @@ class HomeworkCodeHandler extends Handler {
|
|||||||
);
|
);
|
||||||
const rnames = {};
|
const rnames = {};
|
||||||
for (const tsdoc of tsdocs) {
|
for (const tsdoc of tsdocs) {
|
||||||
for (const pdetail of tsdoc.detail || []) {
|
for (const pid in tsdoc.detail || {}) {
|
||||||
rnames[pdetail.rid] = `U${tsdoc.uid}_P${pdetail.pid}_R${pdetail.rid}`;
|
rnames[tsdoc.detail[pid].rid] = `U${tsdoc.uid}_P${pid}_R${tsdoc.detail[pid].rid}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const zip = new AdmZip();
|
const zip = new AdmZip();
|
||||||
@@ -418,7 +418,7 @@ class HomeworkCodeHandler extends Handler {
|
|||||||
for (const rdoc of rdocs) {
|
for (const rdoc of rdocs) {
|
||||||
zip.addFile(`${rnames[rdoc._id.toHexString()]}.${rdoc.lang}`, Buffer.from(rdoc.code));
|
zip.addFile(`${rnames[rdoc._id.toHexString()]}.${rdoc.lang}`, Buffer.from(rdoc.code));
|
||||||
}
|
}
|
||||||
await this.binary(zip.toBuffer(), `${tdoc.title}.zip`);
|
this.binary(zip.toBuffer(), `${tdoc.title}.zip`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user