AdarshDRC commited on
Commit
5add2a4
·
verified ·
1 Parent(s): 7f323ef

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +6 -3
main.py CHANGED
@@ -286,16 +286,19 @@ async def search_database(
286
  # ══════════════════════════════════════════════════════════════════
287
  @app.post("/api/categories")
288
  async def get_categories(user_cloudinary_url: str = Form("")):
289
- actual_cld_url = user_cloudinary_url or os.getenv("DEFAULT_CLOUDINARY_URL", "")
 
 
 
 
290
  if not actual_cld_url:
291
  return {"categories": []}
292
 
293
  creds = get_cloudinary_creds(actual_cld_url)
294
- if not creds.get("cloud_name"):
295
  return {"categories": []}
296
 
297
  try:
298
- # Uses THIS request's credentials — never touches another user's cloud
299
  result = await asyncio.to_thread(_cld_root_folders, creds)
300
  return {"categories": [f["name"] for f in result.get("folders", [])]}
301
  except Exception as e:
 
286
  # ══════════════════════════════════════════════════════════════════
287
  @app.post("/api/categories")
288
  async def get_categories(user_cloudinary_url: str = Form("")):
289
+ # Priority:
290
+ # 1. Logged-in user sends their own URL → use it, fetch THEIR folders
291
+ # 2. Guest (no URL sent) → use DEFAULT_CLOUDINARY_URL (server owner's demo cloud)
292
+ # 3. No URL anywhere → return empty list, never error
293
+ actual_cld_url = user_cloudinary_url.strip() or os.getenv("DEFAULT_CLOUDINARY_URL", "")
294
  if not actual_cld_url:
295
  return {"categories": []}
296
 
297
  creds = get_cloudinary_creds(actual_cld_url)
298
+ if not creds.get("cloud_name") or not creds.get("api_key"):
299
  return {"categories": []}
300
 
301
  try:
 
302
  result = await asyncio.to_thread(_cld_root_folders, creds)
303
  return {"categories": [f["name"] for f in result.get("folders", [])]}
304
  except Exception as e: