mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: use Types.ArrayOf to replace Types.Array
This commit is contained in:
1 parent
760c585ac5
commit
37af6fd5a6
7 files changed
+9
-8
No files matched your search
@@ -557,7 +557,7 @@ export class ContestManagementHandler extends ContestManagementBaseHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@param('tid', Types.ObjectID)
|
@param('tid', Types.ObjectID)
|
||||||
@post('files', Types.Array)
|
@post('files', Types.ArrayOf(Types.Name))
|
||||||
async postDeleteFiles(domainId: string, tid: ObjectID, files: string[]) {
|
async postDeleteFiles(domainId: string, tid: ObjectID, files: string[]) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
storage.del(files.map((t) => `contest/${domainId}/${tid}/${t}`), this.user._id),
|
storage.del(files.map((t) => `contest/${domainId}/${tid}/${t}`), this.user._id),
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ class DomainRoleHandler extends ManageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@requireSudo
|
@requireSudo
|
||||||
@param('roles', Types.Array)
|
@param('roles', Types.ArrayOf(Types.Name))
|
||||||
async postDelete(domainId: string, roles: string[]) {
|
async postDelete(domainId: string, roles: string[]) {
|
||||||
if (Set.intersection(roles, ['root', 'default', 'guest']).size > 0) {
|
if (Set.intersection(roles, ['root', 'default', 'guest']).size > 0) {
|
||||||
throw new ValidationError('role', null, 'You cannot delete root, default or guest roles');
|
throw new ValidationError('role', null, 'You cannot delete root, default or guest roles');
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export class FilesHandler extends Handler {
|
|||||||
this.back();
|
this.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@post('files', Types.Array)
|
@post('files', Types.ArrayOf(Types.Name))
|
||||||
async postDeleteFiles(domainId: string, files: string[]) {
|
async postDeleteFiles(domainId: string, files: string[]) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
storage.del(files.map((t) => `user/${this.user._id}/${t}`), this.user._id),
|
storage.del(files.map((t) => `user/${this.user._id}/${t}`), this.user._id),
|
||||||
|
|||||||
@@ -784,7 +784,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
|||||||
this.back();
|
this.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@post('files', Types.Array)
|
@post('files', Types.ArrayOf(Types.Name))
|
||||||
@post('type', Types.Range(['testdata', 'additional_file']), true)
|
@post('type', Types.Range(['testdata', 'additional_file']), true)
|
||||||
async postDeleteFiles(domainId: string, files: string[], type = 'testdata') {
|
async postDeleteFiles(domainId: string, files: string[], type = 'testdata') {
|
||||||
if (this.pdoc.reference) throw new ProblemIsReferencedError('delete files');
|
if (this.pdoc.reference) throw new ProblemIsReferencedError('delete files');
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ export class TrainingFilesHandler extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@param('tid', Types.ObjectID)
|
@param('tid', Types.ObjectID)
|
||||||
@post('files', Types.Array)
|
@post('files', Types.ArrayOf(Types.Name))
|
||||||
async postDeleteFiles(domainId: string, tid: ObjectID, files: string[]) {
|
async postDeleteFiles(domainId: string, tid: ObjectID, files: string[]) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
storage.del(files.map((t) => `contest/${domainId}/${tid}/${t}`), this.user._id),
|
storage.del(files.map((t) => `contest/${domainId}/${tid}/${t}`), this.user._id),
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import type { Handler } from './server';
|
|||||||
type MethodDecorator = (target: any, name: string, obj: any) => any;
|
type MethodDecorator = (target: any, name: string, obj: any) => any;
|
||||||
type InputType = string | number | Record<string, any> | any[];
|
type InputType = string | number | Record<string, any> | any[];
|
||||||
type Converter<T> = (value: any) => T;
|
type Converter<T> = (value: any) => T;
|
||||||
type Validator = (value: InputType) => boolean;
|
type Validator<Loose extends boolean = true> = (value: Loose extends true ? any : InputType) => boolean;
|
||||||
export interface ParamOption<T> {
|
export interface ParamOption<T> {
|
||||||
name: string,
|
name: string,
|
||||||
source: 'all' | 'get' | 'post' | 'route',
|
source: 'all' | 'get' | 'post' | 'route',
|
||||||
@@ -21,7 +21,7 @@ export interface ParamOption<T> {
|
|||||||
validate?: Validator,
|
validate?: Validator,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Type<T> = [Converter<T>, Validator?, boolean?];
|
type Type<T> = [Converter<T>, Validator<false>?, boolean?];
|
||||||
|
|
||||||
export interface Types {
|
export interface Types {
|
||||||
Content: Type<string>;
|
Content: Type<string>;
|
||||||
@@ -117,6 +117,7 @@ export const Types: Types = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
/** @deprecated suggested to use Types.ArrayOf instead. */
|
||||||
Array: [(v) => {
|
Array: [(v) => {
|
||||||
if (v instanceof Array) return v;
|
if (v instanceof Array) return v;
|
||||||
return v ? [v] : [];
|
return v ? [v] : [];
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ export class HandlerCommon {
|
|||||||
export class Handler extends HandlerCommon {
|
export class Handler extends HandlerCommon {
|
||||||
loginMethods: any;
|
loginMethods: any;
|
||||||
noCheckPermView = false;
|
noCheckPermView = false;
|
||||||
__param: Record<string, decorators.ParamOption[]>;
|
__param: Record<string, decorators.ParamOption<any>[]>;
|
||||||
|
|
||||||
back(body?: any) {
|
back(body?: any) {
|
||||||
this.response.body = body || this.response.body || {};
|
this.response.body = body || this.response.body || {};
|
||||||
|
|||||||
Reference in new issue
Block a user