33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
from fastapi import APIRouter, UploadFile, File, HTTPException, Form
|
|
from app.services.cape import CapeService
|
|
from app.services.auth import AuthService
|
|
|
|
router = APIRouter(tags=["Capes"])
|
|
|
|
@router.post("/user/{username}/cape")
|
|
async def set_cape(
|
|
username: str,
|
|
cape_file: UploadFile = File(...),
|
|
accessToken: str = Form(...),
|
|
clientToken: str = Form(...)
|
|
):
|
|
# Validate the token
|
|
is_valid = await AuthService().validate(accessToken, clientToken)
|
|
if not is_valid:
|
|
raise HTTPException(status_code=401, detail="Invalid authentication tokens")
|
|
|
|
return await CapeService().set_cape(username, cape_file)
|
|
|
|
@router.delete("/user/{username}/cape")
|
|
async def remove_cape(
|
|
username: str,
|
|
accessToken: str,
|
|
clientToken: str
|
|
):
|
|
# Validate the token
|
|
is_valid = await AuthService().validate(accessToken, clientToken)
|
|
if not is_valid:
|
|
raise HTTPException(status_code=401, detail="Invalid authentication tokens")
|
|
|
|
return await CapeService().remove_cape(username)
|