AdarshDRC commited on
Commit
7aff74f
·
1 Parent(s): 9fd6d94

fix : setting page issues

Browse files
Files changed (1) hide show
  1. main.py +34 -27
main.py CHANGED
@@ -169,6 +169,8 @@ DEFAULT_PC_KEY = os.getenv("DEFAULT_PINECONE_KEY", "")
169
  DEFAULT_CLD_URL = os.getenv("DEFAULT_CLOUDINARY_URL", "")
170
 
171
  def _is_default_key(key: str, default: str) -> bool:
 
 
172
  return bool(default) and key.strip() == default.strip()
173
 
174
 
@@ -991,34 +993,39 @@ async def delete_account(
991
 
992
  creds = get_cloudinary_creds(user_cloudinary_url)
993
 
994
- # ── Cloudinary: paginated delete ALL resources then folders ───
995
- try:
996
- deleted = await asyncio.to_thread(_cld_delete_all_paginated, creds)
997
- _log_fn("INFO", f"Account delete Cloudinary: {deleted} resources removed")
998
- except Exception as e:
999
- _log_fn("WARNING", f"Account delete Cloudinary: {e}")
1000
-
1001
- try:
1002
- folders_res = await asyncio.to_thread(_cld_root_folders, creds)
1003
- folder_tasks = [
1004
- asyncio.to_thread(_cld_remove_folder, f["name"], creds)
1005
- for f in folders_res.get("folders", [])
1006
- ]
1007
- if folder_tasks:
1008
- await asyncio.gather(*folder_tasks, return_exceptions=True)
1009
- except Exception as e:
1010
- _log_fn("WARNING", f"Account delete Cloudinary folders: {e}")
 
 
1011
 
1012
- # ── Pinecone: delete both indexes ────────────────────────────
1013
- try:
1014
- pc = _get_pinecone(user_pinecone_key)
1015
- existing = {idx.name for idx in await asyncio.to_thread(pc.list_indexes)}
1016
- tasks = []
1017
- if IDX_OBJECTS in existing: tasks.append(asyncio.to_thread(pc.delete_index, IDX_OBJECTS))
1018
- if IDX_FACES in existing: tasks.append(asyncio.to_thread(pc.delete_index, IDX_FACES))
1019
- if tasks: await asyncio.gather(*tasks)
1020
- except Exception as e:
1021
- _log_fn("WARNING", f"Account delete Pinecone: {e}")
 
 
 
1022
 
1023
  log("WARNING", "danger.delete_account.complete",
1024
  user_id=user_id or "anonymous", ip=ip,
 
169
  DEFAULT_CLD_URL = os.getenv("DEFAULT_CLOUDINARY_URL", "")
170
 
171
  def _is_default_key(key: str, default: str) -> bool:
172
+ if not key or not key.strip(): # empty key never matches — prevents blocking users with no keys
173
+ return False
174
  return bool(default) and key.strip() == default.strip()
175
 
176
 
 
993
 
994
  creds = get_cloudinary_creds(user_cloudinary_url)
995
 
996
+ # ── Cloudinary: skip gracefully if user has no credentials ───
997
+ if creds.get("cloud_name"):
998
+ try:
999
+ deleted = await asyncio.to_thread(_cld_delete_all_paginated, creds)
1000
+ _log_fn("INFO", f"Account delete Cloudinary: {deleted} resources removed")
1001
+ except Exception as e:
1002
+ _log_fn("WARNING", f"Account delete Cloudinary: {e}")
1003
+ try:
1004
+ folders_res = await asyncio.to_thread(_cld_root_folders, creds)
1005
+ folder_tasks = [
1006
+ asyncio.to_thread(_cld_remove_folder, f["name"], creds)
1007
+ for f in folders_res.get("folders", [])
1008
+ ]
1009
+ if folder_tasks:
1010
+ await asyncio.gather(*folder_tasks, return_exceptions=True)
1011
+ except Exception as e:
1012
+ _log_fn("WARNING", f"Account delete Cloudinary folders: {e}")
1013
+ else:
1014
+ _log_fn("INFO", "Account delete: no Cloudinary credentials — skipping CDN wipe")
1015
 
1016
+ # ── Pinecone: skip gracefully if user has no key ─────────────
1017
+ if user_pinecone_key and user_pinecone_key.strip():
1018
+ try:
1019
+ pc = _get_pinecone(user_pinecone_key)
1020
+ existing = {idx.name for idx in await asyncio.to_thread(pc.list_indexes)}
1021
+ tasks = []
1022
+ if IDX_OBJECTS in existing: tasks.append(asyncio.to_thread(pc.delete_index, IDX_OBJECTS))
1023
+ if IDX_FACES in existing: tasks.append(asyncio.to_thread(pc.delete_index, IDX_FACES))
1024
+ if tasks: await asyncio.gather(*tasks)
1025
+ except Exception as e:
1026
+ _log_fn("WARNING", f"Account delete Pinecone: {e}")
1027
+ else:
1028
+ _log_fn("INFO", "Account delete: no Pinecone key — skipping vector wipe")
1029
 
1030
  log("WARNING", "danger.delete_account.complete",
1031
  user_id=user_id or "anonymous", ip=ip,