Fix recipe upload to accept file uploads instead of JSON
The CLI client sends multipart file uploads but the server expected JSON. Changed the /recipes/upload endpoint to accept UploadFile and return the additional fields (name, version, variable_inputs, fixed_inputs) that the client expects. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -39,22 +39,55 @@ def get_recipe_service():
|
|||||||
|
|
||||||
@router.post("/upload")
|
@router.post("/upload")
|
||||||
async def upload_recipe(
|
async def upload_recipe(
|
||||||
req: RecipeUploadRequest,
|
file: UploadFile = File(...),
|
||||||
ctx: UserContext = Depends(require_auth),
|
ctx: UserContext = Depends(require_auth),
|
||||||
recipe_service: RecipeService = Depends(get_recipe_service),
|
recipe_service: RecipeService = Depends(get_recipe_service),
|
||||||
):
|
):
|
||||||
"""Upload a new recipe from YAML."""
|
"""Upload a new recipe from YAML file."""
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
# Read the YAML content from the uploaded file
|
||||||
|
yaml_content = (await file.read()).decode("utf-8")
|
||||||
|
|
||||||
|
# Parse YAML to extract recipe info for response
|
||||||
|
try:
|
||||||
|
recipe_data = yaml.safe_load(yaml_content)
|
||||||
|
except yaml.YAMLError as e:
|
||||||
|
raise HTTPException(400, f"Invalid YAML: {e}")
|
||||||
|
|
||||||
|
# Use filename (without extension) as recipe name if not in YAML
|
||||||
|
recipe_name = recipe_data.get("name")
|
||||||
|
if not recipe_name and file.filename:
|
||||||
|
recipe_name = file.filename.rsplit(".", 1)[0]
|
||||||
|
|
||||||
recipe_id, error = await recipe_service.upload_recipe(
|
recipe_id, error = await recipe_service.upload_recipe(
|
||||||
yaml_content=req.yaml_content,
|
yaml_content=yaml_content,
|
||||||
uploader=ctx.actor_id,
|
uploader=ctx.actor_id,
|
||||||
name=req.name,
|
name=recipe_name,
|
||||||
description=req.description,
|
description=recipe_data.get("description"),
|
||||||
)
|
)
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
raise HTTPException(400, error)
|
raise HTTPException(400, error)
|
||||||
|
|
||||||
return {"recipe_id": recipe_id, "message": "Recipe uploaded successfully"}
|
# Extract input info for response
|
||||||
|
inputs = recipe_data.get("inputs", {})
|
||||||
|
variable_inputs = []
|
||||||
|
fixed_inputs = []
|
||||||
|
for input_name, input_def in inputs.items():
|
||||||
|
if isinstance(input_def, dict) and input_def.get("fixed"):
|
||||||
|
fixed_inputs.append(input_name)
|
||||||
|
else:
|
||||||
|
variable_inputs.append(input_name)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"recipe_id": recipe_id,
|
||||||
|
"name": recipe_name or "unnamed",
|
||||||
|
"version": recipe_data.get("version", "1.0"),
|
||||||
|
"variable_inputs": variable_inputs,
|
||||||
|
"fixed_inputs": fixed_inputs,
|
||||||
|
"message": "Recipe uploaded successfully",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("")
|
@router.get("")
|
||||||
|
|||||||
Reference in New Issue
Block a user