mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
draft: hack?
This commit is contained in:
1 parent
cd3a426ef8
commit
8b956575ee
10 files changed
+213
-10
No files matched your search
@@ -2,6 +2,7 @@ import { ObjectID } from 'mongodb';
|
||||
import { PermissionError, RecordNotFoundError } from '../error';
|
||||
import { PERM, CONSTANT } from '../model/builtin';
|
||||
import * as problem from '../model/problem';
|
||||
import * as file from '../model/file';
|
||||
import * as record from '../model/record';
|
||||
import * as contest from '../model/contest';
|
||||
import * as user from '../model/user';
|
||||
@@ -11,6 +12,7 @@ import {
|
||||
Route, Handler, Connection, ConnectionHandler, Types, param,
|
||||
} from '../service/server';
|
||||
import { Rdoc } from '../interface';
|
||||
import { streamToBuffer } from '../utils';
|
||||
|
||||
const RecordHandler = contest.ContestHandlerMixin(Handler);
|
||||
|
||||
@@ -84,8 +86,51 @@ class RecordDetailHandler extends RecordHandler {
|
||||
pdoc,
|
||||
};
|
||||
}
|
||||
|
||||
@param('rid', Types.ObjectID)
|
||||
async postRejudge(domainId: string, rid: ObjectID) {
|
||||
this.checkPerm(PERM.PERM_REJUDGE);
|
||||
const rdoc = await record.get(domainId, rid);
|
||||
if (rdoc) {
|
||||
await record.reset(domainId, rid, true);
|
||||
await record.judge(domainId, rid);
|
||||
}
|
||||
this.back();
|
||||
}
|
||||
}
|
||||
|
||||
class RecordHackHandler extends Handler {
|
||||
@param('rid', Types.ObjectID)
|
||||
@param('ufid', Types.ObjectID)
|
||||
async get(domainId: string, rid: ObjectID, ufid?: ObjectID) {
|
||||
if (ufid) {
|
||||
const stream = await file.get(ufid);
|
||||
const buf = await streamToBuffer(stream);
|
||||
const input = buf.toString();
|
||||
await this.post(domainId, rid, input);
|
||||
} else this.response.template = 'record_hack.html';
|
||||
}
|
||||
|
||||
@param('rid', Types.ObjectID)
|
||||
@param('input', Types.String)
|
||||
async post(domainId: string, rid: ObjectID, input: string) {
|
||||
const rdoc = await record.get(domainId, rid);
|
||||
if (!rdoc) throw new RecordNotFoundError(domainId, rid);
|
||||
const newRid = await record.add(
|
||||
domainId, rdoc.pid, this.user._id,
|
||||
rdoc.lang, rdoc.code, true,
|
||||
{ hack: input },
|
||||
);
|
||||
bus.boardcast('record/change', rdoc);
|
||||
this.response.body = { rid: newRid };
|
||||
this.response.redirect = this.url('record_detail', { rid: newRid });
|
||||
// TODO handle hack(modify testdata, rejudge problem)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
class RecordRejudgeHandler extends Handler {
|
||||
@param('rid', Types.ObjectID)
|
||||
async post(domainId: string, rid: ObjectID) {
|
||||
@@ -183,6 +228,7 @@ class RecordDetailConnectionHandler extends contest.ContestHandlerMixin(Connecti
|
||||
export async function apply() {
|
||||
Route('record_main', '/record', RecordListHandler);
|
||||
Route('record_detail', '/record/:rid', RecordDetailHandler);
|
||||
Route('record_hack', '/record/:rid/hack', RecordHackHandler);
|
||||
Route('record_rejudge', '/record/:rid/rejudge', RecordRejudgeHandler);
|
||||
Connection('record_conn', '/record-conn', RecordMainConnectionHandler);
|
||||
Connection('record_detail_conn', '/record-detail-conn', RecordDetailConnectionHandler);
|
||||
|
||||
@@ -199,12 +199,18 @@ export interface TestCase {
|
||||
message: string,
|
||||
}
|
||||
|
||||
export interface HackConfig {
|
||||
hack: string,
|
||||
}
|
||||
|
||||
export interface PretestConfig {
|
||||
time?: string,
|
||||
memory?: string,
|
||||
input: string,
|
||||
}
|
||||
|
||||
export type RunConfig = HackConfig | PretestConfig;
|
||||
|
||||
export interface ContestInfo {
|
||||
type: 30 | 60,
|
||||
tid: ObjectID,
|
||||
@@ -229,7 +235,7 @@ export interface Rdoc {
|
||||
status: number,
|
||||
hidden: boolean,
|
||||
progress?: number,
|
||||
config?: PretestConfig,
|
||||
config?: RunConfig,
|
||||
contest?: ContestInfo,
|
||||
}
|
||||
|
||||
|
||||
@@ -550,6 +550,7 @@ export const STATUS = {
|
||||
STATUS_SYSTEM_ERROR: 8,
|
||||
STATUS_CANCELED: 9,
|
||||
STATUS_ETC: 10,
|
||||
STATUS_HACKED: 11,
|
||||
STATUS_JUDGING: 20,
|
||||
STATUS_COMPILING: 21,
|
||||
STATUS_FETCHED: 22,
|
||||
@@ -568,6 +569,7 @@ export const STATUS_TEXTS = {
|
||||
[STATUS.STATUS_SYSTEM_ERROR]: 'System Error',
|
||||
[STATUS.STATUS_CANCELED]: 'Cancelled',
|
||||
[STATUS.STATUS_ETC]: 'Unknown Error',
|
||||
[STATUS.STATUS_HACKED]: 'Hacked',
|
||||
[STATUS.STATUS_JUDGING]: 'Running',
|
||||
[STATUS.STATUS_COMPILING]: 'Compiling',
|
||||
[STATUS.STATUS_FETCHED]: 'Fetched',
|
||||
@@ -586,6 +588,7 @@ export const STATUS_CODES = {
|
||||
8: 'fail',
|
||||
9: 'ignored',
|
||||
10: 'fail',
|
||||
11: 'fail',
|
||||
20: 'progress',
|
||||
21: 'progress',
|
||||
22: 'progress',
|
||||
|
||||
@@ -6,7 +6,7 @@ import { STATUS } from './builtin';
|
||||
import * as task from './task';
|
||||
import * as problem from './problem';
|
||||
import {
|
||||
Rdoc, TestCase, PretestConfig, ContestInfo, ProblemConfig,
|
||||
Rdoc, TestCase, RunConfig, ContestInfo, ProblemConfig,
|
||||
} from '../interface';
|
||||
import * as db from '../service/db';
|
||||
|
||||
@@ -56,7 +56,7 @@ export async function get(domainId: string, _id: ObjectID): Promise<Rdoc | null>
|
||||
|
||||
export async function judge(domainId: string, rid: ObjectID) {
|
||||
const rdoc = await get(domainId, rid);
|
||||
let config: ProblemConfig = rdoc.config;
|
||||
let config: RunConfig | ProblemConfig = rdoc.config;
|
||||
if (!config) {
|
||||
const pdoc = await problem.get(domainId, rdoc.pid);
|
||||
config = pdoc?.config || {};
|
||||
@@ -73,7 +73,7 @@ export async function judge(domainId: string, rid: ObjectID) {
|
||||
|
||||
export async function add(
|
||||
domainId: string, pid: number, uid: number,
|
||||
lang: string, code: string, addTask: boolean, contestOrConfig?: ContestInfo | PretestConfig,
|
||||
lang: string, code: string, addTask: boolean, contestOrConfig?: ContestInfo | RunConfig,
|
||||
) {
|
||||
const data: Rdoc = {
|
||||
status: STATUS.STATUS_WAITING,
|
||||
@@ -98,7 +98,7 @@ export async function add(
|
||||
if ((contestOrConfig as ContestInfo).type) {
|
||||
data.contest = contestOrConfig as ContestInfo;
|
||||
} else {
|
||||
data.config = contestOrConfig as PretestConfig;
|
||||
data.config = contestOrConfig as RunConfig;
|
||||
}
|
||||
}
|
||||
const res = await coll.insertOne(data);
|
||||
|
||||
@@ -170,7 +170,8 @@ export function param(name: string, ...args: any): MethodDecorator {
|
||||
if (!target.__param[target.constructor.name][funcName]) {
|
||||
target.__param[target.constructor.name][funcName] = [{ name: 'domainId', type: 'string' }];
|
||||
const originalMethod = obj.value;
|
||||
obj.value = function validate(rawArgs: any) {
|
||||
obj.value = function validate(rawArgs: any, ...extra: any[]) {
|
||||
if (typeof rawArgs === 'string' || extra.length) return originalMethod.call(this, rawArgs, ...extra);
|
||||
const c = [];
|
||||
const arglist: ParamOption[] = this.__param[target.constructor.name][funcName];
|
||||
for (const item of arglist) {
|
||||
|
||||
Reference in new issue
Block a user