Spaces:
Sleeping
Sleeping
fix : setting page issues
Browse files
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:
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
|
|
|
|
|
|
|
| 1011 |
|
| 1012 |
-
# ── Pinecone:
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
|
|
|
|
|
|
|
|
|
|
| 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,
|