Update SlowAPI
This commit is contained in:
25
app.py
25
app.py
@@ -15,12 +15,11 @@ from typing import Any
|
||||
from libs.slow import (
|
||||
JSONAPI,
|
||||
App,
|
||||
HTTPResponse,
|
||||
JSONResponse,
|
||||
Request,
|
||||
redirect,
|
||||
render,
|
||||
)
|
||||
from libs.slow.responses import HTTPResponse, JSONResponse
|
||||
|
||||
|
||||
class Coord:
|
||||
@@ -231,7 +230,7 @@ def room_key():
|
||||
@app.POST("/create_room")
|
||||
async def new_room(request):
|
||||
if len(rooms) == len(letters) ** 4:
|
||||
return HTTPResponse(request, "Out of service", status=501)
|
||||
return HTTPResponse("Out of service", status=501)
|
||||
key = room_key()
|
||||
rooms[key] = Room()
|
||||
return JSONResponse(
|
||||
@@ -279,21 +278,19 @@ async def quick_match(request: Request):
|
||||
|
||||
qid = data["queue_id"]
|
||||
if qid in quick_map:
|
||||
return JSONResponse(request, {"room_id": quick_map[qid]})
|
||||
return JSONResponse({"room_id": quick_map[qid]})
|
||||
else:
|
||||
return JSONResponse(
|
||||
request, {}
|
||||
) # Client handles empty as continue to wait
|
||||
return JSONResponse({}) # Client handles empty as continue to wait
|
||||
|
||||
else:
|
||||
qid = str(uuid.uuid4())
|
||||
quick_queue.append(qid)
|
||||
return JSONResponse(request, {"queue_id": qid})
|
||||
return JSONResponse({"queue_id": qid})
|
||||
|
||||
|
||||
@app.GET("/")
|
||||
async def home(request):
|
||||
return render(request, "home.html")
|
||||
return render("home.html")
|
||||
|
||||
|
||||
@app.GET("/<id>")
|
||||
@@ -302,13 +299,13 @@ async def game(request, id):
|
||||
return redirect("/")
|
||||
if id not in rooms:
|
||||
return redirect("/")
|
||||
return render(request, "game.html")
|
||||
return render("game.html")
|
||||
|
||||
|
||||
@app.POST("/join/<room_id>")
|
||||
async def join(request, room_id):
|
||||
if room_id not in rooms:
|
||||
return JSONResponse(request, {"code": "NOGO", "error": "Room not found."}, 404)
|
||||
return JSONResponse({"code": "NOGO", "error": "Room not found."}, 404)
|
||||
room: Room = rooms[room_id]
|
||||
player = room.add_player()
|
||||
if player:
|
||||
@@ -664,11 +661,9 @@ async def static(request, fn):
|
||||
try:
|
||||
path = sanitize_filename(fn, Path("static/").resolve())
|
||||
|
||||
return HTTPResponse(
|
||||
request, path.read_bytes(), content_type="application/octet-stream"
|
||||
)
|
||||
return HTTPResponse(path.read_bytes(), content_type="application/octet-stream")
|
||||
except Exception:
|
||||
return HTTPResponse(request, "404 File Not Found", status=404)
|
||||
return HTTPResponse("404 File Not Found", status=404)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user