mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
错误修复
This commit is contained in:
1 parent
fff2172c38
commit
257d9814a9
15 files changed
+48
-54
No files matched your search
@@ -43,8 +43,8 @@ class ContestListHandler extends ContestHandler {
|
||||
}
|
||||
|
||||
class ContestDetailHandler extends ContestHandler {
|
||||
async _prepare({ tid }) {
|
||||
this.tdoc = await contest.get(tid);
|
||||
async _prepare({ domainId, tid }) {
|
||||
this.tdoc = await contest.get(domainId, tid);
|
||||
}
|
||||
|
||||
async get({ domainId, page = 1 }) {
|
||||
@@ -66,7 +66,7 @@ class ContestDetailHandler extends ContestHandler {
|
||||
for (const i in psdict) rdict[psdict[i].rid] = { _id: psdict[i].rid };
|
||||
}
|
||||
} else attended = false;
|
||||
const udict = await user.getList([this.tdoc.owner]);
|
||||
const udict = await user.getList(domainId, [this.tdoc.owner]);
|
||||
const path = [
|
||||
['Hydro', '/'],
|
||||
['contest_main', '/c'],
|
||||
|
||||
@@ -19,7 +19,7 @@ async function _postJudge(rdoc) {
|
||||
contest.updateStatus(rdoc.domainId, rdoc.tid, rdoc.uid, rdoc._id, rdoc.pid, accept, rdoc.score),
|
||||
);
|
||||
}
|
||||
if (await problem.updateStatus(rdoc.rdoc.pid, rdoc.uid, rdoc._id, rdoc.status)) {
|
||||
if (await problem.updateStatus(rdoc.pid, rdoc.uid, rdoc._id, rdoc.status)) {
|
||||
if (accept && !rdoc.rejudged) {
|
||||
tasks.push(
|
||||
problem.inc(rdoc.domainId, rdoc.pid, 'nAccept', 1),
|
||||
|
||||
@@ -73,7 +73,7 @@ class RecordConnectionHandler extends ConnectionHandler {
|
||||
|
||||
async message(msg) {
|
||||
for (const rid of msg.rids) {
|
||||
const rdoc = await record.get(rid); // eslint-disable-line no-await-in-loop
|
||||
const rdoc = await record.get(this.domainId, rid); // eslint-disable-line no-await-in-loop
|
||||
await this.onRecordChange({ value: rdoc }); // eslint-disable-line no-await-in-loop
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ class RecordConnectionHandler extends ConnectionHandler {
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [udoc, pdoc] = await Promise.all([
|
||||
user.getById(this.domainId, rdoc.uid),
|
||||
problem.getById(this.domainId, rdoc.pid),
|
||||
problem.get(this.domainId, rdoc.pid),
|
||||
]);
|
||||
if (pdoc.hidden && !this.user.hasPerm(PERM_VIEW_PROBLEM_HIDDEN)) pdoc = null;
|
||||
this.send({ html: await this.renderHTML('record_main_tr.html', { rdoc, udoc, pdoc }) });
|
||||
|
||||
+5
-4
@@ -238,9 +238,10 @@ async function load() {
|
||||
await server.prepare();
|
||||
await service();
|
||||
const builtinModel = [
|
||||
'document', 'blacklist', 'builtin', 'contest', 'message',
|
||||
'opcount', 'problem', 'record', 'setting', 'solution',
|
||||
'token', 'training', 'user', 'file', 'discussion',
|
||||
'builtin', 'document', 'domain', 'blacklist', 'opcount',
|
||||
'setting', 'token', 'user', 'problem', 'record',
|
||||
'contest', 'message', 'solution', 'training', 'file',
|
||||
'discussion',
|
||||
];
|
||||
for (const i of builtinModel) {
|
||||
const m = require(`./model/${i}`);
|
||||
@@ -250,7 +251,7 @@ async function load() {
|
||||
const dbVer = await system.get('db.ver');
|
||||
if (dbVer !== 1) {
|
||||
const ins = require('./script/install');
|
||||
await ins.run();
|
||||
await ins.run('Root', 'rootroot');
|
||||
}
|
||||
const builtinHandler = [
|
||||
'home', 'problem', 'record', 'judge', 'user',
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ async function dec(_id) {
|
||||
return file.count;
|
||||
}
|
||||
|
||||
async function get(_id, secret = null) {
|
||||
async function get(_id, secret) {
|
||||
const file = await coll.findOne({ _id });
|
||||
if (typeof secret !== 'undefined') {
|
||||
const timestamp = _timestamp();
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
const { ObjectID } = require('bson');
|
||||
const { STATUS_ACCEPTED } = require('./builtin').STATUS;
|
||||
const file = require('./file');
|
||||
const document = require('./document');
|
||||
const domain = require('./domain');
|
||||
const { ProblemNotFoundError } = require('../error');
|
||||
const validator = require('../lib/validator');
|
||||
|
||||
/**
|
||||
* @typedef {import('../interface').Pdoc} Pdoc
|
||||
@@ -30,8 +28,6 @@ async function add(domainId, title, content, owner, {
|
||||
tag = [],
|
||||
hidden = false,
|
||||
}) {
|
||||
validator.checkTitle(title);
|
||||
validator.checkContent(content);
|
||||
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, {
|
||||
@@ -46,7 +42,9 @@ async function add(domainId, title, content, owner, {
|
||||
* @returns {Pdoc}
|
||||
*/
|
||||
async function get(domainId, pid, uid = null) {
|
||||
const pdoc = await document.get(domainId, document.TYPE_PROBLEM, pid);
|
||||
const pdoc = Number.isInteger(pid)
|
||||
? await document.get(domainId, document.TYPE_PROBLEM, pid)
|
||||
: (await document.getMulti(domainId, document.TYPE_PROBLEM, { pid }).toArray())[0];
|
||||
if (!pdoc) throw new ProblemNotFoundError(pid);
|
||||
if (uid) {
|
||||
pdoc.psdoc = await document.getStatus(domainId, document.TYPE_PROBLEM, pdoc.docId, uid);
|
||||
@@ -92,8 +90,6 @@ function getMultiStatus(domainId, query) {
|
||||
* @returns {Pdoc}
|
||||
*/
|
||||
function edit(domainId, _id, $set) {
|
||||
if ($set.title) validator.checkTitle($set.title);
|
||||
if ($set.content) validator.checkContent($set.content);
|
||||
return document.set(domainId, document.TYPE_CONTEST, _id, $set);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ const db = require('../service/db');
|
||||
const coll = db.collection('task');
|
||||
|
||||
async function add(task) {
|
||||
console.log(task);
|
||||
const res = await coll.insertOne(task);
|
||||
return res.insertedId;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@ class USER {
|
||||
}
|
||||
|
||||
async function getPerm(domainId, udoc) {
|
||||
if (udoc._id === 1) { // Is Guest
|
||||
const p = await document.get(domainId, document.TYPE_DOMAIN_ROLE, 'guest');
|
||||
return p.content;
|
||||
}
|
||||
if (udoc.priv === 1) {
|
||||
const p = await document.get(domainId, document.TYPE_DOMAIN_ROLE, 'admin');
|
||||
return p.content;
|
||||
|
||||
+11
-9
@@ -4,7 +4,6 @@ const builtin = require('../model/builtin');
|
||||
const discussion = require('../model/discussion');
|
||||
const system = require('../model/system');
|
||||
const domain = require('../model/domain');
|
||||
const user = require('../model/user');
|
||||
const pwhash = require('../lib/hash.hydro');
|
||||
const { udoc } = require('../interface');
|
||||
|
||||
@@ -20,7 +19,7 @@ const allowFail = async (func, ...args) => {
|
||||
return res;
|
||||
};
|
||||
|
||||
async function run() {
|
||||
async function run(username, password) {
|
||||
const def = {
|
||||
PROBLEM_PER_PAGE: 100,
|
||||
RECORD_PER_PAGE: 100,
|
||||
@@ -52,10 +51,8 @@ async function run() {
|
||||
tasks.push(system.set(key, def[key]));
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
const salt = String.random();
|
||||
tasks = [
|
||||
allowFail(domain.add, 'system', 1),
|
||||
user.setRole('system', 0, 'guest'),
|
||||
allowFail(domain.add, 'system', 0),
|
||||
collUser.updateOne({ _id: 0 }, {
|
||||
$set: defaults({
|
||||
_id: 0,
|
||||
@@ -74,20 +71,25 @@ async function run() {
|
||||
unameLower: 'guest',
|
||||
}, udoc),
|
||||
}, { upsert: true }),
|
||||
];
|
||||
if (username && password) {
|
||||
const salt = String.random();
|
||||
tasks.push(
|
||||
collUser.updateOne({ _id: -1 }, {
|
||||
$set: defaults({
|
||||
_id: -1,
|
||||
mail: 'root@hydro',
|
||||
mailLower: 'root@hydro',
|
||||
uname: 'Root',
|
||||
unameLower: 'root',
|
||||
hash: pwhash.hash('rootroot', salt),
|
||||
uname: username,
|
||||
unameLower: username.trim().toLowerCase(),
|
||||
hash: pwhash.hash(password, salt),
|
||||
salt,
|
||||
gravatar: 'root@hydro',
|
||||
priv: 1,
|
||||
}, udoc),
|
||||
}, { upsert: true }),
|
||||
];
|
||||
);
|
||||
}
|
||||
for (const category in builtin.DEFAULT_NODES) {
|
||||
const nodes = builtin.DEFAULT_NODES[category];
|
||||
for (const node of nodes) {
|
||||
|
||||
+12
-22
@@ -1,23 +1,11 @@
|
||||
const map = [
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
||||
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
|
||||
'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
|
||||
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
|
||||
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8',
|
||||
'9', '0',
|
||||
];
|
||||
const dict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
||||
|
||||
String.random = function random(digit) {
|
||||
let str = '';
|
||||
for (let i = 1; i <= digit; i++) str += map[Math.floor(Math.random() * 62)];
|
||||
for (let i = 1; i <= digit; i++) str += dict[Math.floor(Math.random() * 62)];
|
||||
return str;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array} a
|
||||
* @param {Array} b
|
||||
*/
|
||||
Array.isDiff = function isDiff(a, b) {
|
||||
if (a.length !== b.length) return true;
|
||||
a.sort();
|
||||
@@ -43,15 +31,17 @@ Set.isSuperset = function isSuperset(set, subset) {
|
||||
}
|
||||
return true;
|
||||
};
|
||||
Set.union = function union(setA, setB) {
|
||||
const _union = new Set(setA);
|
||||
for (const elem of setB) _union.add(elem);
|
||||
return _union;
|
||||
|
||||
Set.union = function Union(setA, setB) {
|
||||
const union = new Set(setA);
|
||||
for (const elem of setB) union.add(elem);
|
||||
return union;
|
||||
};
|
||||
Set.intersection = function intersection(setA, setB) {
|
||||
const _intersection = new Set();
|
||||
|
||||
Set.intersection = function Intersection(setA, setB) {
|
||||
const intersection = new Set();
|
||||
for (const elem of setB) {
|
||||
if (setA.has(elem)) _intersection.add(elem);
|
||||
if (setA.has(elem)) intersection.add(elem);
|
||||
}
|
||||
return _intersection;
|
||||
return intersection;
|
||||
};
|
||||
@@ -29,7 +29,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for pdoc in pdocs %}
|
||||
{% set psdoc = psdict[pdoc['_id']] %}
|
||||
{% set psdoc = psdict[pdoc['docId']] %}
|
||||
<tr>
|
||||
{% if handler.hasPerm(perm.PERM_LOGGEDIN) %}
|
||||
{% if psdoc['rid'] %}
|
||||
|
||||
@@ -129,7 +129,7 @@
|
||||
{% if page_name != 'discussion_node' and page_name != 'discussion_detail' %}
|
||||
{% if handler.hasPerm(perm.PERM_LOGGEDIN) %}
|
||||
<dt>{{ _('# My Submissions') }}</dt>
|
||||
<dd><a href="/r?pid={{ pdoc.docId }}&uid_or_name={{ handler.user['_id'] }}">{{ pdoc['psdoc'].nSubmit|default(0) }}</a></dd>
|
||||
<dd><a href="/r?pid={{ pdoc.docId }}&uid_or_name={{ handler.user._id }}">{{ pdoc['psdoc'].nSubmit|default(0) }}</a></dd>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<dt>{{ _('Accepted') }}</dt>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<div class="section__body">
|
||||
<iframe src="/p/{{ pdoc.pid }}/upload" frameborder="0" style="width: 100%; height: 100px;"></iframe>
|
||||
<p class="help-text">{{ _('Hint') }}: <a href="/wiki/help#upload">{{ _('Dataset Format') }}</a>, {{ _('An example of dataset') }}: <a href="https://github.com/vijos/jd4/blob/master/jd4/testdata/aplusb-legacy.zip?raw=true">{{ _('Download') }}</a></p>
|
||||
{% if pdoc and (pdoc.owner == user._id or handler.hasPerm(perm.PERM_READ_PROBLEM_DATA)) %}
|
||||
{% if pdoc and (pdoc.owner == handler.user._id or handler.hasPerm(perm.PERM_READ_PROBLEM_DATA)) %}
|
||||
<p><a href="/p/{{ pdoc.pid }}/data" class="expanded button">{{ _('Download Dataset') }}</a></p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<a href="/c/{{ tdoc.docId }}">{{ tdoc.title }}</a>
|
||||
</dd>
|
||||
{% endif %}
|
||||
{% if pdoc and (user._id == pdoc.owner or handler.hasPerm(perm.PERM_READ_PROBLEM_DATA)) %}
|
||||
{% if pdoc and (handler.user._id == pdoc.owner or handler.hasPerm(perm.PERM_READ_PROBLEM_DATA)) %}
|
||||
<dt>{{ _('Problem Data') }}</dt>
|
||||
<dd><a href="/p/{{ pdoc.pid }}/data"><span class="icon icon-download"></span> {{ _('Download') }}</a></dd>
|
||||
{% endif %}
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
<td class="col--name col--problem-name">
|
||||
{% if handler.hasPerm(perm.PERM_LOGGEDIN) %}
|
||||
<form class="form--inline" action="/p" method="post">
|
||||
<input type="hidden" name="pid" value="{{ pdoc['_id'] }}">
|
||||
<input type="hidden" name="pid" value="{{ pdoc.docId }}">
|
||||
<input type="hidden" name="operation" value="{% if not psdoc['star'] %}star{% else %}unstar{% endif %}">
|
||||
<input type="hidden" name="csrfToken" value="{{ handler.csrfToken }}">
|
||||
<button class="star{% if psdoc['star'] %} activated{% endif %}" type="submit">
|
||||
|
||||
Reference in new issue
Block a user