mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: problem api
This commit is contained in:
1 parent
89d100c548
commit
79ec4d300c
5 files changed
+51
-6
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.33.5",
|
"version": "2.33.6",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { Handler, Route } from '../service/server';
|
|||||||
import * as bus from '../service/bus';
|
import * as bus from '../service/bus';
|
||||||
|
|
||||||
const types: Record<string, Record<string, string>> = {};
|
const types: Record<string, Record<string, string>> = {};
|
||||||
|
const unions: Record<string, string> = {};
|
||||||
const descriptions: Record<string, Record<string, string>> = {};
|
const descriptions: Record<string, Record<string, string>> = {};
|
||||||
const handlers: Record<string, Record<string, any>> = {};
|
const handlers: Record<string, Record<string, any>> = {};
|
||||||
let root: Record<string, any> = {};
|
let root: Record<string, any> = {};
|
||||||
@@ -30,18 +31,23 @@ export function registerResolver(typeName: string, key: string, value: string, f
|
|||||||
bus.emit('api/update');
|
bus.emit('api/update');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function registerUnion(typeName: string, ...unionTypes: string[]) {
|
||||||
|
unions[typeName] = unionTypes.join(' | ');
|
||||||
|
bus.emit('api/update');
|
||||||
|
}
|
||||||
|
|
||||||
function setDescription(desc: string) {
|
function setDescription(desc: string) {
|
||||||
if (desc.includes('\n')) return ['"""', desc, '"""'].join('\n');
|
if (desc.includes('\n')) return ['"""', desc, '"""'].join('\n');
|
||||||
return JSON.stringify(desc);
|
return JSON.stringify(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildSchemaStr() {
|
function buildSchemaStr() {
|
||||||
let res = `${typeDefs.join('\n')}\n`;
|
let res = `${Object.keys(unions).map((i) => `union ${i} = ${unions[i]}`)}\n${typeDefs.join('\n')}\n`;
|
||||||
for (const key in types) {
|
for (const key in types) {
|
||||||
if (descriptions[key]._description) res += `${setDescription(descriptions[key]._description)}\n`;
|
if (descriptions[key]?._description) res += `${setDescription(descriptions[key]._description)}\n`;
|
||||||
res += `type ${key}{\n`;
|
res += `type ${key}{\n`;
|
||||||
for (const k in types[key]) {
|
for (const k in types[key]) {
|
||||||
if (descriptions[key][k]) res += ` ${setDescription(descriptions[key][k])}\n`;
|
if (descriptions[key]?.[k]) res += ` ${setDescription(descriptions[key][k])}\n`;
|
||||||
res += ` ${k}: ${types[key][k]}\n`;
|
res += ` ${k}: ${types[key][k]}\n`;
|
||||||
}
|
}
|
||||||
res += '}\n';
|
res += '}\n';
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { FilterQuery, ObjectID } from 'mongodb';
|
|||||||
import AdmZip from 'adm-zip';
|
import AdmZip from 'adm-zip';
|
||||||
import { sortFiles } from '@hydrooj/utils/lib/utils';
|
import { sortFiles } from '@hydrooj/utils/lib/utils';
|
||||||
import { lookup } from 'mime-types';
|
import { lookup } from 'mime-types';
|
||||||
|
import { registerResolver, registerValue } from './api';
|
||||||
import {
|
import {
|
||||||
NoProblemError, PermissionError, ValidationError,
|
NoProblemError, PermissionError, ValidationError,
|
||||||
SolutionNotFoundError, ProblemNotFoundError, BadRequestError,
|
SolutionNotFoundError, ProblemNotFoundError, BadRequestError,
|
||||||
@@ -32,6 +33,36 @@ import {
|
|||||||
export const parseCategory = (value: string) => flatten(value.replace(/,/g, ',').split(',')).map((e) => e.trim());
|
export const parseCategory = (value: string) => flatten(value.replace(/,/g, ',').split(',')).map((e) => e.trim());
|
||||||
export const parsePid = (value: string) => (isSafeInteger(value) ? +value : value);
|
export const parsePid = (value: string) => (isSafeInteger(value) ? +value : value);
|
||||||
|
|
||||||
|
registerValue('FileInfo', [
|
||||||
|
['_id', 'String!'],
|
||||||
|
['name', 'String!'],
|
||||||
|
['size', 'Int'],
|
||||||
|
['lastModified', 'Date'],
|
||||||
|
]);
|
||||||
|
registerValue('Problem', [
|
||||||
|
['_id', 'ObjectID!'],
|
||||||
|
['owner', 'Int!'],
|
||||||
|
['domainId', 'String!'],
|
||||||
|
['docId', 'Int!'],
|
||||||
|
['docType', 'Int!'],
|
||||||
|
['title', 'String!'],
|
||||||
|
['content', 'String!'],
|
||||||
|
['config', 'String!'],
|
||||||
|
['data', '[FileInfo]'],
|
||||||
|
['additional_file', '[FileInfo]'],
|
||||||
|
['nSubmit', 'Int'],
|
||||||
|
['nAccept', 'Int'],
|
||||||
|
['difficulty', 'Int'],
|
||||||
|
['tag', '[String]'],
|
||||||
|
['hidden', 'Boolean'],
|
||||||
|
]);
|
||||||
|
registerResolver('Query', 'problem(id: Int, pid: String)', 'Problem', async (arg, ctx) => {
|
||||||
|
const pdoc = await problem.get(ctx.domainId, arg.pid || arg.id);
|
||||||
|
if (!pdoc) return null;
|
||||||
|
if (pdoc.hidden && !ctx.user.own(pdoc)) ctx.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||||
|
return pdoc;
|
||||||
|
});
|
||||||
|
|
||||||
export class ProblemHandler extends Handler {
|
export class ProblemHandler extends Handler {
|
||||||
async cleanup() {
|
async cleanup() {
|
||||||
if (this.response.template === 'problem_main.html' && this.request.json) {
|
if (this.response.template === 'problem_main.html' && this.request.json) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.18.1",
|
"version": "4.18.2",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
@@ -1,2 +1,10 @@
|
|||||||
.graphiql-container .doc-explorer-title, .graphiql-container .history-title
|
.graphiql-container .doc-explorer-title, .graphiql-container .history-title
|
||||||
padding: 2px !important
|
overflow: hidden;
|
||||||
|
padding: 5px 40px 0px 0px !important
|
||||||
|
|
||||||
|
.graphiql-container .docExplorerWrap
|
||||||
|
font-family: "Source Code Pro", "Consolas" !important
|
||||||
|
|
||||||
|
.graphiql-container .doc-explorer-back
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 8px 20px 0px 20px !important
|
||||||
Reference in new issue
Block a user