feat(backups): download button for backups

This commit is contained in:
thelastWallE 2021-09-05 16:54:44 +02:00
parent 5dfbcd803f
commit 8b6c987640
3 changed files with 15 additions and 10 deletions

View File

@ -446,11 +446,11 @@ class KlipperPlugin(
bak_path = os.path.join(self.get_plugin_data_folder(), "configs", "")
return [
(r"/download/(.*)", LargeResponseHandler, dict(path=configpath,
(r"/download/configs/(.*)", LargeResponseHandler, dict(path=configpath,
as_attachment=True,
path_validation=path_validation_factory(lambda path: not is_hidden_path(path),
status_code=404))),
(r"/download/backup(.*)", LargeResponseHandler, dict(path=bak_path,
(r"/download/backup/(.*)", LargeResponseHandler, dict(path=bak_path,
as_attachment=True,
path_validation=path_validation_factory(lambda path: not is_hidden_path(path),
status_code=404)))

View File

@ -39,14 +39,16 @@ def list_cfg_files(self, path: str) -> list:
for f in cfg_files:
filesize = os.path.getsize(f)
filemdate = time.localtime(os.path.getmtime(f))
if path != "backup":
url = flask.url_for("index") + "plugin/klipper/download/configs/" + os.path.basename(f)
else:
url = flask.url_for("index") + "plugin/klipper/download/backup/" + os.path.basename(f)
files.append(dict(
name=os.path.basename(f),
file=f,
size=" ({:.1f} KB)".format(filesize / 1000.0),
mdate=time.strftime("%d.%m.%Y %H:%M", filemdate),
url= flask.url_for("index")
+ "plugin/klipper/download/"
+ os.path.basename(f),
name= os.path.basename(f),
file= f,
size= " ({:.1f} KB)".format(filesize / 1000.0),
mdate= time.strftime("%d.%m.%Y %H:%M", filemdate),
url= url,
))
logger.log_debug(self, "list_cfg_files " + str(len(files)) + ": " + f)
return files

View File

@ -61,9 +61,12 @@
<a href="javascript:void(0)" class="far fa-trash-alt" title="{{ _('Delete') }}"
data-bind="css: {disabled: !$root.klipperViewModel.hasRightKo('CONFIG')()}, click: function() { $parent.removeCfg($data.name); }"></a>
&nbsp;|&nbsp;
<a href="javascript:void(0)" class="fas fa-download" title="{{ _('Restore') }}"
<a href="javascript:void(0)" class="fas fa-undo" title="{{ _('Restore') }}"
data-bind="css: {disabled: !$root.klipperViewModel.hasRightKo('CONFIG')()}, click: function() { $parent.restoreBak($data.name); }"></a>
&nbsp;|&nbsp;
<a href="javascript:void(0)" class="fas fa-download" title="{{ _('Download') }}"
data-bind="css: {disabled: !$root.klipperViewModel.hasRightKo('CONFIG')()}, attr: { href: ($root.klipperViewModel.hasRightKo('CONFIG')()) ? $data.url : 'javascript:void(0)'}"></a>
&nbsp;|&nbsp;
<a href="javascript:void(0)" class="fas fa-camera" title="{{ _('Preview') }}"
data-bind="css: {disabled: !$root.klipperViewModel.hasRightKo('CONFIG')()}, click: function() { $parent.showCfg($data.name); }"></a>
</td>