feat: 添加账号删除功能

This commit is contained in:
qzl
2026-04-10 10:40:44 +08:00
parent 17a1303f00
commit 46513829cd
30 changed files with 1510 additions and 664 deletions
+70
View File
@@ -271,6 +271,76 @@ class SupabaseService(BaseServiceProvider):
return signed_url
raise RuntimeError("Invalid signed url payload")
async def delete_prefix(self, *, bucket: str, prefix: str) -> int:
normalized_prefix = prefix.strip("/")
def _delete_prefix() -> int:
bucket_client = self._ensure_bucket_client(bucket)
list_objects = getattr(bucket_client, "list", None)
remove_objects = getattr(bucket_client, "remove", None)
if not callable(list_objects) or not callable(remove_objects):
raise RuntimeError("Supabase storage delete APIs are unavailable")
offset = 0
limit = 100
total_deleted = 0
while True:
options = {
"limit": limit,
"offset": offset,
"sortBy": {"column": "name", "order": "asc"},
}
try:
raw_entries = list_objects(normalized_prefix, options)
except TypeError:
raw_entries = list_objects(normalized_prefix)
entries = raw_entries if isinstance(raw_entries, list) else []
if not entries:
break
paths: list[str] = []
for entry in entries:
name: str | None = None
if isinstance(entry, dict):
raw_name = entry.get("name")
if isinstance(raw_name, str) and raw_name:
name = raw_name
else:
raw_name = getattr(entry, "name", None)
if isinstance(raw_name, str) and raw_name:
name = raw_name
if name is None:
continue
if normalized_prefix:
paths.append(f"{normalized_prefix}/{name}")
else:
paths.append(name)
if paths:
remove_objects(paths)
total_deleted += len(paths)
if len(entries) < limit:
break
offset += limit
return total_deleted
return await asyncio.to_thread(_delete_prefix)
async def delete_auth_user(self, *, user_id: str) -> None:
def _delete_auth_user() -> None:
admin_client = self.get_admin_client()
auth_admin = getattr(getattr(admin_client, "auth", None), "admin", None)
delete_user = getattr(auth_admin, "delete_user", None)
if not callable(delete_user):
raise RuntimeError("Supabase admin delete_user API is unavailable")
delete_user(user_id)
await asyncio.to_thread(_delete_auth_user)
def parse_signed_url(self, url: str) -> tuple[str, str]:
from urllib.parse import urlparse