feat: initial commit - massive-cloud point cloud processing system
This commit is contained in:
33
server/cadFilePick.ts
Normal file
33
server/cadFilePick.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import * as path from 'path';
|
||||
|
||||
/** 与 DB model_cad_files / 上传接口一致的最小字段 */
|
||||
export type CadFileRow = {
|
||||
format: string | null;
|
||||
name: string;
|
||||
filePath: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 解析扩展名:优先数据库 format,否则从文件名推断(避免 format 为空或录入错误)。
|
||||
*/
|
||||
export function resolveCadExtension(f: CadFileRow): string {
|
||||
let ext = (f.format || '').trim().toLowerCase().replace(/^\./, '');
|
||||
if (!ext && f.name) {
|
||||
ext = path.extname(f.name).slice(1).toLowerCase();
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平滑热力:优先 STL,其次 OBJ(与前端可加载格式对齐)。
|
||||
*/
|
||||
export function pickCadFileForHeatmap(
|
||||
files: CadFileRow[],
|
||||
): { file: CadFileRow; ext: 'stl' | 'obj' } | null {
|
||||
const withExt = files.map((file) => ({ file, ext: resolveCadExtension(file) }));
|
||||
const stl = withExt.find((x) => x.ext === 'stl');
|
||||
if (stl) return { file: stl.file, ext: 'stl' };
|
||||
const obj = withExt.find((x) => x.ext === 'obj');
|
||||
if (obj) return { file: obj.file, ext: 'obj' };
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user