-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
101 lines (78 loc) · 2.91 KB
/
api.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import uuid
import fastapi
import uvicorn
from Entities import RunnerRequest, CompilerRequest
from cpp.cpp_compiler import CppCompiler
from cpp.cpp_runner import CppRunner
from jdk.GenericJavaRunner import GenericJavaRunner
from jdk.JDKCompiler import JDKCompiler
from lifecycle.CompileLifeCycle import CompileLifeCycle
from lifecycle.RunnerLifeCycle import RunnerLifeCycle
from lifecycle.plugins.AutomaticPathGenerator import AutomaticPathGenerator
from py3.GenericPythonRunner import GenericPython3Runner
from py3.python_compiler import PythonCompiler
app = fastapi.FastAPI()
@app.post("/api/cpp_compiler")
async def cpp_compiler(request: CompilerRequest):
return CompileLifeCycle(request, lambda: CppCompiler()) \
.addPlugin(AutomaticPathGenerator()).startLifeCycle()
@app.post("/api/cpp_runner/")
async def cpp_runner(request: RunnerRequest):
return RunnerLifeCycle(request, lambda: CppRunner()).startLifeCycle()
@app.post("/api/python3_compiler")
async def python3_compiler(request: CompilerRequest):
return CompileLifeCycle(request, lambda: PythonCompiler()) \
.addPlugin(AutomaticPathGenerator()).startLifeCycle()
@app.post("/api/python3_runner/{python_version}")
async def python3_runner(request: RunnerRequest, python_version: str):
return RunnerLifeCycle(request, lambda: GenericPython3Runner(python_version)).startLifeCycle()
@app.post("/api/jdk_compiler")
async def jdk_compiler(request: CompilerRequest):
return CompileLifeCycle(request, lambda: JDKCompiler()) \
.addPlugin(AutomaticPathGenerator()).startLifeCycle()
@app.post("/api/jdk_runner/{java_version}")
async def jdk_runner(request: RunnerRequest, java_version: int):
return RunnerLifeCycle(request, lambda: GenericJavaRunner(java_version)) \
.startLifeCycle()
name = uuid.uuid4()
@app.get("/api/metadata")
async def get_metadata():
return {
"serverName": name,
"networkMetadata": {
"apiRootUrl": "http://127.0.0.1:8080/api/",
},
"compilerMetadata": {
"supportCompilers": [
{
"name": "gcc-cpp",
"version": "17",
"url": "cpp_compiler"
},
{
"name": "java",
"version": "17",
"url": "jdk_compiler"
},
{
"name": "python",
"version": "3.10",
"url": "python3_compiler"
}
]
},
"runnerMetadata": {
"supportRunners": [
{
"name": "cpp-runner",
"version": "unknown",
"url": "cpp_runner"
}
]
}
}
@app.get("/")
async def root():
return "Welcome to Llonvne Judge Server!"
if __name__ == "__main__":
uvicorn.run(app, host='0.0.0.0', port=8000)