Skip to content

Commit

Permalink
url encode thumbnail URL
Browse files Browse the repository at this point in the history
now that OctoPrint allows filenames with special characters need to adjust the URL to not use reserved characters, #84
  • Loading branch information
jneilliii committed Jan 7, 2022
1 parent c82ebdb commit 91b85b8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion octoprint_prusaslicerthumbnails/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import re
import base64

try:
from urllib import quote_plus
except ImportError:
from urllib.parse import quote_plus


class PrusaslicerthumbnailsPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.AssetPlugin,
Expand Down Expand Up @@ -169,6 +174,7 @@ def on_event(self, event, payload):
results = self._process_gcode(local_files[file_key], results)
self._logger.debug("Scan results: {}".format(results))
if event in ["FileAdded", "FileRemoved"] and payload["storage"] == "local" and "gcode" in payload["type"]:
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)

Expand All @@ -178,7 +184,7 @@ def on_event(self, event, payload):
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, datetime.datetime.now())
thumbnail_url = "plugin/prusaslicerthumbnails/thumbnail/{}?{:%Y%m%d%H%M%S}".format(thumbnail_path.replace(thumbnail_name, quote_plus(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)

Expand Down

0 comments on commit 91b85b8

Please sign in to comment.