@@ -89,22 +89,40 @@ def post(self, entry_key):
8989class StorageResource (Resource ):
9090 def get (self , path ):
9191 """Get file content or list directory based on path"""
92- if path .endswith ('/' ):
92+ # Handle empty path as root directory
93+ if not path :
94+ path = ""
95+
96+ if path .endswith ('/' ) or path == "" :
9397 # List directory
94- # Find all files that start with this path
95- files = StorageFile .query .filter (StorageFile .file_path .like (f'{ path } %' )).all ()
96-
97- # Extract immediate children (not nested)
98- children = set ()
99- for file in files :
100- relative_path = file .file_path [len (path ):]
101- if '/' in relative_path :
102- # It's in a subdirectory, add the directory name
103- dir_name = relative_path .split ('/' )[0 ] + '/'
104- children .add (dir_name )
105- else :
106- # It's a direct child file
107- children .add (relative_path )
98+ # For root directory, find all files
99+ if path == "" :
100+ files = StorageFile .query .all ()
101+ # Extract top-level files and directories
102+ children = set ()
103+ for file in files :
104+ if '/' in file .file_path :
105+ # It's in a subdirectory, add the directory name
106+ dir_name = file .file_path .split ('/' )[0 ] + '/'
107+ children .add (dir_name )
108+ else :
109+ # It's a top-level file
110+ children .add (file .file_path )
111+ else :
112+ # Find all files that start with this path
113+ files = StorageFile .query .filter (StorageFile .file_path .like (f'{ path } %' )).all ()
114+
115+ # Extract immediate children (not nested)
116+ children = set ()
117+ for file in files :
118+ relative_path = file .file_path [len (path ):]
119+ if '/' in relative_path :
120+ # It's in a subdirectory, add the directory name
121+ dir_name = relative_path .split ('/' )[0 ] + '/'
122+ children .add (dir_name )
123+ else :
124+ # It's a direct child file
125+ children .add (relative_path )
108126
109127 return {'files' : sorted (list (children ))}
110128 else :
@@ -189,10 +207,28 @@ def post(self):
189207 db .session .rollback ()
190208 return {'error' : 'Failed to rename' }, 500
191209
210+ class StorageRootResource (Resource ):
211+ def get (self ):
212+ """List all top-level files and directories"""
213+ files = StorageFile .query .all ()
214+ # Extract top-level files and directories
215+ children = set ()
216+ for file in files :
217+ if '/' in file .file_path :
218+ # It's in a subdirectory, add the directory name
219+ dir_name = file .file_path .split ('/' )[0 ] + '/'
220+ children .add (dir_name )
221+ else :
222+ # It's a top-level file
223+ children .add (file .file_path )
224+
225+ return {'files' : sorted (list (children ))}
226+
192227# Register API routes
193228# Storage API routes (more specific routes first)
194229api .add_resource (StorageEntryResource , '/entries/<path:entry_key>' )
195230api .add_resource (StorageFileRenameResource , '/storage/rename' )
231+ api .add_resource (StorageRootResource , '/storage/' )
196232api .add_resource (StorageResource , '/storage/<path:path>' )
197233
198234@app .route ('/' )
0 commit comments