From e8dad1c8c0ca15208ff6a4889005d64358cb9380 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sun, 30 Oct 2022 16:39:01 -0400 Subject: [PATCH] file_manager: add list roots endpoint Signed-off-by: Eric Callahan --- moonraker/components/file_manager/file_manager.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/moonraker/components/file_manager/file_manager.py b/moonraker/components/file_manager/file_manager.py index 0631427..6e27bda 100644 --- a/moonraker/components/file_manager/file_manager.py +++ b/moonraker/components/file_manager/file_manager.py @@ -86,6 +86,8 @@ class FileManager: "/server/files/list", ['GET'], self._handle_filelist_request) self.server.register_endpoint( "/server/files/metadata", ['GET'], self._handle_metadata_request) + self.server.register_endpoint( + "/server/files/roots", ['GET'], self._handle_list_roots) self.server.register_endpoint( "/server/files/directory", ['GET', 'POST', 'DELETE'], self._handle_directory_request) @@ -334,6 +336,19 @@ class FileManager: metadata['filename'] = requested_file return metadata + async def _handle_list_roots( + self, web_request: WebRequest + ) -> List[Dict[str, Any]]: + root_list: List[Dict[str, Any]] = [] + for name, path in self.file_paths.items(): + perms = "rw" if name in self.full_access_roots else "r" + root_list.append({ + "name": name, + "path": path, + "permissions": perms + }) + return root_list + async def _handle_directory_request(self, web_request: WebRequest ) -> Dict[str, Any]: