fps-import: handle images

This commit is contained in:
undefined committed 2024-10-15 11:59:06 +08:00
1 parent 8c501293b1
commit b777afc1cc
1 file changed
+9 -1
+9 -1
View File
@@ -19,7 +19,7 @@ class FpsProblemImportHandler extends Handler {
if (!result?.fps) throw new BadRequestError('Selected file is not a valid FPS problemset.');
for (const p of result.fps.item) {
const markdown = [p.description?.[0], p.input?.[0], p.output?.[0], p.hint?.[0]].some((i) => i?.includes('[md]'));
const content = buildContent({
let content = buildContent({
description: p.description?.[0],
input: p.input?.[0],
output: p.output?.[0],
@@ -62,6 +62,14 @@ class FpsProblemImportHandler extends Handler {
addTestdata(p.test_input[2 * i + 1], `${i + 1}`, 'out');
}
}
if (p.img?.length) {
for (const img of p.img) {
const filename = String.random(8) + img.src[0].split('/').pop().split('.').pop();
tasks.push(ProblemModel.addAdditionalFile(domainId, pid, filename, Buffer.from(img.base64[0], 'base64')));
content = content.replace(img.src[0], `file://${filename}`);
}
await ProblemModel.edit(domainId, pid, { content });
}
await Promise.all(tasks);
if (p.solution) {
let s = '';