10. 재접속 현황·완료 표시·재업로드 경고:
- GET /projects/{id}/upload-overview 신설 — 완료 파일 목록(input_files 정본),
중단 청크 세션(진행률), 필수 파일·WF1 분석 완료 여부
- 진입 시 서버 정본으로 슬롯 카드 표시(serverUploaded), localStorage는 보조로 강등
- 파일 재선택 전에도 중단 세션 이어올리기 안내 배너
- 전체 완료 배지 + 완료 슬롯 재업로드 시 교체 확인 모달(승인 시에만 진행)
- 필수 슬롯 검증: 서버 업로드분 있으면 충족 — 단일 파일 교체 업로드 허용
9. 자동 설계 체인 연장 (B03_FileInput_Service_Chain.py):
- WF1 자동 확정 후 같은 백그라운드 태스크에서 ① 계획노선 CSV 기반 B05 기본 경로
계산(solve) ② 경로 확정(stage 2) ③ B06 기본 횡단 설계 확정(stage 3)까지 진행
- 수동 이력 보호: 프로젝트에 경로가 이미 있으면 건너뜀
- 단계별 실패 격리: 실패 단계에서 멈추고 로그·workflow 상태로만 기록
- AUTO_DESIGN_CHAIN_ENABLED config 플래그(기본 True)
typecheck·ruff·B03 unittest(7건) 통과.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
202 lines
5.6 KiB
TypeScript
202 lines
5.6 KiB
TypeScript
/* B03 다중 파일 업로드 API 클라이언트 */
|
|
|
|
import { API_BASE_URL, API_TIMEOUT_MS } from "@config/config_frontend";
|
|
|
|
export interface UploadedFileResult {
|
|
input_file_id: number;
|
|
original_filename: string;
|
|
file_type: string;
|
|
relative_path: string;
|
|
size_bytes: number;
|
|
metadata: Record<string, unknown>;
|
|
}
|
|
|
|
export interface FileUploadResponse {
|
|
status: string;
|
|
project_id: string;
|
|
files: UploadedFileResult[];
|
|
}
|
|
|
|
export interface ChunkSessionCreateResponse {
|
|
status: string;
|
|
project_id: string;
|
|
upload_session_id: string;
|
|
original_filename: string;
|
|
file_size_bytes: number;
|
|
chunk_size_bytes: number;
|
|
total_chunks: number;
|
|
completed_chunks: number;
|
|
}
|
|
|
|
export interface ChunkUploadResponse {
|
|
status: string;
|
|
upload_session_id: string;
|
|
chunk_index: number;
|
|
completed_chunks: number;
|
|
total_chunks: number;
|
|
chunk_hash: string;
|
|
}
|
|
|
|
export interface UploadStatusResponse {
|
|
status: string;
|
|
upload_session_id: string;
|
|
upload_status: string;
|
|
original_filename: string;
|
|
file_size_bytes: number;
|
|
chunk_size_bytes: number;
|
|
total_chunks: number;
|
|
completed_chunks: number;
|
|
completed_chunk_indexes: number[];
|
|
}
|
|
|
|
async function readJsonOrThrow<T>(response: Response): Promise<T> {
|
|
const payload = (await response.json()) as T & { message?: string };
|
|
if (!response.ok) {
|
|
throw new Error(payload.message ?? `HTTP ${response.status}`);
|
|
}
|
|
return payload;
|
|
}
|
|
|
|
export async function uploadProjectFiles(
|
|
projectId: string,
|
|
files: readonly File[],
|
|
): Promise<FileUploadResponse> {
|
|
const formData = new FormData();
|
|
for (const file of files) formData.append("files", file, file.name);
|
|
|
|
const controller = new AbortController();
|
|
const timeoutId = window.setTimeout(() => controller.abort(), API_TIMEOUT_MS);
|
|
try {
|
|
const response = await fetch(`${API_BASE_URL}/projects/${projectId}/files`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
body: formData,
|
|
signal: controller.signal,
|
|
});
|
|
return await readJsonOrThrow<FileUploadResponse>(response);
|
|
} finally {
|
|
window.clearTimeout(timeoutId);
|
|
}
|
|
}
|
|
|
|
export async function createUploadSession(
|
|
projectId: string,
|
|
file: File,
|
|
chunkSizeBytes: number,
|
|
): Promise<ChunkSessionCreateResponse> {
|
|
const response = await fetch(`${API_BASE_URL}/projects/${projectId}/upload-sessions`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
original_filename: file.name,
|
|
size_bytes: file.size,
|
|
chunk_size_bytes: chunkSizeBytes,
|
|
}),
|
|
});
|
|
return await readJsonOrThrow<ChunkSessionCreateResponse>(response);
|
|
}
|
|
|
|
export async function uploadFileChunk(
|
|
projectId: string,
|
|
sessionId: string,
|
|
chunkIndex: number,
|
|
chunk: Blob,
|
|
): Promise<ChunkUploadResponse> {
|
|
const formData = new FormData();
|
|
formData.append("session_id", sessionId);
|
|
formData.append("chunk_index", String(chunkIndex));
|
|
formData.append("chunk_data", chunk, `${sessionId}-${chunkIndex}.chunk`);
|
|
|
|
const response = await fetch(`${API_BASE_URL}/projects/${projectId}/chunks`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
body: formData,
|
|
});
|
|
return await readJsonOrThrow<ChunkUploadResponse>(response);
|
|
}
|
|
|
|
export async function finalizeUploadSession(
|
|
projectId: string,
|
|
sessionId: string,
|
|
totalChunks: number,
|
|
completeUpload: boolean,
|
|
): Promise<FileUploadResponse> {
|
|
const response = await fetch(`${API_BASE_URL}/projects/${projectId}/finalize`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
session_id: sessionId,
|
|
total_chunks: totalChunks,
|
|
complete_upload: completeUpload,
|
|
}),
|
|
});
|
|
return await readJsonOrThrow<FileUploadResponse>(response);
|
|
}
|
|
|
|
export async function fetchUploadStatus(
|
|
projectId: string,
|
|
sessionId: string,
|
|
): Promise<UploadStatusResponse> {
|
|
const response = await fetch(`${API_BASE_URL}/projects/${projectId}/upload-status/${sessionId}`, {
|
|
method: "GET",
|
|
credentials: "include",
|
|
});
|
|
return await readJsonOrThrow<UploadStatusResponse>(response);
|
|
}
|
|
|
|
export interface UploadOverviewFile {
|
|
input_file_id: number;
|
|
file_type: string;
|
|
original_filename: string;
|
|
file_size_mb: number;
|
|
status: string;
|
|
uploaded_at: string | null;
|
|
}
|
|
|
|
export interface UploadOverviewSession {
|
|
upload_session_id: string;
|
|
original_filename: string;
|
|
file_size_bytes: number;
|
|
total_chunks: number;
|
|
completed_chunks: number;
|
|
progress_percent: number;
|
|
updated_at: string | null;
|
|
}
|
|
|
|
export interface UploadOverviewResponse {
|
|
status: string;
|
|
files: UploadOverviewFile[];
|
|
pending_sessions: UploadOverviewSession[];
|
|
required_complete: boolean;
|
|
analysis_complete: boolean;
|
|
}
|
|
|
|
/** 재접속 시 업로드 현황(정본) — 완료 파일 목록 + 중단 세션 + 완료 여부. */
|
|
export async function fetchUploadOverview(projectId: string): Promise<UploadOverviewResponse> {
|
|
const response = await fetch(`${API_BASE_URL}/projects/${projectId}/upload-overview`, {
|
|
method: "GET",
|
|
credentials: "include",
|
|
});
|
|
return await readJsonOrThrow<UploadOverviewResponse>(response);
|
|
}
|
|
|
|
export interface WF1AnalysisStatus {
|
|
project_id: string;
|
|
status: "pending" | "in_progress" | "completed" | "failed";
|
|
model_count: number;
|
|
progress_percent: number;
|
|
current_stage: string;
|
|
message: string;
|
|
error?: string;
|
|
}
|
|
|
|
export async function checkWF1AnalysisStatus(projectId: string): Promise<WF1AnalysisStatus> {
|
|
const response = await fetch(`${API_BASE_URL}/projects/${projectId}/surface/status`, {
|
|
method: "GET",
|
|
credentials: "include",
|
|
});
|
|
return await readJsonOrThrow<WF1AnalysisStatus>(response);
|
|
}
|