17 lines
572 B
Python
17 lines
572 B
Python
from pathlib import Path
|
|
|
|
from fastapi import APIRouter, HTTPException, Request, status
|
|
|
|
router = APIRouter()
|
|
COOKIES_PATH = Path("/app/cookies.txt")
|
|
|
|
|
|
@router.post("/cookies", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def uploadCookies(request: Request):
|
|
body = (await request.body()).decode("utf-8", errors="replace")
|
|
if not body.startswith("# Netscape"):
|
|
raise HTTPException(status.HTTP_400_BAD_REQUEST, "Kein Netscape-Cookie-File")
|
|
tmp = COOKIES_PATH.with_suffix(".tmp")
|
|
tmp.write_text(body, encoding="utf-8")
|
|
tmp.replace(COOKIES_PATH)
|