core: use NumericArray to parse uids

This commit is contained in:
undefined committed 2021-04-06 19:46:08 +08:00
1 parent 38bee6415d
commit 4b48c0c164
3 files changed
+10 -2

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.21.13",
"version": "2.21.14",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+1 -1
View File
@@ -136,7 +136,7 @@ class DomainUserHandler extends ManageHandler {
this.back();
}
@param('uid', Types.Array)
@param('uid', Types.NumericArray)
@param('role', Types.String)
async postSetUsers(domainId: string, uid: number[], role: string) {
await domain.setUserRole(domainId, uid, role);
+8
View File
@@ -68,6 +68,7 @@ export interface Types {
Time: Type,
Range: (range: Array<string | number> | Dictionary<any>) => Type,
Array: Type,
NumericArray: Type,
Set: Type,
}
@@ -140,6 +141,13 @@ export const Types: Types = {
if (v instanceof Array) return v;
return v ? [v] : [];
}, null],
NumericArray: [(v) => {
if (v instanceof Array) return v.map(Number);
return v ? [Number(v)] : [];
}, (v) => {
if (v instanceof Array) return !v.map(Number).includes(NaN);
return !Number.isNaN(+v);
}],
Set: [(v) => {
if (v instanceof Array) return new Set(v);
return v ? new Set([v]) : new Set();