mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
fps-importer: allow setting
This commit is contained in:
3 files changed
+25
-5
No files matched your search
@@ -2,8 +2,8 @@
|
|||||||
import decodeHTML from 'decode-html';
|
import decodeHTML from 'decode-html';
|
||||||
import xml2js from 'xml2js';
|
import xml2js from 'xml2js';
|
||||||
import {
|
import {
|
||||||
_, AdmZip, BadRequestError, buildContent, ContentNode, Context, FileTooLargeError, fs,
|
_, AdmZip, BadRequestError, buildContent, ContentNode, Context, FileTooLargeError, fs, Handler,
|
||||||
Handler, PERM, ProblemConfigFile, ProblemModel, ProblemType, SolutionModel, ValidationError, yaml,
|
PERM, ProblemConfigFile, ProblemModel, ProblemType, SettingModel, SolutionModel, SystemModel, ValidationError, yaml,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
|
|
||||||
const knownRemoteMapping = {
|
const knownRemoteMapping = {
|
||||||
@@ -111,7 +111,7 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
const tasks = [];
|
const tasks = [];
|
||||||
try {
|
try {
|
||||||
const file = await fs.stat(this.request.files.file.filepath);
|
const file = await fs.stat(this.request.files.file.filepath);
|
||||||
if (file.size > 64 * 1024 * 1024) throw new FileTooLargeError('64m');
|
if (file.size > SystemModel.get('import-fps.limit')) throw new FileTooLargeError();
|
||||||
const content = fs.readFileSync(this.request.files.file.filepath, 'utf-8');
|
const content = fs.readFileSync(this.request.files.file.filepath, 'utf-8');
|
||||||
const result = await xml2js.parseStringPromise(content);
|
const result = await xml2js.parseStringPromise(content);
|
||||||
tasks.push(result);
|
tasks.push(result);
|
||||||
@@ -127,7 +127,7 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
for (const entry of zip.getEntries()) {
|
for (const entry of zip.getEntries()) {
|
||||||
try {
|
try {
|
||||||
const buf = entry.getData();
|
const buf = entry.getData();
|
||||||
if (buf.byteLength > 64 * 1024 * 1024) throw new FileTooLargeError('64m');
|
if (buf.byteLength > SystemModel.get('import-fps.limit')) throw new FileTooLargeError();
|
||||||
const content = buf.toString();
|
const content = buf.toString();
|
||||||
const result = await xml2js.parseStringPromise(content);
|
const result = await xml2js.parseStringPromise(content);
|
||||||
tasks.push(result);
|
tasks.push(result);
|
||||||
@@ -145,5 +145,22 @@ export async function apply(ctx: Context) {
|
|||||||
ctx.injectUI('ProblemAdd', 'problem_import_fps', { icon: 'copy', text: 'From FPS File' });
|
ctx.injectUI('ProblemAdd', 'problem_import_fps', { icon: 'copy', text: 'From FPS File' });
|
||||||
ctx.i18n.load('zh', {
|
ctx.i18n.load('zh', {
|
||||||
'From FPS File': '从 FPS 文件导入',
|
'From FPS File': '从 FPS 文件导入',
|
||||||
|
'problem.import.fps.hint1': '我们推荐的最大导入大小为 64MiB,若文件超出此大小,强烈建议您在本机使用 EasyFPSViewer 等工具将其拆分或是移除测试数据后单独上传。',
|
||||||
|
'problem.import.fps.hint2': '由于 xml 格式无法随机读写,解析需要消耗大量内存,在内存过小的机器上导入大型题目包很可能导致崩溃或死机。',
|
||||||
|
'problem.import.fps.hint3': '若您确有需要,此限制可在系统设置中更改。我们建议您使用 Hydro 自带的 zip 格式存储或是交换题目。',
|
||||||
|
});
|
||||||
|
ctx.i18n.load('en', {
|
||||||
|
'From FPS File': 'Import from FPS File',
|
||||||
|
'problem.import.fps.hint1': 'We recommend that the maximum import size is 64MiB. If the file exceeds this size, \
|
||||||
|
we strongly recommend that you use tools such as EasyFPSViewer to split it or remove the testdata and upload it separately on your local machine.',
|
||||||
|
'problem.import.fps.hint2': 'Since the xml format cannot be read randomly, parsing requires a large amount of memory. \
|
||||||
|
Importing a large problem set on a machine with insufficient memory may cause a crash or freeze.',
|
||||||
|
'problem.import.fps.hint3': 'If you really need it, this limit can be changed in the system settings. \
|
||||||
|
We strongly recommend that you use the zip format to store or exchange problemsets.',
|
||||||
|
});
|
||||||
|
ctx.inject(['setting'], (c) => {
|
||||||
|
c.setting.SystemSetting(
|
||||||
|
SettingModel.Setting('setting_limits', 'import-fps.limit', 64 * 1024 * 1024, 'text', 'Maximum file size for FPS problemset import'),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/fps-importer",
|
"name": "@hydrooj/fps-importer",
|
||||||
"version": "1.5.10",
|
"version": "1.5.11",
|
||||||
"description": "Import FPS problems",
|
"description": "Import FPS problems",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
<input type="file" name="file">
|
<input type="file" name="file">
|
||||||
<input type="submit" value="{{ _('Upload') }}" class="rounded primary button">
|
<input type="submit" value="{{ _('Upload') }}" class="rounded primary button">
|
||||||
</p>
|
</p>
|
||||||
|
<p>{{ _('problem.import.fps.hint1') }}</p>
|
||||||
|
<p>{{ _('problem.import.fps.hint2') }}</p>
|
||||||
|
<p>{{ _('problem.import.fps.hint3') }}</p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user