Add corrected image generation

这个提交包含在:
cryptocommuniums-afk
2026-02-01 13:38:57 +08:00
父节点 a0e9cf7e02
当前提交 103340ff9d
修改 6 个文件,包含 561 行新增85 行删除

查看文件

@@ -14,6 +14,8 @@ type AssignmentSummary = {
score: number;
imagePath?: string;
imagePaths?: string[];
correctedImagePath?: string;
correctedImagePaths?: string[];
createdAt: string;
};
@@ -23,6 +25,8 @@ type AssignmentDetail = AssignmentSummary & {
feedback: string;
imagePath?: string;
imagePaths?: string[];
correctedImagePath?: string;
correctedImagePaths?: string[];
};
type ImageItem = {
@@ -394,9 +398,15 @@ export default function HomePage() {
const imageUrlFor = (id: number, index = 0) =>
`${apiBase}/assignments/${id}/image?username=${encodeURIComponent(savedUser)}&index=${index}`;
const correctedImageUrlFor = (id: number, index = 0) =>
`${apiBase}/assignments/${id}/corrected?username=${encodeURIComponent(savedUser)}&index=${index}`;
const imageCountFor = (item: AssignmentSummary) =>
item.imagePaths?.length ?? (item.imagePath ? 1 : 0);
const correctedImageCountFor = (item: AssignmentSummary) =>
item.correctedImagePaths?.length ?? (item.correctedImagePath ? 1 : 0);
const selectedImagePaths =
selected?.imagePaths && selected.imagePaths.length > 0
? selected.imagePaths
@@ -404,6 +414,13 @@ export default function HomePage() {
? [selected.imagePath]
: [];
const selectedCorrectedPaths =
selected?.correctedImagePaths && selected.correctedImagePaths.length > 0
? selected.correctedImagePaths
: selected?.correctedImagePath
? [selected.correctedImagePath]
: [];
return (
<main>
<div className="page">
@@ -574,6 +591,19 @@ export default function HomePage() {
{imageCountFor(item) > 1 ? ` (${imageCountFor(item)}张)` : ""}
</a>
)}
{correctedImageCountFor(item) > 0 && (
<a
className="button secondary"
href={correctedImageUrlFor(item.id, 0)}
download={`assignment-${item.id}-corrected-1.jpg`}
onClick={(event) => event.stopPropagation()}
>
{correctedImageCountFor(item) > 1
? ` (${correctedImageCountFor(item)}张)`
: ""}
</a>
)}
<button
className="button secondary"
onClick={(event) => {
@@ -636,6 +666,31 @@ export default function HomePage() {
</div>
</div>
)}
{selectedCorrectedPaths.length > 0 && (
<div style={{ display: "grid", gap: 12 }}>
<div className="assignment-meta">
<span> {selectedCorrectedPaths.length} </span>
</div>
<div className="image-grid">
{selectedCorrectedPaths.map((_, index) => (
<div key={`${selected.id}-corrected-${index}`} className="image-card">
<img
className="preview"
src={correctedImageUrlFor(selected.id, index)}
alt={`订正图 ${index + 1}`}
/>
<a
className="button secondary"
href={correctedImageUrlFor(selected.id, index)}
download={`assignment-${selected.id}-corrected-${index + 1}.jpg`}
>
{index + 1}
</a>
</div>
))}
</div>
</div>
)}
<div className="markdown">
<ReactMarkdown>{selected.markdown}</ReactMarkdown>
</div>