mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: support namespace for problem import
This commit is contained in:
1 file changed
+8
-2
@@ -13,7 +13,7 @@ import {
|
|||||||
extractZip, Logger, size, streamToBuffer,
|
extractZip, Logger, size, streamToBuffer,
|
||||||
} from '@hydrooj/utils/lib/utils';
|
} from '@hydrooj/utils/lib/utils';
|
||||||
import { Context } from '../context';
|
import { Context } from '../context';
|
||||||
import { FileUploadError, ProblemNotFoundError, ValidationError } from '../error';
|
import { FileUploadError, NotFoundError, ProblemNotFoundError, ValidationError } from '../error';
|
||||||
import type {
|
import type {
|
||||||
Document, ProblemDict, ProblemStatusDoc, User,
|
Document, ProblemDict, ProblemStatusDoc, User,
|
||||||
} from '../interface';
|
} from '../interface';
|
||||||
@@ -460,6 +460,8 @@ export class ProblemModel {
|
|||||||
} = options;
|
} = options;
|
||||||
let delSource = options.delSource;
|
let delSource = options.delSource;
|
||||||
let problems: string[];
|
let problems: string[];
|
||||||
|
const ddoc = await DomainModel.get(domainId);
|
||||||
|
if (!ddoc) throw new NotFoundError(domainId);
|
||||||
try {
|
try {
|
||||||
if (filepath.endsWith('.zip')) {
|
if (filepath.endsWith('.zip')) {
|
||||||
tmpdir = path.join(os.tmpdir(), 'hydro', `${Math.random()}.import`);
|
tmpdir = path.join(os.tmpdir(), 'hydro', `${Math.random()}.import`);
|
||||||
@@ -502,7 +504,11 @@ export class ProblemModel {
|
|||||||
let overridePid = null;
|
let overridePid = null;
|
||||||
|
|
||||||
const isValidPid = async (id: string) => {
|
const isValidPid = async (id: string) => {
|
||||||
if (!(/^[A-Za-z][0-9A-Za-z]*$/.test(id))) return false;
|
if (!(/^(?:[a-z0-9]{1,10}-)?[a-z][0-9a-z]*$/i.test(id))) return false;
|
||||||
|
if (id.includes('-')) {
|
||||||
|
const [prefix] = id.split('-');
|
||||||
|
if (!ddoc?.namespaces?.[prefix]) return false;
|
||||||
|
}
|
||||||
const doc = await ProblemModel.get(domainId, id);
|
const doc = await ProblemModel.get(domainId, id);
|
||||||
if (doc) {
|
if (doc) {
|
||||||
if (!override) return false;
|
if (!override) return false;
|
||||||
|
|||||||
Reference in new issue
Block a user