import { MAX_SERIES_FILES, MAX_VOLUME_BYTES, type DicomSource, } from "./dicom-series"; const size = (bytes: number) => `${(bytes / 1024 ** 3).toFixed(3)} GiB (${bytes.toLocaleString("en-US")} bytes)`; export function logDicomSeries(sources: DicomSource[]) { const sourceBytes = sources.reduce((total, file) => total + file.size, 0); const largestFileBytes = sources.reduce( (largest, file) => Math.max(largest, file.size), 0 ); // Only sizes and counts: never include paths, share tokens or patient tags. console.info("[DICOM 3D] Series size", { fileCount: sources.length, sourceBytes, sourceSize: size(sourceBytes), largestFileBytes, largestFileSize: size(largestFileBytes), sourceLimit: size(MAX_VOLUME_BYTES), decodedVolumeLimit: size(MAX_VOLUME_BYTES), perFileLimit: "64 MiB", fileCountLimit: MAX_SERIES_FILES, }); return { sourceBytes, largestFileBytes }; } export function logDicomVolumeEstimate( rows: number, cols: number, count: number ) { const decodedBytes = rows * cols * count * Float32Array.BYTES_PER_ELEMENT; console.info("[DICOM 3D] Decoded volume estimate", { dimensions: [cols, rows, count], bytesPerVoxel: Float32Array.BYTES_PER_ELEMENT, decodedBytes, decodedSize: size(decodedBytes), decodedVolumeLimit: size(MAX_VOLUME_BYTES), }); return decodedBytes; } export function dicomLimitExceeded( reason: string, actual: number, limit: number ): never { console.warn(`[DICOM 3D] Limit exceeded: ${reason}`, { actual, limit, ...(reason !== "file count" && { actualSize: size(actual), limitSize: size(limit), }), }); throw new Error("DICOM_VOLUME_LIMIT"); }