40 lines
974 B
TypeScript
40 lines
974 B
TypeScript
export async function runProgramChallenge(challenge: any, problem: any, cases: any[]) {
|
|
const languages: { [id: string]: number } = {
|
|
"cpp": 54
|
|
};
|
|
|
|
const code = challenge.answers?.code;
|
|
const language = challenge.answers?.language;
|
|
if (!code || !language || !cases || Object.keys(languages).indexOf(language) < 0) {
|
|
return {
|
|
status: "skipped",
|
|
submissions: null
|
|
};
|
|
}
|
|
|
|
const idx = languages[language];
|
|
const submissions = cases.map((item: any) => {
|
|
return {
|
|
"language_id": idx,
|
|
"source_code": challenge.answers?.code,
|
|
"expected_output": item?.stdout,
|
|
"stdin": code
|
|
};
|
|
});
|
|
|
|
const resp = await fetch(
|
|
Deno.env.get("JUDGE0_ENDPOINT") + "/submissions/batch",
|
|
{
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ submissions })
|
|
}
|
|
);
|
|
|
|
const result = await resp.json();
|
|
|
|
return {
|
|
status: "judging",
|
|
submissions: result
|
|
};
|
|
} |