fmatituy/selectospromanager
0
1from nicegui import app
2from fastapi.responses import FileResponse
3from pydantic import BaseModel
4import os
5
6class SyncItem(BaseModel):
7 action: str
8 data: dict
9 timestamp: str
10
11def register_api_endpoints(static_path):
12 @app.post('/api/offline-sync')
13 async def offline_sync(item: SyncItem):
14 """Recibe datos guardados en el navegador durante periodos sin internet."""
15 print(f"๐ SINCRONIZANDO OFFLINE: {item.action} @ {item.timestamp}")
16 try:
17 return {"status": "success", "synced": item.action}
18 except Exception as e:
19 return {"status": "error", "message": str(e)}
20
21 @app.get('/descargar/{filename}')
22 async def descargar_archivo(filename: str):
23 """Endpoint seguro para forzar la descarga de archivos generados por la IA."""
24 path = os.path.join(static_path, 'generados', filename)
25 if os.path.exists(path):
26 return FileResponse(
27 path,
28 filename=filename,
29 media_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
30 )
31 from fastapi import HTTPException
32 raise HTTPException(status_code=404, detail="Archivo no encontrado")
33 