Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a1e2aba
core: store problem content in seperate collection
undefined-moe Oct 28, 2024
508ec77
core: content manager
undefined-moe Nov 8, 2024
3cb1b81
core: fix problem_edit page pid check
undefined-moe Oct 28, 2024
c41f483
core: fix user import metadata
undefined-moe Oct 29, 2024
d33c186
vjudge: add Provider.noComment
undefined-moe Oct 31, 2024
f5af57f
core&judge: add isTrusted option
undefined-moe Nov 3, 2024
898cfa3
core: allow coping copied problems
undefined-moe Nov 4, 2024
4bf52b3
ui: buildContent: add new line between sections
undefined-moe Nov 4, 2024
7c98899
bump version
undefined-moe Nov 5, 2024
444adf8
fix
undefined-moe Nov 5, 2024
a887d24
bump version
undefined-moe Nov 5, 2024
a215e6f
framework: remove uicontext by default (#900) (#901)
undefined-moe Nov 7, 2024
173cca1
core: add task/daily/finish
undefined-moe Nov 7, 2024
5dce917
core: ProblemSubmit: add shouldReadFile check
undefined-moe Nov 7, 2024
2c139d8
core: fix limit.pretest
undefined-moe Nov 10, 2024
e1a9b14
core: ScoreboardView API
undefined-moe Nov 7, 2024
7f1a6a0
feat: add xcpcio
undefined-moe Nov 7, 2024
fbfe3e4
make ci happy
undefined-moe Nov 7, 2024
0a2786d
core: add lang to tsdoc.journal
undefined-moe Nov 10, 2024
5f60908
fix style
undefined-moe Nov 11, 2024
c90436f
core: fix icpc problem format import (#904)
pandadtdyy Nov 12, 2024
c7b67e3
onsite-toolkit: add resolver (#706)
undefined-moe Nov 13, 2024
90bdb48
keep things simple
undefined-moe Nov 13, 2024
265b60b
Merge branch 'master' into problem-content
undefined-moe Nov 13, 2024
5d667f4
Merge branch 'master' into problem-content
undefined-moe Jul 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/hydrooj/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ declare module './model/problem' {
docId: number;
pid: string;
title: string;
content: string;
content: ({ id: string, name: string, lang: string } | { from: string, name: string, lang: string })[];
nSubmit: number;
nAccept: number;
tag: string[];
Expand Down
41 changes: 26 additions & 15 deletions packages/hydrooj/src/model/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export class ProblemModel {
'reference', 'maintainer',
];

static collContent = db.collection('problem.content');

static default = {
_id: new ObjectId(),
domainId: 'system',
Expand All @@ -98,7 +100,7 @@ export class ProblemModel {
pid: '',
owner: 1,
title: '*',
content: '',
content: [],
html: false,
nSubmit: 0,
nAccept: 0,
Expand All @@ -119,7 +121,7 @@ export class ProblemModel {
pid: null,
owner: 1,
title: '*',
content: 'Deleted Problem',
content: [],
html: false,
nSubmit: 0,
nAccept: 0,
Expand All @@ -133,7 +135,7 @@ export class ProblemModel {
};

static async add(
domainId: string, pid: string = '', title: string, content: string, owner: number,
domainId: string, pid: string = '', title: string, content: ProblemDoc['content'], owner: number,
tag: string[] = [], meta: ProblemCreateOptions = {},
) {
const [doc] = await ProblemModel.getMulti(domainId, {})
Expand All @@ -148,7 +150,7 @@ export class ProblemModel {

static async addWithId(
domainId: string, docId: number, pid: string = '', title: string,
content: string, owner: number, tag: string[] = [],
content: ProblemDoc['content'], owner: number, tag: string[] = [],
meta: ProblemCreateOptions = {},
) {
const ddoc = await DomainModel.get(domainId);
Expand Down Expand Up @@ -188,6 +190,11 @@ export class ProblemModel {
return res;
}

static async getContent(contentIds: string[]) {
const content = await ProblemModel.collContent.find({ _id: { $in: contentIds } }).toArray();
return Object.fromEntries(content.map((i) => [i._id.toString(), i.content]));
}

static getMulti(domainId: string, query: Filter<ProblemDoc>, projection = ProblemModel.PROJECTION_LIST) {
return document.getMulti(domainId, document.TYPE_PROBLEM, query, projection).sort({ sort: 1 });
}
Expand Down Expand Up @@ -234,7 +241,7 @@ export class ProblemModel {
if (pid && (/^[0-9]+$/.test(pid) || await ProblemModel.get(target, pid))) pid = '';
if (!pid && original.pid && !await ProblemModel.get(target, original.pid)) pid = original.pid;
return await ProblemModel.add(
target, pid, original.title, original.content,
target, pid, original.title, original.content.map((i) => ({ name: i.name, lang: i.lang, from: 'id' in i ? i.id : i.from })),
original.owner, original.tag, { hidden: original.hidden, reference: { domainId, pid: _id } },
);
}
Expand Down Expand Up @@ -611,16 +618,20 @@ export class ProblemModel {
nAccept: pdoc.nAccept,
difficulty: pdoc.difficulty,
});
await fs.writeFile(problemYaml, problemYamlContent);
try {
const c = JSON.parse(pdoc.content);
for (const key of Object.keys(c)) {
const problemContent = path.join(problemPath, `problem_${key}.md`);
await fs.writeFile(problemContent, typeof c[key] === 'string' ? c[key] : JSON.stringify(c[key]));
}
} catch (e) {
const problemContent = path.join(problemPath, 'problem.md');
await fs.writeFile(problemContent, pdoc.content);
const [c] = await Promise.all([
ProblemModel.getContent(pdoc.content.map((i) => ('id' in i ? i.id : i.from))),
fs.writeFile(problemYaml, problemYamlContent),
]);
for (const i of pdoc.content) {
await fs.writeFile(path.join(problemPath, `problem_${'id' in i ? i.id : i.from}.md`), [
'---',
yaml.dump({
name: i.name,
lang: i.lang,
}),
'---',
c['id' in i ? i.id : i.from],
].join('\n'));
}
if ((pdoc.data || []).length) {
const testdataPath = path.join(problemPath, 'testdata');
Expand Down