From 55e852cd8792c9d158b8b5647bec530cbee1f43a Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Tue, 31 Jan 2023 06:10:19 -0500 Subject: [PATCH] file_manager: add thumbnail request endpoint Signed-off-by: Eric Callahan --- .../components/file_manager/file_manager.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/moonraker/components/file_manager/file_manager.py b/moonraker/components/file_manager/file_manager.py index b1f6fda..e8efbe5 100644 --- a/moonraker/components/file_manager/file_manager.py +++ b/moonraker/components/file_manager/file_manager.py @@ -104,6 +104,9 @@ class FileManager: self.server.register_endpoint( "/server/files/delete_file", ['DELETE'], self._handle_file_delete, transports=["websocket"]) + self.server.register_endpoint( + "/server/files/thumbnails", ['GET'], self._handle_list_thumbs, + transports=["websocket"]) # register client notificaitons self.server.register_notification("file_manager:filelist_changed") @@ -378,6 +381,25 @@ class FileManager: }) return root_list + async def _handle_list_thumbs( + self, web_request: WebRequest + ) -> List[Dict[str, Any]]: + requested_file: str = web_request.get_str("filename") + metadata: Optional[Dict[str, Any]] + metadata = self.gcode_metadata.get(requested_file, None) + if metadata is None: + return [] + if "thumbnails" not in metadata: + return [] + thumblist: List[Dict[str, Any]] = metadata["thumbnails"] + for info in thumblist: + relpath: Optional[str] = info.pop("relative_path", None) + if relpath is None: + continue + thumbpath = pathlib.Path(requested_file).parent.joinpath(relpath) + info["thumbnail_path"] = str(thumbpath) + return thumblist + async def _handle_directory_request(self, web_request: WebRequest ) -> Dict[str, Any]: @@ -1751,7 +1773,7 @@ class MetadataStorage: str, Tuple[Dict[str, Any], asyncio.Event]] = {} self.busy: bool = False - def prune_storage(self): + def prune_storage(self) -> None: # Check for removed gcode files while moonraker was shutdown if self.gc_path: del_keys: List[str] = []