file_manager: add thumbnail request endpoint
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
1bad68cb66
commit
55e852cd87
|
@ -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] = []
|
||||
|
|
Loading…
Reference in New Issue