Skip to content

Commit 9689516

Browse files
committed
tidy up
1 parent 5b39d91 commit 9689516

3 files changed

Lines changed: 4 additions & 14 deletions

File tree

‎image-redraw/src/image_redraw/api.py‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
ALLOWED_CONTENT_TYPES,
99
GALLERY_SIZE,
1010
LIST_PAGE_SIZE,
11-
MAX_UPLOAD_BYTES,
1211
OUTPUT_PREFIX,
1312
STATUS_MAP,
1413
failure_key,
@@ -33,20 +32,13 @@ def declared_length(request: Request) -> int | None:
3332

3433
@app.post("/api/jobs", status_code=202)
3534
async def create_job(request: Request) -> dict[str, str]:
36-
content_type = request.headers.get("content-type", "").split(";")[0].strip().lower()
37-
if content_type not in ALLOWED_CONTENT_TYPES:
35+
content_type = request.headers.get("content-type", "")
36+
if not content_type.startswith(ALLOWED_CONTENT_TYPES):
3837
raise HTTPException(415, "Send a raw image/png, image/jpeg or image/webp body.")
3938

40-
too_long = f"Images must be at most {MAX_UPLOAD_BYTES} bytes."
41-
length = declared_length(request)
42-
if length is not None and length > MAX_UPLOAD_BYTES:
43-
raise HTTPException(413, too_long)
44-
4539
image = await request.body()
4640
if not image:
4741
raise HTTPException(400, "The request body is empty.")
48-
if len(image) > MAX_UPLOAD_BYTES:
49-
raise HTTPException(413, too_long)
5042

5143
env = request.scope["env"]
5244
job_id = uuid.uuid4().hex
@@ -151,7 +143,6 @@ async def get_image(kind: str, job_id: str, request: Request) -> Response:
151143
if obj is None:
152144
raise HTTPException(404, "Image not found.")
153145

154-
# Serve the type recorded when the bytes were stored; never guess from the key.
155146
http_metadata = obj.httpMetadata
156147
media_type = http_metadata.contentType if http_metadata is not None else None
157148
blob = await obj.blob()

‎image-redraw/src/image_redraw/constants.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
OUTPUT_PREFIX = "outputs/"
2626
FAILURE_PREFIX = "failures/"
2727

28-
ALLOWED_CONTENT_TYPES = {"image/png", "image/jpeg", "image/webp"}
29-
MAX_UPLOAD_BYTES = 5_000_000
28+
ALLOWED_CONTENT_TYPES = ("image/png", "image/jpeg", "image/webp")
3029

3130
# A deliberately small, fixed canvas for this example: it keeps inference cheap
3231
# and every reference picture uniform. It is a choice made here, not a limit

‎image-redraw/src/image_redraw/workflow.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727

2828
# Magic bytes, because the model tells us nothing about the format it picked.
29-
IMAGE_SIGNATURES = ((b"\x89PNG", "image/png"), (b"\xff\xd8\xff", "image/jpeg"))
29+
IMAGE_SIGNATURES = ((b"\x89PNG", "image/png"), (b"\xff\xd8\xff", "image/jpeg"), (b"RIFF", "image/webp"))
3030

3131

3232
class UnusableImageError(Exception):

0 commit comments

Comments
 (0)