fix: tolerate blank creative job requests
This commit is contained in:
16
api/main.py
16
api/main.py
@@ -5486,11 +5486,25 @@ def _write_creative_reference_frame(job_id: str, file_bytes: bytes | None = None
|
||||
|
||||
|
||||
@app.post("/creative/jobs/image", response_model=Job)
|
||||
async def create_creative_image_job(request: Request, file: UploadFile | None = File(default=None)) -> Job:
|
||||
async def create_creative_image_job(request: Request) -> Job:
|
||||
user = data_user_from_request(request)
|
||||
job_id = uuid.uuid4().hex[:12]
|
||||
file_bytes: bytes | None = None
|
||||
source_label = "blank"
|
||||
file: UploadFile | None = None
|
||||
content_type = request.headers.get("content-type", "").lower()
|
||||
if "multipart/form-data" in content_type:
|
||||
content_length = request.headers.get("content-length", "0")
|
||||
if "boundary=" not in content_type and content_length in {"", "0"}:
|
||||
file = None
|
||||
else:
|
||||
try:
|
||||
form = await request.form()
|
||||
except Exception as e:
|
||||
raise HTTPException(400, f"invalid multipart body: {e}")
|
||||
maybe_file = form.get("file")
|
||||
if getattr(maybe_file, "filename", "") and hasattr(maybe_file, "read"):
|
||||
file = maybe_file
|
||||
if file and file.filename:
|
||||
ext = Path(file.filename).suffix.lower()
|
||||
if ext not in {".jpg", ".jpeg", ".png", ".webp"}:
|
||||
|
||||
Reference in New Issue
Block a user