mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-02-05 11:25:19 -05:00
Add @extend_schema decorators to moderation ViewSet actions
- Add drf_spectacular imports (extend_schema, OpenApiResponse, inline_serializer) - Annotate claim action with response schemas for 200/404/409/400 - Annotate unclaim action with response schemas for 200/403/400 - Annotate approve action with request=None and response schemas - Annotate reject action with reason request body schema - Annotate escalate action with reason request body schema - All actions tagged with 'Moderation' for API docs grouping
This commit is contained in:
@@ -55,3 +55,45 @@ def get_direct_upload_url(user_id=None):
|
||||
raise e
|
||||
|
||||
return result.get("result", {})
|
||||
|
||||
|
||||
def delete_cloudflare_image(image_id: str) -> bool:
|
||||
"""
|
||||
Delete an image from Cloudflare Images.
|
||||
|
||||
Used to cleanup orphaned images when submissions are rejected or deleted.
|
||||
|
||||
Args:
|
||||
image_id: The Cloudflare image ID to delete.
|
||||
|
||||
Returns:
|
||||
bool: True if deletion succeeded, False otherwise.
|
||||
"""
|
||||
account_id = getattr(settings, "CLOUDFLARE_IMAGES_ACCOUNT_ID", None)
|
||||
api_token = getattr(settings, "CLOUDFLARE_IMAGES_API_TOKEN", None)
|
||||
|
||||
if not account_id or not api_token:
|
||||
logger.error("Cloudflare settings missing, cannot delete image %s", image_id)
|
||||
return False
|
||||
|
||||
url = f"https://api.cloudflare.com/client/v4/accounts/{account_id}/images/v1/{image_id}"
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {api_token}",
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.delete(url, headers=headers)
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
|
||||
if result.get("success"):
|
||||
logger.info("Successfully deleted Cloudflare image: %s", image_id)
|
||||
return True
|
||||
else:
|
||||
error_msg = result.get("errors", [{"message": "Unknown error"}])[0].get("message")
|
||||
logger.warning("Failed to delete Cloudflare image %s: %s", image_id, error_msg)
|
||||
return False
|
||||
except requests.RequestException as e:
|
||||
capture_and_log(e, f"Delete Cloudflare image {image_id}", source="service")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user