fix(server): return 400 for unknown /upload/image type instead of 500

get_dir_by_type() only bound type_dir for dir_type in {None, "input",
"temp", "output"}. Any other value fell through to
`return type_dir, dir_type` with type_dir never assigned, raising
UnboundLocalError, which aiohttp surfaced as an unhandled HTTP 500.

POST /upload/image and POST /upload/mask both take the type value
straight from the multipart body, so a client typo such as type=foo
produced a server error where a client error is correct.

Return None for an unrecognised type and have image_upload answer 400.
Recognised values are unchanged.
This commit is contained in:
dev-willbird1936 2026-07-25 13:32:47 +01:00
parent f966a2b38c
commit e3942dbcec
1 changed files with 6 additions and 0 deletions

View File

@ -377,6 +377,10 @@ class PromptServer():
type_dir = folder_paths.get_temp_directory()
elif dir_type == "output":
type_dir = folder_paths.get_output_directory()
else:
# Unrecognised type: signal "no directory" instead of falling
# through to an unbound `type_dir` (UnboundLocalError -> 500).
return None, dir_type
return type_dir, dir_type
@ -401,6 +405,8 @@ class PromptServer():
image_upload_type = post.get("type")
upload_dir, image_upload_type = get_dir_by_type(image_upload_type)
if upload_dir is None:
return web.Response(status=400)
if image and image.file:
filename = image.filename