From a7dc00361ce4290d880f446a2d5deadad4c56d94 Mon Sep 17 00:00:00 2001 From: undefined Date: Sun, 18 Apr 2021 20:32:48 +0800 Subject: [PATCH] core: fix config hande --- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/model/problem.ts | 11 +++++++++++ packages/ui-default/build/config/webpack.js | 2 +- packages/ui-default/package.json | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 7cfbca362..d662457d0 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.23.1", + "version": "2.23.2", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/model/problem.ts b/packages/hydrooj/src/model/problem.ts index 7c85fe45e..14c3e20a1 100644 --- a/packages/hydrooj/src/model/problem.ts +++ b/packages/hydrooj/src/model/problem.ts @@ -1,6 +1,7 @@ import type { Readable } from 'stream'; import { ObjectID, FilterQuery } from 'mongodb'; import { Dictionary, escapeRegExp, pick } from 'lodash'; +import { streamToBuffer } from '@hydrooj/utils/lib/utils'; import { STATUS } from './builtin'; import * as document from './document'; import { buildProjection } from '../utils'; @@ -248,6 +249,16 @@ export class ProblemModel { } } +bus.on('problem/addTestdata', async (domainId, docId, name) => { + if (!['config.yaml', 'config.yml', 'Config.yaml', 'Config.yml'].includes(name)) return; + const buf = await storage.get(`problem/${domainId}/${docId}/testdata/${name}`); + await ProblemModel.edit(domainId, docId, { config: (await streamToBuffer(buf)).toString() }); +}); +bus.on('problem/delTestdata', async (domainId, docId, names) => { + if (!names.includes('config.yaml')) return; + await ProblemModel.edit(domainId, docId, { config: '' }); +}); + ProblemModel.extend((docId, pid) => ({ _id: new ObjectID(), domainId: 'system', diff --git a/packages/ui-default/build/config/webpack.js b/packages/ui-default/build/config/webpack.js index 4fcf9ff34..b766a7246 100644 --- a/packages/ui-default/build/config/webpack.js +++ b/packages/ui-default/build/config/webpack.js @@ -46,7 +46,7 @@ export default function (env = {}) { function fileLoader() { return { loader: 'file-loader', - options: { name: '[path][name].[ext]?[sha1:hash:hex:10]' }, + options: { name: 'files/[name].[sha1:hash:hex:10].[ext]' }, }; } diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index b4fe95a5f..a27ffa0c0 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/ui-default", - "version": "4.6.2", + "version": "4.6.3", "author": "undefined ", "license": "AGPL-3.0", "main": "hydro.js",