mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +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)
|
||||
@post('files', Types.Array)
|
||||
@post('files', Types.ArrayOf(Types.Name))
|
||||
async postDeleteFiles(domainId: string, tid: ObjectID, files: string[]) {
|
||||
await Promise.all([
|
||||
storage.del(files.map((t) => `contest/${domainId}/${tid}/${t}`), this.user._id),
|
||||
|
||||
@@ -224,7 +224,7 @@ class DomainRoleHandler extends ManageHandler {
|
||||
}
|
||||
|
||||
@requireSudo
|
||||
@param('roles', Types.Array)
|
||||
@param('roles', Types.ArrayOf(Types.Name))
|
||||
async postDelete(domainId: string, roles: string[]) {
|
||||
if (Set.intersection(roles, ['root', 'default', 'guest']).size > 0) {
|
||||
throw new ValidationError('role', null, 'You cannot delete root, default or guest roles');
|
||||
|
||||
@@ -69,7 +69,7 @@ export class FilesHandler extends Handler {
|
||||
this.back();
|
||||
}
|
||||
|
||||
@post('files', Types.Array)
|
||||
@post('files', Types.ArrayOf(Types.Name))
|
||||
async postDeleteFiles(domainId: string, files: string[]) {
|
||||
await Promise.all([
|
||||
storage.del(files.map((t) => `user/${this.user._id}/${t}`), this.user._id),
|
||||
|
||||
@@ -784,7 +784,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
||||
this.back();
|
||||
}
|
||||
|
||||
@post('files', Types.Array)
|
||||
@post('files', Types.ArrayOf(Types.Name))
|
||||
@post('type', Types.Range(['testdata', 'additional_file']), true)
|
||||
async postDeleteFiles(domainId: string, files: string[], type = 'testdata') {
|
||||
if (this.pdoc.reference) throw new ProblemIsReferencedError('delete files');
|
||||
|
||||
@@ -279,7 +279,7 @@ export class TrainingFilesHandler extends Handler {
|
||||
}
|
||||
|
||||
@param('tid', Types.ObjectID)
|
||||
@post('files', Types.Array)
|
||||
@post('files', Types.ArrayOf(Types.Name))
|
||||
async postDeleteFiles(domainId: string, tid: ObjectID, files: string[]) {
|
||||
await Promise.all([
|
||||
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 InputType = string | number | Record<string, any> | any[];
|
||||
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> {
|
||||
name: string,
|
||||
source: 'all' | 'get' | 'post' | 'route',
|
||||
@@ -21,7 +21,7 @@ export interface ParamOption<T> {
|
||||
validate?: Validator,
|
||||
}
|
||||
|
||||
type Type<T> = [Converter<T>, Validator?, boolean?];
|
||||
type Type<T> = [Converter<T>, Validator<false>?, boolean?];
|
||||
|
||||
export interface Types {
|
||||
Content: Type<string>;
|
||||
@@ -117,6 +117,7 @@ export const Types: Types = {
|
||||
return false;
|
||||
},
|
||||
],
|
||||
/** @deprecated suggested to use Types.ArrayOf instead. */
|
||||
Array: [(v) => {
|
||||
if (v instanceof Array) return v;
|
||||
return v ? [v] : [];
|
||||
|
||||
@@ -167,7 +167,7 @@ export class HandlerCommon {
|
||||
export class Handler extends HandlerCommon {
|
||||
loginMethods: any;
|
||||
noCheckPermView = false;
|
||||
__param: Record<string, decorators.ParamOption[]>;
|
||||
__param: Record<string, decorators.ParamOption<any>[]>;
|
||||
|
||||
back(body?: any) {
|
||||
this.response.body = body || this.response.body || {};
|
||||
|
||||
Reference in new issue
Block a user