feat: add model file library links
This commit is contained in:
@@ -24,7 +24,9 @@ ensureDir(TASKS_DIR);
|
||||
const diskStorage = multer.diskStorage({
|
||||
destination: (req, _file, cb) => {
|
||||
let dir: string;
|
||||
if (req.params.modelId) {
|
||||
if (req.params.modelId && req.path.includes('/model-pointcloud/')) {
|
||||
dir = path.join(MODELS_DIR, String(parseInt(req.params.modelId, 10)), 'pointcloud');
|
||||
} else if (req.params.modelId) {
|
||||
dir = path.join(MODELS_DIR, String(parseInt(req.params.modelId, 10)), 'cad');
|
||||
} else if (req.params.taskId && req.path.includes('/task-cad/')) {
|
||||
dir = path.join(TASKS_DIR, String(parseInt(req.params.taskId, 10)), 'cad');
|
||||
@@ -92,6 +94,35 @@ router.post('/upload/cad/:modelId', diskUpload.single('file'), async (req, res)
|
||||
});
|
||||
});
|
||||
|
||||
// ─── 车型点云文件上传 ────────────────────────────────────────────────────────
|
||||
// POST /api/files/upload/model-pointcloud/:modelId
|
||||
// multipart/form-data field: file
|
||||
|
||||
router.post('/upload/model-pointcloud/:modelId', diskUpload.single('file'), async (req, res) => {
|
||||
const modelId = parseInt(req.params.modelId, 10);
|
||||
if (!req.file || isNaN(modelId)) {
|
||||
return res.status(400).json({ success: false, error: 'Missing file or modelId' });
|
||||
}
|
||||
|
||||
const destPath = req.file.path;
|
||||
const record = await db.createModelPointcloudFile({
|
||||
modelId,
|
||||
name: req.file.originalname,
|
||||
fileSize: req.file.size,
|
||||
filePath: destPath,
|
||||
});
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
file: {
|
||||
id: record.id,
|
||||
name: record.name,
|
||||
size: formatFileSize(record.fileSize),
|
||||
filePath: record.filePath,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// ─── 任务 CAD 文件上传 ────────────────────────────────────────────────────────
|
||||
// POST /api/files/upload/task-cad/:taskId
|
||||
|
||||
@@ -173,6 +204,17 @@ router.get('/read/cad/:modelId/:filename', (req, res) => {
|
||||
res.sendFile(filePath);
|
||||
});
|
||||
|
||||
// ─── 读取车型点云文件 ─────────────────────────────────────────────────────────
|
||||
// GET /api/files/read/model-pointcloud/:modelId/:filename
|
||||
|
||||
router.get('/read/model-pointcloud/:modelId/:filename', (req, res) => {
|
||||
const pcDir = path.join(MODELS_DIR, req.params.modelId, 'pointcloud');
|
||||
const filePath = safeResolve(pcDir, req.params.filename);
|
||||
if (!filePath) return res.status(403).json({ error: 'Access denied' });
|
||||
if (!fs.existsSync(filePath)) return res.status(404).json({ error: 'File not found' });
|
||||
res.sendFile(filePath);
|
||||
});
|
||||
|
||||
// ─── 读取点云文件 ─────────────────────────────────────────────────────────────
|
||||
// GET /api/files/read/pointcloud/:taskId/:filename
|
||||
|
||||
|
||||
Reference in New Issue
Block a user