diff --git a/packages/fps-importer/index.ts b/packages/fps-importer/index.ts index ec5f65732..4a2386600 100644 --- a/packages/fps-importer/index.ts +++ b/packages/fps-importer/index.ts @@ -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 = '';