mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
测试数据上传时自动读取config
This commit is contained in:
1 parent
0d7d6ea12a
commit
4b3c10b4eb
14 files changed
+89
-42
No files matched your search
@@ -2,7 +2,7 @@ const user = require('./user');
|
||||
const problem = require('./problem');
|
||||
const {
|
||||
ValidationError, ContestNotFoundError, ContestAlreadyAttendedError,
|
||||
ContestNotAttendedError, ProblemNotFoundError, ContestScoreboardHiddenError,
|
||||
ContestNotAttendedError, ContestScoreboardHiddenError,
|
||||
} = require('../error');
|
||||
const { PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD } = require('../permission');
|
||||
const validator = require('../lib/validator');
|
||||
@@ -74,7 +74,9 @@ const acm = {
|
||||
const rows = [columns];
|
||||
for (const [rank, tsdoc] of rankedTsdocs) {
|
||||
const tsddict = {};
|
||||
if (tdoc.detail) { for (const item of tsdoc.journal) tsddict[item.pid] = item; }
|
||||
if (tdoc.detail) {
|
||||
for (const item of tsdoc.journal) tsddict[item.pid] = item;
|
||||
}
|
||||
const row = [];
|
||||
row.push(
|
||||
{ type: 'string', value: rank },
|
||||
@@ -346,13 +348,7 @@ const ContestHandlerMixin = (c) => class extends c {
|
||||
}
|
||||
|
||||
async verifyProblems(domainId, pids) { // eslint-disable-line class-methods-use-this
|
||||
const r = [];
|
||||
for (const pid of pids) {
|
||||
const res = await problem.get(domainId, pid); // eslint-disable-line no-await-in-loop
|
||||
if (res) r.push(res.docId);
|
||||
else throw new ProblemNotFoundError(pid);
|
||||
}
|
||||
return r;
|
||||
return await problem.getList(domainId, pids, true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ function editReply(domainId, drid, content) {
|
||||
async function delReply(domainId, drid) {
|
||||
const drdoc = await getReply(domainId, drid);
|
||||
if (!drdoc) throw new DocumentNotFoundError(drid);
|
||||
return await Promise.all([ // eslint-disable-line no-return-await
|
||||
return await Promise.all([
|
||||
document.deleteOne(domainId, document.TYPE_DISCUSSION_REPLY, drid),
|
||||
document.inc(domainId, document.TYPE_DISCUSSION, drdoc.parentId, 'nReply', -1),
|
||||
]);
|
||||
|
||||
+17
-12
@@ -1,31 +1,36 @@
|
||||
const fs = require('fs');
|
||||
const { ForbiddenError } = require('../error');
|
||||
const db = require('../service/db');
|
||||
const fs = require('../service/gridfs');
|
||||
const gridfs = require('../service/gridfs');
|
||||
const hash = require('../lib/hash.hydro');
|
||||
|
||||
const coll = db.collection('file');
|
||||
const collFile = db.collection('fs.files');
|
||||
const collChunk = db.collection('fs.chunks');
|
||||
|
||||
function _timestamp() {
|
||||
return Math.floor(Number(new Date()) / 1000000);
|
||||
}
|
||||
|
||||
async function add(stream, filename, meta = {}) {
|
||||
const file = await coll.insertOne(meta);
|
||||
const w = fs.openUploadStreamWithId(file.insertedId, filename);
|
||||
async function add(streamOrPath, filename, meta = {}) {
|
||||
if (typeof streamOrPath === 'string') streamOrPath = fs.createReadStream(streamOrPath);
|
||||
const w = gridfs.openUploadStream(filename);
|
||||
await coll.insertOne({ ...meta, _id: w.id });
|
||||
await new Promise((resolve, reject) => {
|
||||
stream.on('end', resolve);
|
||||
stream.on('error', reject);
|
||||
stream.pipe(w);
|
||||
w.on('error', reject);
|
||||
w.on('finish', resolve);
|
||||
streamOrPath.pipe(w);
|
||||
});
|
||||
const c = await fs.find({ _id: file.insertedId }).toArray();
|
||||
await coll.updateOne({ _id: file.insertedId }, { $set: { md5: c[0].md5, size: c[0].size } });
|
||||
return file.insertedId;
|
||||
const c = await gridfs.find({ _id: w.id }).toArray();
|
||||
await coll.updateOne({ _id: w.id }, { $set: { md5: c[0].md5, size: c[0].size } });
|
||||
return w.id;
|
||||
}
|
||||
|
||||
function del(_id) {
|
||||
return Promise.all([
|
||||
coll.deleteOne({ _id }),
|
||||
fs.delete(_id),
|
||||
collFile.deleteOne({ _id }),
|
||||
collChunk.deleteMany({ files_id: _id }),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -58,7 +63,7 @@ async function get(_id, secret) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return fs.openDownloadStream(_id);
|
||||
return gridfs.openDownloadStream(_id);
|
||||
}
|
||||
|
||||
function getMeta(_id) {
|
||||
|
||||
+13
-8
@@ -3,6 +3,7 @@ const file = require('./file');
|
||||
const document = require('./document');
|
||||
const domain = require('./domain');
|
||||
const { ProblemNotFoundError } = require('../error');
|
||||
const readConfig = require('../lib/readConfig');
|
||||
|
||||
/**
|
||||
* @typedef {import('../interface').Pdoc} Pdoc
|
||||
@@ -30,9 +31,13 @@ async function add(domainId, title, content, owner, {
|
||||
}) {
|
||||
const d = await domain.inc(domainId, 'pidCounter', 1);
|
||||
if (!pid) pid = d.pidCounter.toString();
|
||||
return await document.add(domainId, content, owner, document.TYPE_PROBLEM, d.pidCounter, null, null, {
|
||||
pid, title, data, category, tag, hidden, nSubmit: 0, nAccept: 0,
|
||||
});
|
||||
// eslint-disable-next-line no-return-await
|
||||
return await document.add(
|
||||
domainId, content, owner, document.TYPE_PROBLEM, d.pidCounter, null, null,
|
||||
{
|
||||
pid, title, data, category, tag, hidden, nSubmit: 0, nAccept: 0,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,12 +153,12 @@ async function updateStatus(domainId, pid, uid, rid, status) {
|
||||
return true;
|
||||
}
|
||||
|
||||
async function setTestdata(domainId, _id, readStream) {
|
||||
// TODO read config in zipfile
|
||||
async function setTestdata(domainId, _id, filePath) {
|
||||
const pdoc = await get(domainId, _id);
|
||||
const id = await file.add(readStream, 'data.zip');
|
||||
if (pdoc.data && typeof pdoc.data === 'object') file.dec(this.pdoc.data);
|
||||
return await edit(domainId, _id, { data: id }); // eslint-disable-line no-return-await
|
||||
const config = await readConfig(filePath);
|
||||
const id = await file.add(filePath, 'data.zip');
|
||||
if (pdoc.data && typeof pdoc.data === 'object') file.dec(pdoc.data);
|
||||
return await edit(domainId, _id, { data: id, config });
|
||||
}
|
||||
|
||||
global.Hydro.model.problem = module.exports = {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const moment = require('moment-timezone');
|
||||
const builtin = require('./builtin');
|
||||
const options = require('../options');
|
||||
const i18n = require('../lib/i18n');
|
||||
|
||||
const countries = moment.tz.countries();
|
||||
const tzs = new Set();
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ async function changePassword(uid, currentPassword, newPassword) {
|
||||
const udoc = await getById(uid);
|
||||
udoc.checkPassword(currentPassword);
|
||||
const salt = String.random();
|
||||
return await coll.findOneAndUpdate({ // eslint-disable-line no-return-await
|
||||
return await coll.findOneAndUpdate({
|
||||
_id: udoc._id,
|
||||
}, {
|
||||
$set: { salt, hash: pwhash.hash(newPassword, salt), hashType: 'hydro' },
|
||||
|
||||
Reference in new issue
Block a user