mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add Types.Set
This commit is contained in:
1 parent
43d721b630
commit
c9fdd26504
3 files changed
+15
-6
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.17.20",
|
"version": "2.17.21",
|
||||||
"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",
|
||||||
|
|||||||
@@ -171,7 +171,9 @@ export class ProblemDetailHandler extends ProblemHandler {
|
|||||||
this.pdoc = await problem.get(domainId, pid, this.user._id);
|
this.pdoc = await problem.get(domainId, pid, this.user._id);
|
||||||
if (!this.pdoc) throw new ProblemNotFoundError(domainId, pid);
|
if (!this.pdoc) throw new ProblemNotFoundError(domainId, pid);
|
||||||
if (this.pdoc.hidden && this.pdoc.owner !== this.user._id) {
|
if (this.pdoc.hidden && this.pdoc.owner !== this.user._id) {
|
||||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
if (!this.user.hasPriv(PRIV.PRIV_JUDGE)) {
|
||||||
|
this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await bus.serial('problem/get', this.pdoc, this);
|
await bus.serial('problem/get', this.pdoc, this);
|
||||||
this.udoc = await user.getById(domainId, this.pdoc.owner);
|
this.udoc = await user.getById(domainId, this.pdoc.owner);
|
||||||
@@ -401,15 +403,17 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
|||||||
@param('testdata', Types.Boolean)
|
@param('testdata', Types.Boolean)
|
||||||
@param('additional_file', Types.Boolean)
|
@param('additional_file', Types.Boolean)
|
||||||
async get(domainId: string, getTestdata = true, getAdditionalFile = true) {
|
async get(domainId: string, getTestdata = true, getAdditionalFile = true) {
|
||||||
const canReadData = this.user._id === this.pdoc.owner || this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA);
|
const canReadData = this.user.hasPriv(PRIV.PRIV_JUDGE)
|
||||||
|
|| this.user._id === this.pdoc.owner
|
||||||
|
|| this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA);
|
||||||
this.response.body.testdata = (getTestdata && canReadData) ? this.pdoc.data : [];
|
this.response.body.testdata = (getTestdata && canReadData) ? this.pdoc.data : [];
|
||||||
this.response.body.additional_file = (getAdditionalFile ? this.pdoc.additional_file : []);
|
this.response.body.additional_file = (getAdditionalFile ? this.pdoc.additional_file : []);
|
||||||
this.response.template = 'problem_files.html';
|
this.response.template = 'problem_files.html';
|
||||||
}
|
}
|
||||||
|
|
||||||
@post('files', Types.Array)
|
@post('files', Types.Set)
|
||||||
@post('type', Types.Range(['testdata', 'additional_file']), true)
|
@post('type', Types.Range(['testdata', 'additional_file']), true)
|
||||||
async postGetLinks(domainId: string, files: string[], type = 'testdata') {
|
async postGetLinks(domainId: string, files: Set<string>, type = 'testdata') {
|
||||||
const isJudge = this.user.hasPriv(PRIV.PRIV_JUDGE);
|
const isJudge = this.user.hasPriv(PRIV.PRIV_JUDGE);
|
||||||
if (type === 'testdata' && !isJudge) {
|
if (type === 'testdata' && !isJudge) {
|
||||||
if (this.user._id !== this.pdoc.owner) {
|
if (this.user._id !== this.pdoc.owner) {
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ export interface Types {
|
|||||||
Time: Type,
|
Time: Type,
|
||||||
Range: (range: Array<string | number> | Dictionary<any>) => Type,
|
Range: (range: Array<string | number> | Dictionary<any>) => Type,
|
||||||
Array: Type,
|
Array: Type,
|
||||||
|
Set: Type,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Types: Types = {
|
export const Types: Types = {
|
||||||
@@ -133,7 +134,11 @@ export const Types: Types = {
|
|||||||
],
|
],
|
||||||
Array: [(v) => {
|
Array: [(v) => {
|
||||||
if (v instanceof Array) return v;
|
if (v instanceof Array) return v;
|
||||||
return [v] || [];
|
return v ? [v] : [];
|
||||||
|
}, null],
|
||||||
|
Set: [(v) => {
|
||||||
|
if (v instanceof Array) return new Set(v);
|
||||||
|
return v ? new Set([v]) : new Set();
|
||||||
}, null],
|
}, null],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user