11import express from "express" ;
22import multer from "multer" ;
3- import path from "path" ;
3+ import path from "node: path" ;
44import fs from "fs" ;
55
66import { v4 as uuidv4 } from "uuid" ;
77import { store } from "../../data/store.js" ;
88import { parseAoiFileToFeatureCollection , computeAreaKm2 } from "../../services/aoi/aoi.js" ;
99import { planMissionFromAoi } from "../../services/planner/planner.js" ;
1010import { startProcessingJob } from "../../services/processing/webodm.js" ;
11+ import { chainAppend , hashFileSha256 } from "../../services/chain/chain-client.js" ;
1112
1213const router = express . Router ( ) ;
1314
@@ -79,6 +80,34 @@ router.post("/", upload.single("aoi"), async (req, res) => {
7980 processing : { state : "idle" , outputs : { } } ,
8081 } ) ;
8182
83+ // --- Chain audit: MISSION_CREATED ---
84+ try {
85+ const aoiStoredPath = req . file . path ;
86+ const aoiHash = await hashFileSha256 ( aoiStoredPath ) ;
87+
88+ await chainAppend ( {
89+ event : "MISSION_CREATED" ,
90+ at : new Date ( ) . toISOString ( ) ,
91+ mission : {
92+ id : mission . id ,
93+ name : mission . name ,
94+ areaKm2 : mission . areaKm2 ,
95+ camera : mission . camera ,
96+ gsdCmPerPx : mission . gsdCmPerPx ,
97+ overlapPct : mission . overlapPct ,
98+ speedMps : mission . speedMps ,
99+ } ,
100+ aoi : {
101+ originalName : req . file . originalname ,
102+ storedName : path . basename ( aoiStoredPath ) ,
103+ sha256 : aoiHash ,
104+ } ,
105+ plan : mission . plan ?. derived || null ,
106+ } ) ;
107+ } catch ( e ) {
108+ console . warn ( "[Chain] MISSION_CREATED append failed:" , e ?. message || e ) ;
109+ }
110+
82111 res . status ( 201 ) . json ( mission ) ;
83112 } catch ( e ) {
84113 console . error ( "[missions.create] error:" , e ) ;
@@ -106,4 +135,4 @@ router.post("/:id/process", async (req, res) => {
106135 }
107136} ) ;
108137
109- export default router ;
138+ export default router ;
0 commit comments