anujakkulkarni commited on
Commit
621f326
·
verified ·
1 Parent(s): 8a933b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -1
app.py CHANGED
@@ -17,6 +17,8 @@ from starlette.requests import Request
17
  import fitz # PyMuPDF
18
  import google.generativeai as genai
19
  from PIL import Image
 
 
20
 
21
  # Azure Blob Storage
22
  try:
@@ -1328,4 +1330,42 @@ async def cleanup_batch(
1328
  "batch_id": batch_id,
1329
  "folder_path": f"{ROOT_FOLDER}/{batch_id}/",
1330
  "container": container_name
1331
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  import fitz # PyMuPDF
18
  import google.generativeai as genai
19
  from PIL import Image
20
+ from fastapi import Query
21
+
22
 
23
  # Azure Blob Storage
24
  try:
 
1330
  "batch_id": batch_id,
1331
  "folder_path": f"{ROOT_FOLDER}/{batch_id}/",
1332
  "container": container_name
1333
+ })
1334
+
1335
+
1336
+ # ============================================================
1337
+ # GENERATE DOWNLOAD URL FROM BLOB PATH (PERMANENT ACCESS)
1338
+ # ============================================================
1339
+
1340
+
1341
+ @app.get("/blob/download-url")
1342
+ def generate_download_url(
1343
+ blob_name: str = Query(..., description="Blob path like POD/BATCH.../file.pdf"),
1344
+ container: str = Query(AZURE_CONTAINER_NAME),
1345
+ expiry_minutes: int = Query(60)
1346
+ ):
1347
+ """
1348
+ Returns fresh SAS download URL.
1349
+ This prevents expired links problem.
1350
+ """
1351
+
1352
+ try:
1353
+ sas_token = generate_blob_sas(
1354
+ account_name=AZURE_STORAGE_ACCOUNT_NAME,
1355
+ container_name=container,
1356
+ blob_name=blob_name,
1357
+ account_key=AZURE_STORAGE_ACCOUNT_KEY,
1358
+ permission=BlobSasPermissions(read=True),
1359
+ expiry=datetime.utcnow() + timedelta(minutes=expiry_minutes)
1360
+ )
1361
+
1362
+ download_url = f"https://{AZURE_STORAGE_ACCOUNT_NAME}.blob.core.windows.net/{container}/{blob_name}?{sas_token}"
1363
+
1364
+ return {
1365
+ "success": True,
1366
+ "download_url": download_url,
1367
+ "expires_in_minutes": expiry_minutes
1368
+ }
1369
+
1370
+ except Exception as e:
1371
+ return {"success": False, "error": str(e)}