2026-05-20-01-38-33 完善NII导出与位姿持久化
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { DicomFusionVolume, DicomInfo, DicomPreview, ModuleStyle, OverviewSummary, Project, SessionState, UserRecord } from '../types';
|
||||
import { DicomFusionVolume, DicomInfo, DicomPreview, ModelPose, ModuleStyle, OverviewSummary, Project, SavedModelPose, SessionState, UserRecord } from '../types';
|
||||
|
||||
export type ProjectExportTarget = 'dicom' | 'segmentation' | 'pose';
|
||||
|
||||
async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
|
||||
const response = await fetch(path, {
|
||||
@@ -55,6 +57,11 @@ export const api = {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ moduleStyles }),
|
||||
}),
|
||||
updateProjectModelPoses: (projectId: string, modelPoses: SavedModelPose[]) =>
|
||||
request<Project>(`/api/projects/${projectId}/model-poses`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ modelPoses }),
|
||||
}),
|
||||
getDicomPreview: (projectId: string, slice: number, plane: DicomPreview['plane'] = 'axial', mode: DicomPreview['mode'] = 'default') =>
|
||||
request<DicomPreview>(`/api/projects/${projectId}/dicom-preview?slice=${slice}&plane=${plane}&mode=${mode}`),
|
||||
getDicomFusionVolume: (projectId: string, start: number, end: number, mode: DicomPreview['mode'] = 'soft') =>
|
||||
@@ -67,46 +74,43 @@ export const api = {
|
||||
}),
|
||||
};
|
||||
|
||||
export async function downloadMask(projectId: string, format: 'nii' | 'nii.gz' = 'nii.gz') {
|
||||
const response = await fetch(`/api/projects/${projectId}/export-mask?format=${encodeURIComponent(format)}`, {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`导出失败:${response.status}`);
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
const disposition = response.headers.get('Content-Disposition') ?? '';
|
||||
const match = disposition.match(/filename="([^"]+)"/);
|
||||
const filename = match?.[1] ?? `segmentation-mask.${format}`;
|
||||
const url = URL.createObjectURL(blob);
|
||||
function triggerFileDownload(url: string) {
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
link.rel = 'noopener';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function appendPose(params: URLSearchParams, pose?: ModelPose) {
|
||||
if (pose) {
|
||||
params.set('pose', JSON.stringify(pose));
|
||||
}
|
||||
}
|
||||
|
||||
export async function downloadMask(projectId: string, format: 'nii' | 'nii.gz' = 'nii.gz', pose?: ModelPose) {
|
||||
const params = new URLSearchParams({ format });
|
||||
appendPose(params, pose);
|
||||
triggerFileDownload(`/api/projects/${projectId}/export-mask?${params.toString()}`);
|
||||
}
|
||||
|
||||
export async function downloadProjectExport(projectId: string, target: ProjectExportTarget, format: 'nii' | 'nii.gz' = 'nii.gz', options: { pose?: ModelPose } = {}) {
|
||||
const params = new URLSearchParams({ target, format });
|
||||
if (target !== 'dicom') {
|
||||
appendPose(params, options.pose);
|
||||
}
|
||||
triggerFileDownload(`/api/projects/${projectId}/export-nifti?${params.toString()}`);
|
||||
}
|
||||
|
||||
export async function downloadSelectedProjectExports(projectId: string, targets: ProjectExportTarget[], format: 'nii' | 'nii.gz' = 'nii.gz', options: { pose?: ModelPose } = {}) {
|
||||
targets.forEach((target, index) => {
|
||||
window.setTimeout(() => {
|
||||
void downloadProjectExport(projectId, target, format, options);
|
||||
}, index * 180);
|
||||
});
|
||||
}
|
||||
|
||||
export async function downloadDicomArchive(projectId: string) {
|
||||
const response = await fetch(`/api/projects/${projectId}/dicom-archive`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`DICOM 压缩包下载失败:${response.status}`);
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
const disposition = response.headers.get('Content-Disposition') ?? '';
|
||||
const match = disposition.match(/filename="([^"]+)"/);
|
||||
const filename = match?.[1] ?? `${projectId}-dicom-series.tar.gz`;
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
triggerFileDownload(`/api/projects/${projectId}/dicom-archive`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user