INNER CODE UNIT · Python
auth_error_response
NextWeb4/lan-file-transfer · lan_transfer/api.py:158
def auth_error_response(exc: AuthError) -> HTTPException:
if isinstance(exc, LockedOutError):
return HTTPException(
status_code=423,
detail={
"message": str(exc),
"locked_until": exc.locked_until,
},
)
if isinstance(exc, RoleRequiredError):
return HTTPException(status_code=403, detail=str(exc))
return HTTPException(status_code=400, detail=str(exc))
def content_disposition(filename: str) -> str:
fallback = "".join(char if 32 <= ord(char) < 127 and char not in '";/\\' else "_" for char in filename)
fallback = fallback or "download"
return f"attachment; filename=\"{fallback}\"; filename*=UTF-8''{quote(filename, safe='')}"