1+ import path from "path" ;
2+ import fs from "fs" ;
3+ import { store } from "../../data/store.js" ;
4+
5+ const DATA_DIR = process . env . DATA_DIR || "./data" ;
6+ const RESULTS_DIR = path . join ( DATA_DIR , "results" ) ;
7+ fs . mkdirSync ( RESULTS_DIR , { recursive : true } ) ;
8+
9+ function mkResultFile ( missionId , type ) {
10+ const filename = `${ missionId } _${ type } _${ Date . now ( ) } .json` ;
11+ const abs = path . join ( RESULTS_DIR , filename ) ;
12+ const url = `/files/results/${ filename } ` ;
13+ return { abs, url, filename } ;
14+ }
15+
16+ /**
17+ * Сейчас: MOCK job, чтобы всё работало сразу.
18+ * Позже: подключим WebODM REST API (create project / upload images / run task).
19+ */
20+ export async function startProcessingJob ( { missionId, type } ) {
21+ const mission = store . getMission ( missionId ) ;
22+ if ( ! mission ) throw new Error ( "MISSION_NOT_FOUND" ) ;
23+
24+ store . setProcessingState ( missionId , { state : "running" , lastType : type , startedAt : new Date ( ) . toISOString ( ) } ) ;
25+
26+ // mock delay
27+ setTimeout ( ( ) => {
28+ const out = mkResultFile ( missionId , type ) ;
29+ const payload = {
30+ missionId,
31+ type,
32+ status : "done" ,
33+ createdAt : new Date ( ) . toISOString ( ) ,
34+ note : "MOCK output. Replace with WebODM integration." ,
35+ outputs : {
36+ // в реале будут GeoTIFF/OBJ/GLB/LAZ etc.
37+ previewUrl : type === "ortho"
38+ ? "https://placehold.co/900x600/4F46E5/FFFFFF?text=Ortho+Map"
39+ : type === "dsm"
40+ ? "https://placehold.co/900x600/059669/FFFFFF?text=DSM"
41+ : "https://placehold.co/900x600/DC2626/FFFFFF?text=3D+Model" ,
42+ } ,
43+ } ;
44+
45+ fs . writeFileSync ( out . abs , JSON . stringify ( payload , null , 2 ) , "utf-8" ) ;
46+
47+ store . setProcessingState ( missionId , {
48+ state : "done" ,
49+ finishedAt : new Date ( ) . toISOString ( ) ,
50+ outputs : {
51+ ...( mission . processing ?. outputs || { } ) ,
52+ [ type ] : { url : out . url , kind : "json" , previewUrl : payload . outputs . previewUrl } ,
53+ } ,
54+ } ) ;
55+ } , 1200 ) ;
56+
57+ return { missionId, type, state : "running" } ;
58+ }
0 commit comments