Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update backend_structured/routes.py
Browse files- backend_structured/routes.py +28 -14
backend_structured/routes.py
CHANGED
|
@@ -53,7 +53,10 @@ from scanners.base_scanner import (
|
|
| 53 |
cleanup_scan_logs, schedule_log_cleanup, emit_scan_progress
|
| 54 |
)
|
| 55 |
from scanners import get_pipeline, get_phases, build_scanner, apply_scan_options
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
| 57 |
from cryptography import x509
|
| 58 |
from cryptography.hazmat.backends import default_backend
|
| 59 |
|
|
@@ -891,17 +894,23 @@ def upload_organization_logo(current_user):
|
|
| 891 |
if not file_bytes:
|
| 892 |
return jsonify({'message': 'No valid logo file or URL provided'}), 400
|
| 893 |
|
| 894 |
-
|
|
|
|
|
|
|
|
|
|
| 895 |
|
| 896 |
filename = secure_filename(f"org_{org.id}_{int(time.time())}.{ext}")
|
| 897 |
logo_url = None
|
| 898 |
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
|
|
|
|
|
|
|
|
|
| 905 |
|
| 906 |
if not logo_url:
|
| 907 |
# Fallback: save to local disk
|
|
@@ -2350,15 +2359,20 @@ def generate_pdf_report(current_user, scan_id):
|
|
| 2350 |
date_str = scan_date.strftime('%d%m%Y')
|
| 2351 |
filename = f"LarShield_{clean_org_name}_Report_{date_str}.pdf"
|
| 2352 |
|
| 2353 |
-
# Store a copy in Firebase Cloud Storage for history
|
| 2354 |
-
|
| 2355 |
-
if is_available():
|
| 2356 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2357 |
blob_path = f"reports/{scan_id}/{filename}"
|
| 2358 |
upload_bytes(pdf_bytes_data, 'application/pdf', blob_path)
|
| 2359 |
-
|
| 2360 |
-
|
| 2361 |
-
|
|
|
|
| 2362 |
|
| 2363 |
return send_file(
|
| 2364 |
pdf_bytes,
|
|
|
|
| 53 |
cleanup_scan_logs, schedule_log_cleanup, emit_scan_progress
|
| 54 |
)
|
| 55 |
from scanners import get_pipeline, get_phases, build_scanner, apply_scan_options
|
| 56 |
+
try:
|
| 57 |
+
from backend.utils.fuzzer_engine import ContextAwareFuzzer
|
| 58 |
+
except ImportError:
|
| 59 |
+
from utils.fuzzer_engine import ContextAwareFuzzer
|
| 60 |
from cryptography import x509
|
| 61 |
from cryptography.hazmat.backends import default_backend
|
| 62 |
|
|
|
|
| 894 |
if not file_bytes:
|
| 895 |
return jsonify({'message': 'No valid logo file or URL provided'}), 400
|
| 896 |
|
| 897 |
+
try:
|
| 898 |
+
from backend.utils.firebase_storage import is_available, upload_bytes
|
| 899 |
+
except ImportError:
|
| 900 |
+
from utils.firebase_storage import is_available, upload_bytes
|
| 901 |
|
| 902 |
filename = secure_filename(f"org_{org.id}_{int(time.time())}.{ext}")
|
| 903 |
logo_url = None
|
| 904 |
|
| 905 |
+
try:
|
| 906 |
+
if is_available():
|
| 907 |
+
# Upload to Firebase Cloud Storage
|
| 908 |
+
blob_path = f"logos/{org.id}/{filename}"
|
| 909 |
+
logo_url = upload_bytes(file_bytes, content_type, blob_path)
|
| 910 |
+
if not logo_url:
|
| 911 |
+
current_app.logger.warning(f"[Firebase] Upload failed for {blob_path}. Falling back to local disk storage.")
|
| 912 |
+
except Exception as fb_err:
|
| 913 |
+
current_app.logger.warning(f"[Firebase] Storage check/upload skipped: {fb_err}")
|
| 914 |
|
| 915 |
if not logo_url:
|
| 916 |
# Fallback: save to local disk
|
|
|
|
| 2359 |
date_str = scan_date.strftime('%d%m%Y')
|
| 2360 |
filename = f"LarShield_{clean_org_name}_Report_{date_str}.pdf"
|
| 2361 |
|
| 2362 |
+
# Store a copy in Firebase Cloud Storage for history (non-blocking)
|
| 2363 |
+
try:
|
|
|
|
| 2364 |
try:
|
| 2365 |
+
from backend.utils.firebase_storage import is_available, upload_bytes
|
| 2366 |
+
except ImportError:
|
| 2367 |
+
from utils.firebase_storage import is_available, upload_bytes
|
| 2368 |
+
|
| 2369 |
+
if is_available():
|
| 2370 |
blob_path = f"reports/{scan_id}/{filename}"
|
| 2371 |
upload_bytes(pdf_bytes_data, 'application/pdf', blob_path)
|
| 2372 |
+
except Exception as fb_err:
|
| 2373 |
+
print(f"[Firebase] PDF backup skipped/failed for {scan_id}: {fb_err}")
|
| 2374 |
+
|
| 2375 |
+
pdf_bytes.seek(0)
|
| 2376 |
|
| 2377 |
return send_file(
|
| 2378 |
pdf_bytes,
|