forked from mtusi2026/mtusi2026lab5
feat: add crop and optimized variants, implement idempotent worker
This commit is contained in:
+9
-1
@@ -287,12 +287,20 @@ async def download_attachment(attachment_id: UUID, variant: str = Query("origina
|
||||
raise HTTPException(409, "Attachment not ready")
|
||||
|
||||
key = att.s3_key
|
||||
mime = att.content_type
|
||||
|
||||
if variant == "thumbnail":
|
||||
key = f"{att.s3_key}_thumb.jpg"
|
||||
mime = "image/jpeg"
|
||||
elif variant == "crop":
|
||||
key = f"{att.s3_key}_crop.jpg"
|
||||
mime = "image/jpeg"
|
||||
elif variant == "optimized":
|
||||
key = f"{att.s3_key}_opt.webp"
|
||||
mime = "image/webp"
|
||||
|
||||
obj = s3.get_object(Bucket=BUCKET, Key=key)
|
||||
content = obj["Body"].read()
|
||||
mime = "image/jpeg" if variant == "thumbnail" else att.content_type
|
||||
return Response(content=content, media_type=mime)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user