47 lines
1.7 KiB
Python
47 lines
1.7 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_error,
|
|
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:
|
|
return render_html5_ai_structure_error("Заполните входную папку с .cf/.cfe или выгрузкой 1С.")
|
|
if not output_path:
|
|
return render_html5_ai_structure_error("Заполните папку результата.")
|
|
try:
|
|
result = prepare(project_id=effective_project_id, input_path=Path(input_path), output_path=Path(output_path))
|
|
except FileNotFoundError as error:
|
|
return render_html5_ai_structure_error(str(error))
|
|
except PermissionError as error:
|
|
return render_html5_ai_structure_error(f"Нет доступа к папке: {error}")
|
|
except OSError as error:
|
|
return render_html5_ai_structure_error(f"Ошибка файловой системы: {error}")
|
|
return render_html5_ai_structure_result(result)
|