Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,31 +83,29 @@ async def get_cached_file(url: str, subfolder: str, skip_on_startup: bool = Fals
|
|
| 83 |
# -----------------------------
|
| 84 |
# Preload all assets from Supabase at startup
|
| 85 |
# -----------------------------
|
| 86 |
-
def list_all_files_recursive(bucket_name: str, path=""):
|
| 87 |
"""
|
| 88 |
-
|
| 89 |
-
|
| 90 |
"""
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
response = supabase.storage.from_(bucket_name).list(path=path)
|
| 94 |
-
except Exception as e:
|
| 95 |
-
print(f"Warning: Could not list bucket '{bucket_name}' at path '{path}': {e}")
|
| 96 |
-
return files # return empty, don't crash startup
|
| 97 |
|
| 98 |
for f in response:
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
else:
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
print(f"Warning: Could not get public URL for '{file_path}': {e}")
|
| 110 |
-
return files
|
| 111 |
|
| 112 |
async def preload_all_assets():
|
| 113 |
print("Starting Supabase asset preloading...")
|
|
|
|
| 83 |
# -----------------------------
|
| 84 |
# Preload all assets from Supabase at startup
|
| 85 |
# -----------------------------
|
| 86 |
+
def list_all_files_recursive(bucket_name: str, path="") -> list[tuple[str, str]]:
|
| 87 |
"""
|
| 88 |
+
Returns a list of (file_name, public_url) for all files in the bucket, including nested folders.
|
| 89 |
+
Folders themselves are ignored.
|
| 90 |
"""
|
| 91 |
+
files_list = []
|
| 92 |
+
response = supabase.storage.from_(bucket_name).list(path=path)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
for f in response:
|
| 95 |
+
# Safely get type, default to 'file' if missing
|
| 96 |
+
item_type = f.get("type", "file")
|
| 97 |
+
item_name = f["name"]
|
| 98 |
+
full_path = f"{path}/{item_name}" if path else item_name
|
| 99 |
+
|
| 100 |
+
if item_type == "folder":
|
| 101 |
+
# Recursively get files in this folder
|
| 102 |
+
files_list.extend(list_all_files_recursive(bucket_name, full_path))
|
| 103 |
else:
|
| 104 |
+
# Only add actual files
|
| 105 |
+
url = supabase.storage.from_(bucket_name).get_public_url(full_path)
|
| 106 |
+
files_list.append((full_path, url))
|
| 107 |
+
|
| 108 |
+
return files_list
|
|
|
|
|
|
|
| 109 |
|
| 110 |
async def preload_all_assets():
|
| 111 |
print("Starting Supabase asset preloading...")
|