Fuxi/supabase/functions/judge-challenges/runners/programming.ts

40 lines
974 B
TypeScript
Raw Normal View History

2023-12-13 15:56:01 +00:00
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
};
}