/* ============================================================================= * B09_Draft_Print_Drawings.ts * 인쇄 미리보기 도면 영역(PLAN 302-2) — 서버가 만든 목록 · PDF 를 그대로 받음(보는 것 = 받는 것). * 차례 = B07 도면번호 → 구조물 조합 도면(도번마다 한 번) · 서버 `B09_Draft_Print_Drawings_Router.py` * PDF 머리 X-Aislo-Skipped-Images = 못 넣은 그림 {id: 수} → `skippedImagesOf(blob)` * ========================================================================== */ import { API_BASE_URL } from "@config/config_frontend"; import type { DrawingItem, FetchDrawingList, FetchDrawingsPdf } from "./B09_Draft_Print_Types"; /** 도면 한 장 — 약속 꼴(id · name = label) + 서버가 주는 칸 */ export interface PrintDrawingItem extends DrawingItem { source: "b07" | "structure"; kind: string; label: string; number: string; confirmed: boolean; paper: string | null; /** PDF 를 만들어야 셈 — 목록에서는 null */ images_skipped: number | null; } async function failure(response: Response): Promise { const body = (await response.json().catch(() => null)) as { message?: string } | null; return new Error(body?.message ?? `HTTP ${response.status}`); } export const fetchDrawingList: FetchDrawingList = async (projectId) => { const response = await fetch(`${API_BASE_URL}/projects/${projectId}/print/drawings`, { credentials: "include", }); if (!response.ok) throw await failure(response); const items = (await response.json()) as Omit[]; return items.map((item): PrintDrawingItem => ({ ...item, name: item.label })); }; const skipped = new WeakMap>(); export const fetchDrawingsPdf: FetchDrawingsPdf = async (projectId, ids) => { const response = await fetch(`${API_BASE_URL}/projects/${projectId}/print/drawings-pdf`, { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify(ids ? { ids } : {}), }); if (!response.ok) throw await failure(response); const blob = await response.blob(); try { skipped.set(blob, JSON.parse(response.headers.get("X-Aislo-Skipped-Images") ?? "{}")); } catch { /* 머리가 깨졌으면 빠진 그림 없음으로 */ } return blob; }; /** 그 PDF 에서 못 넣은 그림 {도면 id: 수} — 없으면 빈 꼴 */ export function skippedImagesOf(blob: Blob): Record { return skipped.get(blob) ?? {}; }