"""임시 보관함 라우터 보조 — 조각 수 계산·묶음 폴더 확인·상태 갱신. 라우터가 700줄을 넘어 떼어냈다(2026-09-04). 본체와 청크 모듈이 함께 쓰는 것만 둔다. """ from pathlib import Path from typing import Any from B03_FileInput.B03_FileInput_Repository_Temp import ( get_temp_batch, get_temp_batch_file_types, is_batch_required_complete, mark_temp_batch_completed, mark_temp_batch_incomplete, ) from common_util.common_util_storage import ( resolve_temp_batch_path, ) _POINT_CLOUD_FILE_TYPES = frozenset({"las", "laz"}) def _total_chunks(size_bytes: int, chunk_size_bytes: int) -> int: return max(1, (size_bytes + chunk_size_bytes - 1) // chunk_size_bytes) def _iso(value: Any) -> str | None: return value.isoformat() if value is not None and hasattr(value, "isoformat") else None async def _batch_root(connection: Any, *, batch_id: str, user_id: int) -> Path: """소유권을 확인하고 묶음 폴더를 돌려준다.""" await get_temp_batch(connection, batch_id=batch_id, user_id=user_id) return Path(resolve_temp_batch_path(user_id, batch_id)) async def _refresh_batch_status(connection: Any, *, batch_id: str) -> bool: """필수 파일 충족 여부에 맞춰 상태를 맞춘다. 완료 여부를 돌려준다.""" file_types = await get_temp_batch_file_types(connection, batch_id=batch_id) complete = is_batch_required_complete(file_types) if complete: await mark_temp_batch_completed(connection, batch_id=batch_id) else: # 파일을 지워 필수 조건이 깨진 경우 — 프로젝트 연결 대상에서 빠져야 한다. await mark_temp_batch_incomplete(connection, batch_id=batch_id) return complete