File size: 2,963 Bytes
b010f1b 56e31ec b010f1b 56e31ec b010f1b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
// API service for AIOptimize
import axios from 'axios';
import type {
UploadResponse,
GenerateResponse,
ChatResponse,
GeoJSONFeature
} from '../types';
const API_BASE = import.meta.env.VITE_API_URL || 'http://localhost:8000';
const api = axios.create({
baseURL: API_BASE,
headers: {
'Content-Type': 'application/json',
},
});
export const apiService = {
// Health check
async health() {
const response = await api.get('/api/health');
return response.data;
},
// Get sample data
async getSampleData(): Promise<GeoJSONFeature> {
const response = await api.get('/api/sample-data');
return response.data;
},
// Upload boundary (JSON)
async uploadBoundary(geojson: GeoJSONFeature): Promise<UploadResponse> {
const response = await api.post('/api/upload-boundary-json', {
geojson: geojson,
});
return response.data;
},
// Upload boundary file (DXF, DWG, or GeoJSON)
async uploadBoundaryFile(file: File): Promise<UploadResponse> {
const formData = new FormData();
formData.append('file', file);
// Use DXF endpoint for .dxf and .dwg files (ezdxf handles both)
const filename = file.name.toLowerCase();
const isDxfOrDwg = filename.endsWith('.dxf') || filename.endsWith('.dwg');
const endpoint = isDxfOrDwg ? '/api/upload-dxf' : '/api/upload-boundary';
const response = await api.post(endpoint, formData, {
headers: { 'Content-Type': 'multipart/form-data' },
});
return response.data;
},
// Generate layouts
async generateLayouts(
sessionId: string,
targetPlots: number = 8,
setback: number = 50
): Promise<GenerateResponse> {
const response = await api.post('/api/generate-layouts', {
session_id: sessionId,
target_plots: targetPlots,
setback: setback,
});
return response.data;
},
// Chat
async chat(sessionId: string, message: string): Promise<ChatResponse> {
const response = await api.post('/api/chat', {
session_id: sessionId,
message: message,
});
return response.data;
},
// Export DXF
async exportDxf(sessionId: string, optionId: number): Promise<Blob> {
const response = await api.post('/api/export-dxf', {
session_id: sessionId,
option_id: optionId,
}, {
responseType: 'blob',
});
return response.data;
},
// Export all as ZIP
async exportAllDxf(sessionId: string): Promise<Blob> {
const formData = new FormData();
formData.append('session_id', sessionId);
const response = await api.post('/api/export-all-dxf', formData, {
responseType: 'blob',
});
return response.data;
},
};
export default apiService;
|