Spaces:
Running
Running
download fix..
Browse files- backend/server.py +28 -15
- frontend/vehicles.html +3 -3
backend/server.py
CHANGED
|
@@ -139,24 +139,37 @@ def get_report(video_id: str, name: str):
|
|
| 139 |
|
| 140 |
@app.get("/reports/zip/{video_id}")
|
| 141 |
def download_all_reports(video_id: str):
|
|
|
|
| 142 |
base_path = REPORT_DIR / video_id
|
| 143 |
if not base_path.exists():
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
# Create zip in temp dir
|
| 147 |
-
zip_base = REPORT_DIR / f"bundle_{video_id}"
|
| 148 |
-
shutil.make_archive(str(zip_base), 'zip', str(base_path))
|
| 149 |
-
|
| 150 |
-
final_zip = Path(f"{zip_base}.zip")
|
| 151 |
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
|
| 162 |
@app.websocket("/ws/run")
|
|
|
|
| 139 |
|
| 140 |
@app.get("/reports/zip/{video_id}")
|
| 141 |
def download_all_reports(video_id: str):
|
| 142 |
+
print(f"[BACKEND] ZIP request for {video_id}")
|
| 143 |
base_path = REPORT_DIR / video_id
|
| 144 |
if not base_path.exists():
|
| 145 |
+
print(f"[BACKEND] Error: {base_path} not found")
|
| 146 |
+
return Response(content=f"Report directory not found for {video_id}", status_code=404)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
+
try:
|
| 149 |
+
# Create zip in temp dir
|
| 150 |
+
zip_base = REPORT_DIR / f"bundle_{video_id}"
|
| 151 |
+
if os.path.exists(f"{zip_base}.zip"):
|
| 152 |
+
os.remove(f"{zip_base}.zip")
|
| 153 |
+
|
| 154 |
+
print(f"[BACKEND] Archiving {base_path} to {zip_base}.zip")
|
| 155 |
+
shutil.make_archive(str(zip_base), 'zip', str(base_path))
|
| 156 |
+
|
| 157 |
+
final_zip = Path(f"{zip_base}.zip")
|
| 158 |
+
if not final_zip.exists():
|
| 159 |
+
raise Exception("Zip file was not created")
|
| 160 |
+
|
| 161 |
+
original_name = video_info.get(video_id, "UrbanFlow_Analysis")
|
| 162 |
+
safe_name = "".join(x for x in original_name if x.isalnum() or x in "._-").rsplit(".", 1)[0]
|
| 163 |
+
|
| 164 |
+
print(f"[BACKEND] Serving ZIP: {final_zip}")
|
| 165 |
+
return FileResponse(
|
| 166 |
+
str(final_zip),
|
| 167 |
+
media_type="application/zip",
|
| 168 |
+
filename=f"{safe_name}_reports.zip"
|
| 169 |
+
)
|
| 170 |
+
except Exception as e:
|
| 171 |
+
print(f"[BACKEND] ZIP Error: {str(e)}")
|
| 172 |
+
return Response(content=str(e), status_code=500)
|
| 173 |
|
| 174 |
|
| 175 |
@app.websocket("/ws/run")
|
frontend/vehicles.html
CHANGED
|
@@ -1512,14 +1512,14 @@
|
|
| 1512 |
if (document.getElementById('sv-auto-download').classList.contains('active')) {
|
| 1513 |
// Download the full bundle ZIP
|
| 1514 |
setTimeout(() => {
|
| 1515 |
-
console.log('[UrbanFlow]
|
| 1516 |
const link = document.createElement('a');
|
| 1517 |
link.href = `/reports/zip/${d.video_id}`;
|
| 1518 |
-
link.download = `
|
| 1519 |
document.body.appendChild(link);
|
| 1520 |
link.click();
|
| 1521 |
document.body.removeChild(link);
|
| 1522 |
-
},
|
| 1523 |
}
|
| 1524 |
});
|
| 1525 |
}
|
|
|
|
| 1512 |
if (document.getElementById('sv-auto-download').classList.contains('active')) {
|
| 1513 |
// Download the full bundle ZIP
|
| 1514 |
setTimeout(() => {
|
| 1515 |
+
console.log('[UrbanFlow] Fetching ZIP bundle for:', d.video_id);
|
| 1516 |
const link = document.createElement('a');
|
| 1517 |
link.href = `/reports/zip/${d.video_id}`;
|
| 1518 |
+
link.download = `UrbanFlow_Reports.zip`;
|
| 1519 |
document.body.appendChild(link);
|
| 1520 |
link.click();
|
| 1521 |
document.body.removeChild(link);
|
| 1522 |
+
}, 1000);
|
| 1523 |
}
|
| 1524 |
});
|
| 1525 |
}
|