feat: add inspection object resource workflow
This commit is contained in:
@@ -97,8 +97,14 @@ function safeResolve(base: string, filename: string): string | null {
|
||||
|
||||
router.post('/upload/cad/:modelId', requireFileWrite, 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 inspectionObjectIds = String(req.body.inspectionObjectIds ?? '').split(',').map(Number).filter(Number.isFinite);
|
||||
if (!req.file || isNaN(modelId) || inspectionObjectIds.length === 0) {
|
||||
return res.status(400).json({ success: false, error: '上传车型 CAD 时必须选择适用检测对象' });
|
||||
}
|
||||
const objects = await Promise.all(inspectionObjectIds.map(id => db.getInspectionObjectById(id)));
|
||||
if (objects.some(object => !object || object.modelId !== modelId)) {
|
||||
await fs.promises.rm(req.file.path, { force: true });
|
||||
return res.status(400).json({ success: false, error: '适用检测对象必须属于当前车型' });
|
||||
}
|
||||
|
||||
const destPath = req.file.path;
|
||||
@@ -110,6 +116,7 @@ router.post('/upload/cad/:modelId', requireFileWrite, diskUpload.single('file'),
|
||||
fileSize: req.file.size,
|
||||
filePath: destPath,
|
||||
});
|
||||
await db.setCadInspectionObjects(record.id, inspectionObjectIds);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
@@ -129,8 +136,14 @@ router.post('/upload/cad/:modelId', requireFileWrite, diskUpload.single('file'),
|
||||
|
||||
router.post('/upload/model-pointcloud/:modelId', requireFileWrite, 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 inspectionObjectId = Number(req.body.inspectionObjectId);
|
||||
if (!req.file || isNaN(modelId) || !Number.isFinite(inspectionObjectId)) {
|
||||
return res.status(400).json({ success: false, error: '上传车型点云时必须选择检测对象' });
|
||||
}
|
||||
const object = await db.getInspectionObjectById(inspectionObjectId);
|
||||
if (!object || object.modelId !== modelId) {
|
||||
await fs.promises.rm(req.file.path, { force: true });
|
||||
return res.status(400).json({ success: false, error: '检测对象必须属于当前车型' });
|
||||
}
|
||||
|
||||
const destPath = req.file.path;
|
||||
@@ -140,6 +153,7 @@ router.post('/upload/model-pointcloud/:modelId', requireFileWrite, diskUpload.si
|
||||
name: req.file.originalname,
|
||||
fileSize: req.file.size,
|
||||
filePath: destPath,
|
||||
inspectionObjectId,
|
||||
...metadata,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user