mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add file edit hook
This commit is contained in:
1 parent
32df811bfa
commit
76615e0f5d
4 files changed
+17
-5
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
preset: '@shelf/jest-mongodb',
|
preset: '@shelf/jest-mongodb',
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.ts?$': 'ts-jest'
|
'^.+\\.ts?$': 'ts-jest',
|
||||||
},
|
},
|
||||||
moduleFileExtensions: ['ts', 'js', 'json'],
|
moduleFileExtensions: ['ts', 'js', 'json'],
|
||||||
collectCoverage: true,
|
collectCoverage: true,
|
||||||
|
|||||||
@@ -95,7 +95,11 @@ export interface User extends Dictionary<any> {
|
|||||||
export type Udict = NumericDictionary<User>;
|
export type Udict = NumericDictionary<User>;
|
||||||
|
|
||||||
export interface FileInfo {
|
export interface FileInfo {
|
||||||
|
/** duplicate to filename */
|
||||||
|
_id: string,
|
||||||
|
/** filename */
|
||||||
name: string,
|
name: string,
|
||||||
|
/** file size (in bytes) */
|
||||||
size: number,
|
size: number,
|
||||||
etag: string,
|
etag: string,
|
||||||
lastModified: Date,
|
lastModified: Date,
|
||||||
@@ -139,6 +143,7 @@ export interface ProblemConfig {
|
|||||||
interactor?: string,
|
interactor?: string,
|
||||||
user_extra_files?: string[],
|
user_extra_files?: string[],
|
||||||
judge_extra_files?: string[],
|
judge_extra_files?: string[],
|
||||||
|
outputs?: [string, number][],
|
||||||
cases?: TestCaseConfig[],
|
cases?: TestCaseConfig[],
|
||||||
subtasks?: SubtaskConfig[],
|
subtasks?: SubtaskConfig[],
|
||||||
}
|
}
|
||||||
@@ -189,8 +194,8 @@ declare module './model/problem' {
|
|||||||
difficulty?: number,
|
difficulty?: number,
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
category?: string[],
|
category?: string[],
|
||||||
/** @deprecated */
|
|
||||||
config: any,
|
config: string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export type { Pdoc } from './model/problem';
|
export type { Pdoc } from './model/problem';
|
||||||
|
|||||||
@@ -142,12 +142,14 @@ export class ProblemModel {
|
|||||||
const payload = { name, ...pick(meta, ['size', 'lastModified', 'etag']) };
|
const payload = { name, ...pick(meta, ['size', 'lastModified', 'etag']) };
|
||||||
if (!fileinfo) await ProblemModel.push(domainId, pid, 'data', { _id: name, ...payload });
|
if (!fileinfo) await ProblemModel.push(domainId, pid, 'data', { _id: name, ...payload });
|
||||||
else await document.setSub(domainId, document.TYPE_PROBLEM, pid, 'data', name, payload);
|
else await document.setSub(domainId, document.TYPE_PROBLEM, pid, 'data', name, payload);
|
||||||
|
await bus.emit('problem/addTestdata', domainId, pid, name, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async delTestdata(domainId: string, pid: number, name: string | string[]) {
|
static async delTestdata(domainId: string, pid: number, name: string | string[]) {
|
||||||
const names = (name instanceof Array) ? name : [name];
|
const names = (name instanceof Array) ? name : [name];
|
||||||
await storage.del(names.map((t) => `problem/${domainId}/${pid}/testdata/${t}`));
|
await storage.del(names.map((t) => `problem/${domainId}/${pid}/testdata/${t}`));
|
||||||
await ProblemModel.pull(domainId, pid, 'data', names);
|
await ProblemModel.pull(domainId, pid, 'data', names);
|
||||||
|
await bus.emit('problem/delTestdata', domainId, pid, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async addAdditionalFile(domainId: string, pid: number, name: string, f: Readable | Buffer | string) {
|
static async addAdditionalFile(domainId: string, pid: number, name: string, f: Readable | Buffer | string) {
|
||||||
@@ -159,12 +161,14 @@ export class ProblemModel {
|
|||||||
const payload = { name, ...pick(meta, ['size', 'lastModified', 'etag']) };
|
const payload = { name, ...pick(meta, ['size', 'lastModified', 'etag']) };
|
||||||
if (!fileinfo) await ProblemModel.push(domainId, pid, 'additional_file', { _id: name, ...payload });
|
if (!fileinfo) await ProblemModel.push(domainId, pid, 'additional_file', { _id: name, ...payload });
|
||||||
else await document.setSub(domainId, document.TYPE_PROBLEM, pid, 'additional_file', name, payload);
|
else await document.setSub(domainId, document.TYPE_PROBLEM, pid, 'additional_file', name, payload);
|
||||||
|
await bus.emit('problem/addAdditionalFile', domainId, pid, name, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async delAdditionalFile(domainId: string, pid: number, name: string | string[]) {
|
static async delAdditionalFile(domainId: string, pid: number, name: string | string[]) {
|
||||||
const names = (name instanceof Array) ? name : [name];
|
const names = (name instanceof Array) ? name : [name];
|
||||||
await storage.del(names.map((t) => `problem/${domainId}/${pid}/additional_file/${t}`));
|
await storage.del(names.map((t) => `problem/${domainId}/${pid}/additional_file/${t}`));
|
||||||
await ProblemModel.pull(domainId, pid, 'additional_file', names);
|
await ProblemModel.pull(domainId, pid, 'additional_file', names);
|
||||||
|
await bus.emit('problem/delAdditionalFile', domainId, pid, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async random(domainId: string, query: FilterQuery<Pdoc>): Promise<string | null> {
|
static async random(domainId: string, query: FilterQuery<Pdoc>): Promise<string | null> {
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import { argv } from 'yargs';
|
|||||||
import type { Handler } from './server';
|
import type { Handler } from './server';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import type {
|
import type {
|
||||||
Mdoc, Pdoc, Rdoc, TrainingDoc, User,
|
Mdoc, Pdoc, Rdoc, TrainingDoc, User, Ddoc, DomainDoc, FileInfo,
|
||||||
} from '../interface';
|
} from '../interface';
|
||||||
import type { Ddoc, DomainDoc } from '../loader';
|
|
||||||
import type { DocType } from '../model/document';
|
import type { DocType } from '../model/document';
|
||||||
import type { ProblemSolutionHandler } from '../handler/problem';
|
import type { ProblemSolutionHandler } from '../handler/problem';
|
||||||
import type { UserRegisterHandler } from '../handler/user';
|
import type { UserRegisterHandler } from '../handler/user';
|
||||||
@@ -80,6 +79,10 @@ export interface EventMap extends Record<string, any> {
|
|||||||
'problem/list': (query: FilterQuery<Pdoc>, handler: any) => VoidReturn
|
'problem/list': (query: FilterQuery<Pdoc>, handler: any) => VoidReturn
|
||||||
'problem/get': (doc: Pdoc, handler: any) => VoidReturn
|
'problem/get': (doc: Pdoc, handler: any) => VoidReturn
|
||||||
'problem/delete': (domainId: string, docId: number) => VoidReturn
|
'problem/delete': (domainId: string, docId: number) => VoidReturn
|
||||||
|
'problem/addTestdata': (domainId: string, docId: number, name: string, payload: FileInfo) => VoidReturn
|
||||||
|
'problem/delTestdata': (domainId: string, docId: number, name: string) => VoidReturn
|
||||||
|
'problem/addAdditionalFile': (domainId: string, docId: number, name: string, payload: FileInfo) => VoidReturn
|
||||||
|
'problem/delAdditionalFile': (domainId: string, docId: number, name: string) => VoidReturn
|
||||||
|
|
||||||
'training/list': (query: FilterQuery<TrainingDoc>, handler: any) => VoidReturn
|
'training/list': (query: FilterQuery<TrainingDoc>, handler: any) => VoidReturn
|
||||||
'training/get': (tdoc: TrainingDoc, handler: any) => VoidReturn
|
'training/get': (tdoc: TrainingDoc, handler: any) => VoidReturn
|
||||||
|
|||||||
Reference in new issue
Block a user