删掉模板代码
This commit is contained in:
45
src/api.ts
45
src/api.ts
@@ -1,5 +1,5 @@
|
||||
import axios from "axios"
|
||||
import { deadResults, languageToId } from "./templates"
|
||||
import { languageToId } from "./templates"
|
||||
import { Code, Submission } from "./types"
|
||||
|
||||
function getChromeVersion() {
|
||||
@@ -26,34 +26,29 @@ function decode(bytes?: string) {
|
||||
|
||||
const judge = axios.create({ baseURL: `${protocol}://judge0api.xuyue.cc` })
|
||||
const api = axios.create({ baseURL: `${protocol}://codeapi.xuyue.cc` })
|
||||
// const api = axios.create({ baseURL: `http://localhost:8080` })
|
||||
|
||||
export async function submit(code: Code, input: string) {
|
||||
const encodedCode = encode(code.value)
|
||||
|
||||
if (encodedCode === deadResults[code.language].encoded) {
|
||||
return deadResults[code.language].result
|
||||
} else {
|
||||
const id = languageToId[code.language]
|
||||
let compilerOptions = ""
|
||||
if (id === 50) compilerOptions = "-lm" // 解决 GCC 的链接问题
|
||||
const payload = {
|
||||
source_code: encodedCode,
|
||||
language_id: id,
|
||||
stdin: encode(input),
|
||||
redirect_stderr_to_stdout: true,
|
||||
compiler_options: compilerOptions,
|
||||
}
|
||||
const response = await judge.post<Submission>("/submissions", payload, {
|
||||
params: { base64_encoded: true, wait: true },
|
||||
})
|
||||
const data = response.data
|
||||
return {
|
||||
status: data.status && data.status.id,
|
||||
output: [decode(data.compile_output), decode(data.stdout)]
|
||||
.join("\n")
|
||||
.trim(),
|
||||
}
|
||||
const id = languageToId[code.language]
|
||||
let compilerOptions = ""
|
||||
if (id === 50) compilerOptions = "-lm" // 解决 GCC 的链接问题
|
||||
const payload = {
|
||||
source_code: encodedCode,
|
||||
language_id: id,
|
||||
stdin: encode(input),
|
||||
redirect_stderr_to_stdout: true,
|
||||
compiler_options: compilerOptions,
|
||||
}
|
||||
const response = await judge.post<Submission>("/submissions", payload, {
|
||||
params: { base64_encoded: true, wait: true },
|
||||
})
|
||||
const data = response.data
|
||||
return {
|
||||
status: data.status && data.status.id,
|
||||
output: [decode(data.compile_output), decode(data.stdout)]
|
||||
.join("\n")
|
||||
.trim(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const cSource =
|
||||
'#include<stdio.h>\r\n\r\nint main()\r\n{\r\n printf("黄岩一职");\r\n return 0;\r\n}'
|
||||
"#include<stdio.h>\r\n\r\nint main()\r\n{\r\n \r\n return 0;\r\n}"
|
||||
const cppSource =
|
||||
'#include<iostream>\r\n\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n cout<<"黄岩一职"<<endl;\r\n return 0;\r\n}'
|
||||
const pythonSource = 'print("黄岩一职")'
|
||||
"#include<iostream>\r\n\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n \r\n return 0;\r\n}"
|
||||
const pythonSource = ""
|
||||
const javaSource =
|
||||
'public class Main {\r\n public static void main(String[] args) {\r\n System.out.println("黄岩一职");\r\n }\r\n}'
|
||||
"public class Main {\r\n public static void main(String[] args) {\r\n \r\n }\r\n}"
|
||||
|
||||
export const languageToId = {
|
||||
c: 50,
|
||||
@@ -19,37 +19,3 @@ export const sources = {
|
||||
java: javaSource,
|
||||
python: pythonSource,
|
||||
}
|
||||
|
||||
export const deadResults = {
|
||||
c: {
|
||||
encoded:
|
||||
"I2luY2x1ZGU8c3RkaW8uaD4NCg0KaW50IG1haW4oKQ0Kew0KICAgIHByaW50Zigi6buE5bKp5LiA6IGMIik7DQogICAgcmV0dXJuIDA7DQp9",
|
||||
result: {
|
||||
status: 3,
|
||||
output: "黄岩一职",
|
||||
},
|
||||
},
|
||||
cpp: {
|
||||
encoded:
|
||||
"I2luY2x1ZGU8aW9zdHJlYW0+DQoNCnVzaW5nIG5hbWVzcGFjZSBzdGQ7DQoNCmludCBtYWluKCkNCnsNCiAgICBjb3V0PDwi6buE5bKp5LiA6IGMIjw8ZW5kbDsNCiAgICByZXR1cm4gMDsNCn0=",
|
||||
result: {
|
||||
status: 3,
|
||||
output: "黄岩一职",
|
||||
},
|
||||
},
|
||||
java: {
|
||||
encoded:
|
||||
"cHVibGljIGNsYXNzIE1haW4gew0KICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsNCiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCLpu4TlsqnkuIDogYwiKTsNCiAgICB9DQp9",
|
||||
result: {
|
||||
status: 3,
|
||||
output: "黄岩一职",
|
||||
},
|
||||
},
|
||||
python: {
|
||||
encoded: "cHJpbnQoIum7hOWyqeS4gOiBjCIp",
|
||||
result: {
|
||||
status: 3,
|
||||
output: "黄岩一职",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user