mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: small enhancements
This commit is contained in:
1 parent
50b838d21d
commit
d7908aaff6
5 files changed
+24
-8
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
import decodeHTML from 'decode-html';
|
import decodeHTML from 'decode-html';
|
||||||
import xml2js from 'xml2js';
|
import xml2js from 'xml2js';
|
||||||
import {
|
import {
|
||||||
_, AdmZip, buildContent, ContentNode, Context, FileTooLargeError, fs,
|
_, AdmZip, BadRequestError, buildContent, ContentNode, Context, FileTooLargeError, fs,
|
||||||
Handler, PERM, ProblemConfigFile, ProblemModel, SolutionModel, ValidationError,
|
Handler, PERM, ProblemConfigFile, ProblemModel, SolutionModel, ValidationError,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
|
|
||||||
@@ -12,6 +12,7 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(domainId: string, result: any) {
|
async run(domainId: string, result: any) {
|
||||||
|
if (!result?.fps) throw new BadRequestError('Selected file is not a valid FPS problemset.');
|
||||||
for (const p of result.fps.item) {
|
for (const p of result.fps.item) {
|
||||||
const content: ContentNode[] = [];
|
const content: ContentNode[] = [];
|
||||||
if (p.description?.[0]) {
|
if (p.description?.[0]) {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ langs:
|
|||||||
c:
|
c:
|
||||||
compile: /usr/bin/gcc -Wall --std=c99 -o foo foo.c -lm
|
compile: /usr/bin/gcc -Wall --std=c99 -o foo foo.c -lm
|
||||||
highlight: c
|
highlight: c
|
||||||
monaco: cpp
|
monaco: c
|
||||||
display: C
|
display: C
|
||||||
cc:
|
cc:
|
||||||
compile: /usr/bin/g++ -Wall -std=c++14 -o foo foo.cc -lm
|
compile: /usr/bin/g++ -Wall -std=c++14 -o foo foo.cc -lm
|
||||||
|
|||||||
@@ -648,10 +648,9 @@ export class ProblemEditHandler extends ProblemManageHandler {
|
|||||||
) {
|
) {
|
||||||
if (newPid !== this.pdoc.pid && await problem.get(domainId, newPid)) throw new BadRequestError('new pid exists');
|
if (newPid !== this.pdoc.pid && await problem.get(domainId, newPid)) throw new BadRequestError('new pid exists');
|
||||||
const $update: Partial<ProblemDoc> = {
|
const $update: Partial<ProblemDoc> = {
|
||||||
title, content, pid: newPid, hidden, assign, tag: tag ?? [], difficulty,
|
title, content, pid: newPid, hidden, assign, tag: tag ?? [], difficulty, html: false,
|
||||||
};
|
};
|
||||||
let pdoc = await problem.get(domainId, pid);
|
const pdoc = await problem.edit(domainId, this.pdoc.docId, $update);
|
||||||
pdoc = await problem.edit(domainId, pdoc.docId, $update);
|
|
||||||
this.response.redirect = this.url('problem_detail', { pid: newPid || pdoc.docId });
|
this.response.redirect = this.url('problem_detail', { pid: newPid || pdoc.docId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,15 +58,21 @@ function load(data: Record<string, Record<string, string>>) {
|
|||||||
|
|
||||||
export = load;
|
export = load;
|
||||||
|
|
||||||
|
function collect(lang: string) {
|
||||||
|
const s = translations[lang];
|
||||||
|
if (!(s instanceof Array)) return {};
|
||||||
|
const result = {};
|
||||||
|
for (let i = s.length - 1; i >= 0; i--) Object.assign(result, s[i]);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
global.Hydro.locales = new Proxy(translations, {
|
global.Hydro.locales = new Proxy(translations, {
|
||||||
get(self, lang: string) {
|
get(self, lang: string) {
|
||||||
if (!self[lang]) return {};
|
if (!self[lang]) return {};
|
||||||
return new Proxy(self[lang], {
|
return new Proxy(self[lang], {
|
||||||
get(s, key) {
|
get(s, key) {
|
||||||
if (typeof key === 'string') return app.i18n.get(key, lang);
|
if (typeof key === 'string') return app.i18n.get(key, lang);
|
||||||
const result = {};
|
return Object.assign(collect(lang.split('_')[0]), collect(lang));
|
||||||
for (let i = s.length - 1; i >= 0; i--) Object.assign(result, s[i]);
|
|
||||||
return result;
|
|
||||||
},
|
},
|
||||||
has(s, key: string) {
|
has(s, key: string) {
|
||||||
return !!s.find((i) => !!i[key]);
|
return !!s.find((i) => !!i[key]);
|
||||||
|
|||||||
@@ -3,6 +3,14 @@ import {
|
|||||||
} from 'prom-client';
|
} from 'prom-client';
|
||||||
import { Context, db } from 'hydrooj';
|
import { Context, db } from 'hydrooj';
|
||||||
|
|
||||||
|
declare module 'hydrooj' {
|
||||||
|
interface Context {
|
||||||
|
metrics: Registry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Context.service('metrics');
|
||||||
|
|
||||||
export function createRegistry(ctx: Context) {
|
export function createRegistry(ctx: Context) {
|
||||||
const registry = new Registry();
|
const registry = new Registry();
|
||||||
|
|
||||||
@@ -61,5 +69,7 @@ export function createRegistry(ctx: Context) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
collectDefaultMetrics({ register: registry });
|
collectDefaultMetrics({ register: registry });
|
||||||
|
|
||||||
|
ctx.metrics = registry;
|
||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user