Files
sfera/services/api-server/src/api_server/html5_ai_structure_controller.py
T
m e86f6be385
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled
Prepare AI-ready 1C structure packages
2026-05-21 20:43:14 +03:00

36 lines
1.2 KiB
Python

from __future__ import annotations
from collections.abc import Callable, Iterable
from pathlib import Path
from typing import Any
from fastapi import HTTPException
from api_server.html5_ai_structure import render_html5_ai_structure_page, render_html5_ai_structure_result
from api_server.html5_forms import form_value
def html5_ai_structure_page(
*,
project_id: str,
project_summaries: Callable[[], Iterable[object]],
) -> str:
return render_html5_ai_structure_page(project_id=project_id, projects=project_summaries())
def html5_ai_structure_run(
*,
project_id: str,
form: dict[str, list[str]],
prepare: Callable[..., dict[str, Any]],
) -> str:
effective_project_id = form_value(form, "project_id") or project_id
input_path = form_value(form, "input_path")
output_path = form_value(form, "output_path")
if not input_path:
raise HTTPException(status_code=400, detail="input_path is required")
if not output_path:
raise HTTPException(status_code=400, detail="output_path is required")
result = prepare(project_id=effective_project_id, input_path=Path(input_path), output_path=Path(output_path))
return render_html5_ai_structure_result(result)