Skip to content

Commit

Permalink
adds option to allow for extracting thumbnails into the uploads folder,
Browse files Browse the repository at this point in the history
  • Loading branch information
jneilliii committed Dec 4, 2022
1 parent 9765fe4 commit a07338a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
19 changes: 11 additions & 8 deletions octoprint_prusaslicerthumbnails/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_settings_defaults(self):
'inline_thumbnail_scale_value': "50", 'inline_thumbnail_position_left': False,
'align_inline_thumbnail': False, 'inline_thumbnail_align_value': "left", 'state_panel_thumbnail': True,
'state_panel_thumbnail_scale_value': "100", 'resize_filelist': False, 'filelist_height': "306",
'scale_inline_thumbnail_position': False, 'sync_on_refresh': False}
'scale_inline_thumbnail_position': False, 'sync_on_refresh': False, 'use_uploads_folder': False}

# ~~ AssetPlugin mixin

Expand Down Expand Up @@ -205,20 +205,23 @@ def on_event(self, event, payload):
"type"] and payload.get("name", False):
thumbnail_name = self.regex_extension.sub(".png", payload["name"])
thumbnail_path = self.regex_extension.sub(".png", payload["path"])
thumbnail_filename = "{}/{}".format(self.get_plugin_data_folder(), thumbnail_path)
if not self._settings.get_boolean(["use_uploads_folder"]):
thumbnail_filename = "{}/{}".format(self.get_plugin_data_folder(), thumbnail_path)
else:
thumbnail_filename = self._file_manager.path_on_disk("local", thumbnail_path)

if os.path.exists(thumbnail_filename):
os.remove(thumbnail_filename)
if event == "FileAdded":
gcode_filename = self._file_manager.path_on_disk("local", payload["path"])
self._extract_thumbnail(gcode_filename, thumbnail_filename)
if os.path.exists(thumbnail_filename):
thumbnail_url = "plugin/prusaslicerthumbnails/thumbnail/{}?{:%Y%m%d%H%M%S}".format(
thumbnail_path.replace(thumbnail_name, quote(thumbnail_name)), datetime.datetime.now())
self._file_manager.set_additional_metadata("local", payload["path"], "thumbnail",
thumbnail_url.replace("//", "/"), overwrite=True)
self._file_manager.set_additional_metadata("local", payload["path"], "thumbnail_src",
self._identifier, overwrite=True)
if not self._settings.get_boolean(["use_uploads_folder"]):
thumbnail_url = "plugin/prusaslicerthumbnails/thumbnail/{}?{:%Y%m%d%H%M%S}".format(thumbnail_path.replace(thumbnail_name, quote(thumbnail_name)), datetime.datetime.now())
else:
thumbnail_url = "downloads/files/local/{}?{:%Y%m%d%H%M%S}".format(thumbnail_path.replace(thumbnail_name, quote(thumbnail_name)), datetime.datetime.now())
self._file_manager.set_additional_metadata("local", payload["path"], "thumbnail", thumbnail_url.replace("//", "/"), overwrite=True)
self._file_manager.set_additional_metadata("local", payload["path"], "thumbnail_src", self._identifier, overwrite=True)

# ~~ SimpleApiPlugin mixin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<input type="checkbox" data-bind="checked: settings.plugins.prusaslicerthumbnails.sync_on_refresh"> Rescan all files when pressing refresh in file list.
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.prusaslicerthumbnails.use_uploads_folder"> Extract images into uploads folder.
</label>
</div>
</div>
<div class="row-fluid" data-bind="allowBindings: false">
<div class="row-fluid" data-bind="allowBindings: true">
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "Slicer Thumbnails"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.0.1"
plugin_version = "1.0.2rc1"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit a07338a

Please sign in to comment.