2026-05-20-23-28-51 项目库映射交互与导入提示优化
This commit is contained in:
@@ -243,6 +243,40 @@ function getProjectModelFilePath(project: ProjectRecord, fileName: string) {
|
||||
return path.join(getProjectModelDir(project), fileName);
|
||||
}
|
||||
|
||||
function getProjectDicomInfoCachePath(project: ProjectRecord) {
|
||||
const dicomAssetDir = getProjectDicomDir(project);
|
||||
const resolvedDir = path.resolve(dicomAssetDir);
|
||||
const resolvedUploadDir = path.resolve(uploadDir);
|
||||
if (!resolvedDir.startsWith(`${resolvedUploadDir}${path.sep}`)) {
|
||||
return null;
|
||||
}
|
||||
return path.join(resolvedDir, '.revoxelseg-dicom-info.json');
|
||||
}
|
||||
|
||||
function readCachedDicomInfo(project: ProjectRecord, files: string[]) {
|
||||
const cachePath = getProjectDicomInfoCachePath(project);
|
||||
if (!cachePath || !fs.existsSync(cachePath)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const cached = JSON.parse(fs.readFileSync(cachePath, 'utf8')) as { files?: string[]; info?: unknown };
|
||||
if (!Array.isArray(cached.files) || cached.files.join('|') !== files.join('|') || !cached.info) {
|
||||
return null;
|
||||
}
|
||||
return cached.info;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function writeCachedDicomInfo(project: ProjectRecord, files: string[], info: unknown) {
|
||||
const cachePath = getProjectDicomInfoCachePath(project);
|
||||
if (!cachePath) {
|
||||
return;
|
||||
}
|
||||
fs.writeFileSync(cachePath, JSON.stringify({ generatedAt: now(), files, info }, null, 2));
|
||||
}
|
||||
|
||||
function clearProjectRuntimeCaches(projectId: string) {
|
||||
[...dicomPreviewCache.keys()].forEach((key) => {
|
||||
if (key.startsWith(`${projectId}:`)) {
|
||||
@@ -2391,6 +2425,8 @@ async function startServer() {
|
||||
project.dicomPath = toRepoRelativePath(targetDir);
|
||||
project.dicomCount = dicomFiles.length;
|
||||
project.segmentationResults = [];
|
||||
const dicomInfo = createDicomInfo(project, dicomFiles);
|
||||
writeCachedDicomInfo(project, dicomFiles, dicomInfo);
|
||||
} else {
|
||||
const stlFiles = listFiles(targetDir, '.stl');
|
||||
project.modelPath = toRepoRelativePath(targetDir);
|
||||
@@ -2566,7 +2602,15 @@ async function startServer() {
|
||||
}
|
||||
|
||||
try {
|
||||
res.json(createDicomInfo(project, files));
|
||||
const cachedInfo = readCachedDicomInfo(project, files);
|
||||
if (cachedInfo) {
|
||||
res.json(cachedInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
const info = createDicomInfo(project, files);
|
||||
writeCachedDicomInfo(project, files, info);
|
||||
res.json(info);
|
||||
} catch (error) {
|
||||
res.status(422).json({ message: error instanceof Error ? error.message : 'DICOM 信息解析失败' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user