mirror of
https://github.com/cfngc4594/monaco-editor-lsp-next.git
synced 2025-07-04 01:10:53 +00:00
- 在编辑题目描述和解析面板中添加语言切换功能 - 实现获取题目支持的语言列表和对应语言的题目数据 - 增加添加新语言的功能(仅前端) -优化题目描述和解析的编辑、预览和对比功能 - 在预览中添加 Accordion 和 VideoEmbed 组件支持
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
// app/actions/get-problem-data.ts
|
|
'use server';
|
|
|
|
import prisma from '@/lib/prisma';
|
|
import { Locale } from '@/generated/client'; // ✅ 导入 enum Locale
|
|
import { serialize } from 'next-mdx-remote/serialize';
|
|
|
|
export async function getProblemData(problemId: string, locale: string) {
|
|
const selectedLocale = locale as Locale; // ✅ 强制转换 string 为 Prisma enum
|
|
|
|
const problem = await prisma.problem.findUnique({
|
|
where: { id: problemId },
|
|
include: {
|
|
templates: true,
|
|
testcases: {
|
|
include: { inputs: true }
|
|
},
|
|
localizations: {
|
|
where: {
|
|
locale: selectedLocale, // ✅ 这里使用枚举
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!problem) {
|
|
throw new Error('Problem not found');
|
|
}
|
|
|
|
const getContent = (type: string) =>
|
|
problem.localizations.find(loc => loc.type === type)?.content || '';
|
|
|
|
const rawDescription = getContent('DESCRIPTION');
|
|
|
|
const mdxDescription = await serialize(rawDescription, {
|
|
parseFrontmatter: false,
|
|
});
|
|
|
|
return {
|
|
id: problem.id,
|
|
displayId: problem.displayId,
|
|
difficulty: problem.difficulty,
|
|
isPublished: problem.isPublished,
|
|
timeLimit: problem.timeLimit,
|
|
memoryLimit: problem.memoryLimit,
|
|
title: getContent('TITLE'),
|
|
description: rawDescription,
|
|
mdxDescription,
|
|
solution: getContent('SOLUTION'),
|
|
templates: problem.templates.map(t => ({
|
|
language: t.language,
|
|
content: t.content,
|
|
})),
|
|
testcases: problem.testcases.map(tc => ({
|
|
id: tc.id,
|
|
expectedOutput: tc.expectedOutput,
|
|
inputs: tc.inputs.map(input => ({
|
|
name: input.name,
|
|
value: input.value,
|
|
})),
|
|
})),
|
|
};
|
|
}
|