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,12 +1,12 @@
|
|||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
import { decode, encode } from "./functions"
|
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 })
|
const http = axios.create({ baseURL: import.meta.env.PUBLIC_JUDGE0_URL })
|
||||||
|
|
||||||
export async function createTestSubmission(code: Code, input: string) {
|
// Judge0 的语言 id。Flowchart 和 SQL 不在其中 —— 前者根本不是可执行代码,
|
||||||
const encodedCode = encode(code.value)
|
// 后者由本站自己的 SQL 沙箱判,都走不到 Judge0。
|
||||||
const id = {
|
const JUDGE0_LANGUAGE_ID: Partial<Record<LANGUAGE, number>> = {
|
||||||
C: 50,
|
C: 50,
|
||||||
"C++": 54,
|
"C++": 54,
|
||||||
Java: 62,
|
Java: 62,
|
||||||
@@ -14,7 +14,14 @@ export async function createTestSubmission(code: Code, input: string) {
|
|||||||
JavaScript: 63,
|
JavaScript: 63,
|
||||||
Python2: 70,
|
Python2: 70,
|
||||||
Python3: 71,
|
Python3: 71,
|
||||||
}[code.language]
|
}
|
||||||
|
|
||||||
|
export async function createTestSubmission(code: Code, input: string) {
|
||||||
|
const encodedCode = encode(code.value)
|
||||||
|
const id = JUDGE0_LANGUAGE_ID[code.language]
|
||||||
|
if (id === undefined) {
|
||||||
|
return { status: null, output: `${code.language} 不支持在线试运行` }
|
||||||
|
}
|
||||||
let compilerOptions = ""
|
let compilerOptions = ""
|
||||||
if (id === 50) compilerOptions = "-lm" // 解决 GCC 的链接问题
|
if (id === 50) compilerOptions = "-lm" // 解决 GCC 的链接问题
|
||||||
const payload = {
|
const payload = {
|
||||||
|
|||||||
Reference in New Issue
Block a user