mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
+translation +argType.Range
This commit is contained in:
1 parent
3cb4d2ad49
commit
b472b5c245
19 files changed
+100
-44
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/hydrojudge",
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.3",
|
||||
"main": "package.json",
|
||||
"author": "masnn",
|
||||
"os": [
|
||||
|
||||
@@ -39,7 +39,7 @@ function judgeCase(c) {
|
||||
status = STATUS.STATUS_RUNTIME_ERROR;
|
||||
if (code < 32) message = signals[code];
|
||||
else message = `您的程序返回了 ${code}.`;
|
||||
} else[status, score, message] = resInteractor.files.stderr.split('\n');
|
||||
} else [status, score, message] = resInteractor.files.stderr.split('\n');
|
||||
ctxSubtask.score = Score[ctxSubtask.subtask.type](ctxSubtask.score, score);
|
||||
ctxSubtask.status = Math.max(ctxSubtask.status, status);
|
||||
ctx.total_time_usage_ms += time_usage_ms;
|
||||
|
||||
@@ -3,4 +3,9 @@
|
||||
SETTINGS_PRIVACY.allowRegisteredUsers
|
||||
model.setting.ui.name
|
||||
pdoc.secretConfig?
|
||||
message.markAsRead
|
||||
message.markAsRead
|
||||
Handle OAuth Map !important
|
||||
基于document的model难以lint,建议拆分
|
||||
写test! !important
|
||||
每日签到
|
||||
rp.delta
|
||||
@@ -138,6 +138,7 @@ Content: 内容
|
||||
Contest scoreboard is not visible.: 当前比赛成绩表隐藏,暂不可显示。
|
||||
Contest Scoreboard: 比赛成绩表
|
||||
contest_create: 创建比赛
|
||||
contest_detail: 比赛详情
|
||||
contest_detail_problem_submit: 递交比赛题目
|
||||
contest_edit: 编辑比赛
|
||||
contest_main: 比赛
|
||||
@@ -398,8 +399,6 @@ Login to Attend Contest: 登录后参加比赛
|
||||
Login to Claim Homework: 登录后认领作业
|
||||
Login to Create a Discussion: 登录后创建讨论
|
||||
Login to Submit: 登录后递交
|
||||
Login with Github: 使用 Github 登录
|
||||
Login with Google: 使用 Google 登录
|
||||
Login: 登录
|
||||
Logout All Sessions: 注销所有会话
|
||||
Logout This Session: 注销该会话
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.12.9",
|
||||
"version": "2.12.10",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -23,7 +23,7 @@ import * as bus from '../service/bus';
|
||||
const ContestHandler = contest.ContestHandlerMixin(Handler);
|
||||
|
||||
class ContestListHandler extends ContestHandler {
|
||||
@param('rule', Types.String, true)
|
||||
@param('rule', Types.Range(contest.RULES), true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
async get(domainId: string, rule = '', page = 1) {
|
||||
this.response.template = 'contest_main.html';
|
||||
@@ -34,7 +34,6 @@ class ContestListHandler extends ContestHandler {
|
||||
tdocs = contest.getMulti(domainId).sort({ beginAt: -1 });
|
||||
qs = '';
|
||||
} else {
|
||||
if (!contest.RULES[rule]) throw new ValidationError('rule');
|
||||
tdocs = contest.getMulti(domainId, { rule }).sort({ beginAt: -1 });
|
||||
qs = `rule=${rule}`;
|
||||
}
|
||||
@@ -196,7 +195,7 @@ class ContestEditHandler extends ContestHandler {
|
||||
@param('duration', Types.Float)
|
||||
@param('title', Types.String, isTitle)
|
||||
@param('content', Types.String, isContent)
|
||||
@param('rule', Types.String)
|
||||
@param('rule', Types.Range(contest.RULES))
|
||||
@param('pids', Types.String)
|
||||
@param('rated', Types.Boolean)
|
||||
async post(
|
||||
|
||||
@@ -207,7 +207,7 @@ class DomainJoinApplicationsHandler extends ManageHandler {
|
||||
this.response.template = 'domain_join_applications.html';
|
||||
}
|
||||
|
||||
@param('method', Types.UnsignedInt)
|
||||
@param('method', Types.Range(domain.JOIN_METHOD_RANGE))
|
||||
@param('role', Types.String, true)
|
||||
@param('expire', Types.UnsignedInt, true)
|
||||
@param('invitationCode', Types.String, true)
|
||||
@@ -215,7 +215,6 @@ class DomainJoinApplicationsHandler extends ManageHandler {
|
||||
const r = await domain.getRoles(this.domain);
|
||||
const roles = r.map((rl) => rl._id);
|
||||
const current = domain.getJoinSettings(this.domain, roles);
|
||||
if (!domain.JOIN_METHOD_RANGE[method]) throw new ValidationError('method');
|
||||
let joinSettings;
|
||||
if (method === domain.JOIN_METHOD_NONE) joinSettings = null;
|
||||
else {
|
||||
@@ -245,7 +244,6 @@ class DomainJoinHandler extends Handler {
|
||||
if (this.user.role !== 'default') throw new DomainJoinAlreadyMemberError(this.domain._id, this.user._id);
|
||||
}
|
||||
|
||||
// @base.require_priv(builtin.PRIV_USER_PROFILE)
|
||||
@param('code', Types.String, true)
|
||||
async get(domainId: string, code: string) {
|
||||
this.response.template = 'domain_join.html';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Pdoc } from '../interface';
|
||||
import * as problem from '../model/problem';
|
||||
|
||||
export const description = 'Create a new user';
|
||||
export const description = 'Caculate the difficulty of a problem';
|
||||
|
||||
const _CACHE_INFO = {
|
||||
last_s: 0.0,
|
||||
|
||||
@@ -46,21 +46,34 @@ interface ParamOption {
|
||||
validate?: Validator,
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
export enum Types { String, Int, UnsignedInt, PositiveInt, Float, ObjectID, Boolean, Date, Time }
|
||||
type Type = [Converter, Validator, boolean?];
|
||||
|
||||
const Tools: Array<[Converter, Validator, boolean?]> = [
|
||||
[(v) => v.toString(), null],
|
||||
[(v) => parseInt(v, 10), (v) => isSafeInteger(parseInt(v, 10))],
|
||||
[(v) => parseInt(v, 10), (v) => parseInt(v, 10) >= 0],
|
||||
[(v) => parseInt(v, 10), (v) => parseInt(v, 10) > 0],
|
||||
[(v) => parseFloat(v), (v) => {
|
||||
export interface Types {
|
||||
String: Type,
|
||||
Int: Type,
|
||||
UnsignedInt: Type,
|
||||
PositiveInt: Type,
|
||||
Float: Type,
|
||||
ObjectID: Type,
|
||||
Boolean: Type,
|
||||
Date: Type,
|
||||
Time: Type,
|
||||
Range: (range: Array<string | number> | Dictionary<any>) => Type,
|
||||
}
|
||||
|
||||
export const Types: Types = {
|
||||
String: [(v) => v.toString(), null],
|
||||
Int: [(v) => parseInt(v, 10), (v) => isSafeInteger(parseInt(v, 10))],
|
||||
UnsignedInt: [(v) => parseInt(v, 10), (v) => parseInt(v, 10) >= 0],
|
||||
PositiveInt: [(v) => parseInt(v, 10), (v) => parseInt(v, 10) > 0],
|
||||
Float: [(v) => parseFloat(v), (v) => {
|
||||
const t = parseFloat(v);
|
||||
return t && !Number.isNaN(t) && Number.isFinite(t);
|
||||
}],
|
||||
[(v) => new ObjectID(v), ObjectID.isValid],
|
||||
[(v) => !!v, null, true],
|
||||
[
|
||||
// eslint-disable-next-line no-shadow
|
||||
ObjectID: [(v) => new ObjectID(v), ObjectID.isValid],
|
||||
Boolean: [(v) => !!v, null, true],
|
||||
Date: [
|
||||
(v) => {
|
||||
const d = v.split('-');
|
||||
assert(d.length === 3);
|
||||
@@ -71,8 +84,9 @@ const Tools: Array<[Converter, Validator, boolean?]> = [
|
||||
assert(d.length === 3);
|
||||
const st = `${d[0]}-${d[1].length === 1 ? '0' : ''}${d[1]}-${d[2].length === 1 ? '0' : ''}${d[2]}`;
|
||||
return moment(st).isValid();
|
||||
}],
|
||||
[
|
||||
},
|
||||
],
|
||||
Time: [
|
||||
(v) => {
|
||||
const t = v.split(':');
|
||||
assert(t.length === 2);
|
||||
@@ -84,34 +98,51 @@ const Tools: Array<[Converter, Validator, boolean?]> = [
|
||||
return moment(`2020-01-01 ${(t[0].length === 1 ? '0' : '') + t[0]}:${t[1].length === 1 ? '0' : ''}${t[1]}`).isValid();
|
||||
},
|
||||
],
|
||||
];
|
||||
Range: (range) => [
|
||||
null,
|
||||
(v) => {
|
||||
if (range instanceof Array) {
|
||||
for (const item of range) {
|
||||
if (typeof item === 'string') {
|
||||
if (item === v) return true;
|
||||
} else if (typeof item === 'number') {
|
||||
if (item === parseInt(v, 10)) return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const key in range) {
|
||||
if (key === v) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export function param(name: string, type: Types, validate: Validator): MethodDecorator;
|
||||
export function param(name: string, type?: Types, isOptional?: boolean): MethodDecorator;
|
||||
export function param(name: string, type: Type, validate: Validator): MethodDecorator;
|
||||
export function param(name: string, type?: Type, isOptional?: boolean): MethodDecorator;
|
||||
export function param(
|
||||
name: string, type: Types, validate: null, convert: Converter
|
||||
name: string, type: Type, validate: null, convert: Converter
|
||||
): MethodDecorator;
|
||||
export function param(
|
||||
name: string, type: Types, validate?: Validator, convert?: Converter,
|
||||
name: string, type: Type, validate?: Validator, convert?: Converter,
|
||||
): MethodDecorator;
|
||||
export function param(
|
||||
name: string, type: Types, isOptional?: boolean, validate?: Validator, convert?: Converter,
|
||||
name: string, type: Type, isOptional?: boolean, validate?: Validator, convert?: Converter,
|
||||
): MethodDecorator;
|
||||
export function param(
|
||||
name: string, ...args: Array<Types | boolean | Converter | Validator>
|
||||
name: string, ...args: Array<Type | boolean | Converter | Validator>
|
||||
): MethodDecorator;
|
||||
export function param(name: string, ...args: any): MethodDecorator {
|
||||
let cursor = 0;
|
||||
const v: ParamOption = { name };
|
||||
let isValidate = true;
|
||||
while (cursor < args.length) {
|
||||
if (typeof args[cursor] === 'number') {
|
||||
if (args[cursor] instanceof Array) {
|
||||
const type = args[cursor];
|
||||
if (Tools[type]) {
|
||||
if (Tools[type][0]) v.convert = Tools[type][0];
|
||||
if (Tools[type][1]) v.validate = Tools[type][1];
|
||||
if (Tools[type][2]) v.isOptional = Tools[type][2];
|
||||
}
|
||||
if (type[0]) v.convert = type[0];
|
||||
if (type[1]) v.validate = type[1];
|
||||
if (type[2]) v.isOptional = type[2];
|
||||
} else if (typeof args[cursor] === 'boolean') v.isOptional = args[cursor];
|
||||
else if (isValidate) {
|
||||
if (args[cursor] !== null) v.validate = args[cursor];
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Login With Github: 使用 Github 登录
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/login-with-github",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"main": "package.json",
|
||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||
"author": "undefined <masnn0@outlook.com>",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Login With Google: 使用 Google 登录
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/login-with-google",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"main": "package.json",
|
||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||
"author": "undefined <masnn0@outlook.com>",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Login With Osu: 使用 Osu 登录
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/login-with-osu",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"main": "package.json",
|
||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||
"author": "undefined <masnn0@outlook.com>",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'hydrooj';
|
||||
import { } from 'hydrooj';
|
||||
|
||||
const { md5, sha1 } = global.Hydro.lib;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/migrate-vijos",
|
||||
"version": "1.3.4",
|
||||
"version": "1.3.5",
|
||||
"main": "package.json",
|
||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||
"author": "undefined <masnn0@outlook.com>",
|
||||
|
||||
@@ -205,6 +205,7 @@ const tasks = {
|
||||
display_name: 'displayName',
|
||||
rp: null,
|
||||
rank: null,
|
||||
userfile_usage: null,
|
||||
},
|
||||
record: async (doc) => {
|
||||
const testCases: TestCase[] = [];
|
||||
@@ -417,6 +418,24 @@ async function removeInvalidPid(src: Db, report: Function) {
|
||||
}
|
||||
}
|
||||
|
||||
async function userfileUsage(src: Db, report: Function) {
|
||||
const count = await src.collection('domain.user').find().count();
|
||||
const bulk = dst.collection('user').initializeUnorderedBulkOp();
|
||||
await report({ progress: 1, message: `userfileUsage: ${count}` });
|
||||
const total = Math.floor(count / 50);
|
||||
for (let i = 0; i <= total; i++) {
|
||||
const docs = await src.collection('userfileUsage')
|
||||
.find().skip(i * 50).limit(50)
|
||||
.toArray();
|
||||
for (const doc of docs) {
|
||||
if (doc.userfile_usage) {
|
||||
bulk.find({ _id: doc.uid }).updateOne({ $set: { usage: doc.userfile_usage } });
|
||||
}
|
||||
}
|
||||
await bulk.execute();
|
||||
}
|
||||
}
|
||||
|
||||
async function task(name: string, src: Db, report: Function) {
|
||||
const count = await cursor[name](src).count();
|
||||
await report({ progress: 1, message: `${name}: ${count}` });
|
||||
@@ -532,6 +551,7 @@ export async function run({
|
||||
await fixProblem(report);
|
||||
await discussionNode(src, report);
|
||||
await message(src, report);
|
||||
await userfileUsage(src, report);
|
||||
await removeInvalidPid(src, report);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
{ "path": "packages/geoip" },
|
||||
{ "path": "packages/login-with-github" },
|
||||
{ "path": "packages/login-with-google" },
|
||||
{ "path": "packages/login-with-osu" },
|
||||
{ "path": "packages/migrate-vijos" },
|
||||
{ "path": "tsconfig.build.json" },
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user