diff --git a/src/actions/judge.ts b/src/actions/judge.ts index 0960a92..2ccf98f 100644 --- a/src/actions/judge.ts +++ b/src/actions/judge.ts @@ -65,6 +65,7 @@ function createTarStream(file: string, value: string) { export async function judge( language: EditorLanguage, value: string, + problemId: string, ): Promise { const session = await auth(); if (!session) redirect("/sign-in"); @@ -89,12 +90,28 @@ export async function judge( }; } + const problem = await prisma.problem.findUnique({ + where: { id: problemId }, + select: { + timeLimit: true, + memoryLimit: true, + }, + }); + + if (!problem) { + return { + id: uuid(), + output: "Problem not found.", + exitCode: ExitCode.SE, + executionTime: null, + memoryUsage: null, + }; + } + const { image, tag, workingDir, - memoryLimit, - timeLimit, compileOutputLimit, runOutputLimit, } = config.dockerConfig; @@ -103,7 +120,7 @@ export async function judge( // Prepare the environment and create a container await prepareEnvironment(image, tag); - container = await createContainer(image, tag, workingDir, memoryLimit); + container = await createContainer(image, tag, workingDir, problem.memoryLimit); // Upload code to the container const tarStream = createTarStream(file, value); @@ -116,7 +133,7 @@ export async function judge( } // Run the code - const runResult = await run(container, fileName, timeLimit, runOutputLimit); + const runResult = await run(container, fileName, problem.timeLimit, runOutputLimit); return runResult; } catch (error) { console.error(error); diff --git a/src/components/run-code.tsx b/src/components/run-code.tsx index 9b4eaa1..b22821e 100644 --- a/src/components/run-code.tsx +++ b/src/components/run-code.tsx @@ -22,7 +22,7 @@ export function RunCode({ className, ...props }: RunCodeProps) { - const { currentLang, editor } = useProblem(); + const { currentLang, editor, problemId } = useProblem(); const [isLoading, setIsLoading] = useState(false); const handleJudge = async () => { @@ -32,7 +32,7 @@ export function RunCode({ setIsLoading(true); try { - const result = await judge(currentLang, code); + const result = await judge(currentLang, code, problemId); showExitCodeToast({ exitCode: result.exitCode }); } catch (error) { console.error("Error occurred while judging the code:");