fix(试运行): 流程图/SQL 会往 Judge0 发出 language_id: undefined
Judge0 的语言 id 表里只有 C/C++/Java/Golang/JavaScript/Python2/Python3, 而 code.language 的类型包含 Flowchart 和 SQL —— 前者不是可执行代码, 后者由本站自己的 SQL 沙箱判,都走不到 Judge0。之前直接索引拿到 undefined 就发出去了。 改成 Partial<Record<LANGUAGE, number>>,取不到就提前返回提示。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,20 +1,27 @@
|
||||
import axios from "axios"
|
||||
import { decode, encode } from "./functions"
|
||||
import { Code } from "./types"
|
||||
import type { Code, LANGUAGE } from "./types"
|
||||
|
||||
const http = axios.create({ baseURL: import.meta.env.PUBLIC_JUDGE0_URL })
|
||||
|
||||
// Judge0 的语言 id。Flowchart 和 SQL 不在其中 —— 前者根本不是可执行代码,
|
||||
// 后者由本站自己的 SQL 沙箱判,都走不到 Judge0。
|
||||
const JUDGE0_LANGUAGE_ID: Partial<Record<LANGUAGE, number>> = {
|
||||
C: 50,
|
||||
"C++": 54,
|
||||
Java: 62,
|
||||
Golang: 60,
|
||||
JavaScript: 63,
|
||||
Python2: 70,
|
||||
Python3: 71,
|
||||
}
|
||||
|
||||
export async function createTestSubmission(code: Code, input: string) {
|
||||
const encodedCode = encode(code.value)
|
||||
const id = {
|
||||
C: 50,
|
||||
"C++": 54,
|
||||
Java: 62,
|
||||
Golang: 60,
|
||||
JavaScript: 63,
|
||||
Python2: 70,
|
||||
Python3: 71,
|
||||
}[code.language]
|
||||
const id = JUDGE0_LANGUAGE_ID[code.language]
|
||||
if (id === undefined) {
|
||||
return { status: null, output: `${code.language} 不支持在线试运行` }
|
||||
}
|
||||
let compilerOptions = ""
|
||||
if (id === 50) compilerOptions = "-lm" // 解决 GCC 的链接问题
|
||||
const payload = {
|
||||
|
||||
Reference in New Issue
Block a user