sessionservice
This commit is contained in:
parent
9e688b76b4
commit
a0faecd030
17
app/main.py
17
app/main.py
@ -32,12 +32,13 @@ async def login():
|
||||
return FileResponse(root / "login.html")
|
||||
|
||||
|
||||
base = "http://v6d3music/"
|
||||
ubot = "http://v6d3music/"
|
||||
ussv = "http://sessionservice/"
|
||||
|
||||
|
||||
@app.get("/authlink/")
|
||||
async def authlink():
|
||||
async with aiohttp.ClientSession() as s, s.get(f"{base}authlink/") as response:
|
||||
async with aiohttp.ClientSession() as s, s.get(f"{ussv}authlink/") as response:
|
||||
return PlainTextResponse(await response.text())
|
||||
|
||||
|
||||
@ -69,7 +70,7 @@ async def repeat(repeated: Callable[[], Coroutine[Any, Any, T]]) -> T:
|
||||
|
||||
|
||||
async def handle_auth(response: aiohttp.ClientResponse):
|
||||
if 300 <= response.status <= 399:
|
||||
if response.status == 200:
|
||||
return RedirectResponse("/")
|
||||
else:
|
||||
return Response(content=await response.read(), media_type=response.content_type, status_code=response.status)
|
||||
@ -80,8 +81,8 @@ async def auth(session: str | None = None, state: str | None = None, code: str |
|
||||
match session, state, code:
|
||||
case str() as session, str() as state, str() as code:
|
||||
params: dict[str, str] = {"session": session, "state": state, "code": code}
|
||||
return await repeat(lambda: url_get(f"{base}auth/", params, handle_auth))
|
||||
case None, None, None:
|
||||
return await repeat(lambda: url_get(f"{ussv}auth/", params, handle_auth))
|
||||
case None, str(), str():
|
||||
return FileResponse(root / "auth.html")
|
||||
case _:
|
||||
raise HTTPException(400)
|
||||
@ -93,12 +94,12 @@ async def handle_json(response: aiohttp.ClientResponse):
|
||||
|
||||
@app.get("/state/")
|
||||
async def state(session: str):
|
||||
return await repeat(lambda: url_get(f"{base}state/", {"session": session}, handle_json))
|
||||
return await repeat(lambda: url_get(f"{ussv}state/", {"session": session}, handle_json))
|
||||
|
||||
|
||||
@app.get("/status/")
|
||||
async def status(session: str):
|
||||
return await repeat(lambda: url_get(f"{base}status/", {"session": session}, handle_json))
|
||||
return await repeat(lambda: url_get(f"{ussv}status/", {"session": session}, handle_json))
|
||||
|
||||
|
||||
@app.get("/main.js")
|
||||
@ -123,4 +124,4 @@ async def operatorcss():
|
||||
|
||||
@app.post("/api/")
|
||||
async def api(json: dict, session: str):
|
||||
return await repeat(lambda: url_post(f"{base}api/", {"session": session}, json, handle_json))
|
||||
return await repeat(lambda: url_post(f"{ubot}api/", {"session": session}, json, handle_json))
|
||||
|
Loading…
Reference in New Issue
Block a user