diff --git a/api.py b/api.py new file mode 100644 index 0000000..d6a0c9f --- /dev/null +++ b/api.py @@ -0,0 +1,65 @@ +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware +from pydantic import BaseModel + +import uvicorn + +from time import time + +app = FastAPI() + +main_req = "/apipanda/v2/game/755/tele2-panda-kombat/config" + +@app.get(main_req) +async def root(): + return { + "canPlay": True, + "serverTime": int(time()), + "errorCode": 0, + "errorMessage": None, + "tryAvailable": 1, + "nextFreeTryAt": int(time()) + 86400 +} + +@app.options(main_req) +async def opt(): + return None + +@app.post("/apipanda/v2/game/755/tele2-panda-kombat/game/start") +async def start(): + return {"gameSessionId":"1234567890"} + +@app.options("/apipanda/v2/game/755/tele2-panda-kombat/game/start") +async def start_opt(): + return None + +class GameEnd(BaseModel): + gameSessionId: str + duration: int + score: int + +@app.post("/apipanda/v2/game/755/tele2-panda-kombat/game/end") +async def end(gameEnd: GameEnd): + return {"win": 1} ## 0 если вебал + +@app.options("/apipanda/v2/game/755/tele2-panda-kombat/game/end") +async def end_opt(): + return None + +origins = [ + "http://localhost:5500", + "http://localhost:8000", + "http://127.0.0.1:5500", + "http://127.0.0.1:8000" +] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +if __name__ == "__main__": + uvicorn.run(app, host="0.0.0.0", port=8000) \ No newline at end of file diff --git a/index.html b/index.html index 26fd10c..d632024 100644 --- a/index.html +++ b/index.html @@ -243,4 +243,4 @@ if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.errorHandler && messages.length) { window.webkit.messageHandlers.errorHandler.postMessage(messages[0]); } - };