MariaKaiser commited on
Commit
1cd3435
·
verified ·
1 Parent(s): e6685d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -86,25 +86,23 @@ async def download_to_cache(url: str, subfolder: str):
86
  # -----------------------------
87
  # Preload all assets from Supabase at startup
88
  # -----------------------------
89
- def list_all_files_recursive(bucket_name: str, path="") -> list[tuple[str, str]]:
90
- """
91
- Returns a list of (file_name, public_url) for all files in the bucket, including nested folders.
92
- Folders themselves are ignored.
93
- """
94
  files_list = []
95
- response = supabase.storage.from_(bucket_name).list(path=path)
 
 
 
 
 
96
 
97
  for f in response:
98
- # Safely get type, default to 'file' if missing
99
- item_type = f.get("type", "file")
100
- item_name = f["name"]
101
- full_path = f"{path}/{item_name}" if path else item_name
102
 
103
- if item_type == "folder":
104
- # Recursively get files in this folder
105
  files_list.extend(list_all_files_recursive(bucket_name, full_path))
106
  else:
107
- # Only add actual files
108
  url = supabase.storage.from_(bucket_name).get_public_url(full_path)
109
  files_list.append((full_path, url))
110
 
 
86
  # -----------------------------
87
  # Preload all assets from Supabase at startup
88
  # -----------------------------
89
+ def list_all_files_recursive(bucket_name: str, path=""):
 
 
 
 
90
  files_list = []
91
+
92
+ try:
93
+ response = supabase.storage.from_(bucket_name).list(path=path)
94
+ except Exception as e:
95
+ print(f"Warning listing {bucket_name}/{path}: {e}")
96
+ return files_list
97
 
98
  for f in response:
99
+ name = f["name"]
100
+ full_path = f"{path}/{name}" if path else name
 
 
101
 
102
+ # If metadata is None → it's a folder
103
+ if f.get("metadata") is None:
104
  files_list.extend(list_all_files_recursive(bucket_name, full_path))
105
  else:
 
106
  url = supabase.storage.from_(bucket_name).get_public_url(full_path)
107
  files_list.append((full_path, url))
108