-
Notifications
You must be signed in to change notification settings - Fork 8
/
java.ts
38 lines (33 loc) · 928 Bytes
/
java.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { CodeOutput } from '..';
const url = 'https://api2.sololearn.com/v2/codeplayground/v2/compile';
export default async function (code: string, output: CodeOutput): Promise<void> {
const param = {
code,
language: 'java',
input: '',
codeId: null,
}
const res = await fetch(url, {
method: 'POST',
headers: {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json",
},
body: JSON.stringify(param),
mode: "cors",
})
const data: {
success: boolean,
errors: [],
data: {
sourceCode: string,
output: string,
language: string
}
} = await res.json();
if (data.errors && data.errors.length > 0) {
data.errors.forEach(e => output.error(e));
return
}
output.write(data.data.output);
}