✨ feat(backups): download button for backups
This commit is contained in:
parent
5dfbcd803f
commit
8b6c987640
|
@ -446,11 +446,11 @@ class KlipperPlugin(
|
||||||
bak_path = os.path.join(self.get_plugin_data_folder(), "configs", "")
|
bak_path = os.path.join(self.get_plugin_data_folder(), "configs", "")
|
||||||
|
|
||||||
return [
|
return [
|
||||||
(r"/download/(.*)", LargeResponseHandler, dict(path=configpath,
|
(r"/download/configs/(.*)", LargeResponseHandler, dict(path=configpath,
|
||||||
as_attachment=True,
|
as_attachment=True,
|
||||||
path_validation=path_validation_factory(lambda path: not is_hidden_path(path),
|
path_validation=path_validation_factory(lambda path: not is_hidden_path(path),
|
||||||
status_code=404))),
|
status_code=404))),
|
||||||
(r"/download/backup(.*)", LargeResponseHandler, dict(path=bak_path,
|
(r"/download/backup/(.*)", LargeResponseHandler, dict(path=bak_path,
|
||||||
as_attachment=True,
|
as_attachment=True,
|
||||||
path_validation=path_validation_factory(lambda path: not is_hidden_path(path),
|
path_validation=path_validation_factory(lambda path: not is_hidden_path(path),
|
||||||
status_code=404)))
|
status_code=404)))
|
||||||
|
|
|
@ -39,14 +39,16 @@ def list_cfg_files(self, path: str) -> list:
|
||||||
for f in cfg_files:
|
for f in cfg_files:
|
||||||
filesize = os.path.getsize(f)
|
filesize = os.path.getsize(f)
|
||||||
filemdate = time.localtime(os.path.getmtime(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(
|
files.append(dict(
|
||||||
name=os.path.basename(f),
|
name= os.path.basename(f),
|
||||||
file=f,
|
file= f,
|
||||||
size=" ({:.1f} KB)".format(filesize / 1000.0),
|
size= " ({:.1f} KB)".format(filesize / 1000.0),
|
||||||
mdate=time.strftime("%d.%m.%Y %H:%M", filemdate),
|
mdate= time.strftime("%d.%m.%Y %H:%M", filemdate),
|
||||||
url= flask.url_for("index")
|
url= url,
|
||||||
+ "plugin/klipper/download/"
|
|
||||||
+ os.path.basename(f),
|
|
||||||
))
|
))
|
||||||
logger.log_debug(self, "list_cfg_files " + str(len(files)) + ": " + f)
|
logger.log_debug(self, "list_cfg_files " + str(len(files)) + ": " + f)
|
||||||
return files
|
return files
|
||||||
|
|
|
@ -61,9 +61,12 @@
|
||||||
<a href="javascript:void(0)" class="far fa-trash-alt" title="{{ _('Delete') }}"
|
<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>
|
data-bind="css: {disabled: !$root.klipperViewModel.hasRightKo('CONFIG')()}, click: function() { $parent.removeCfg($data.name); }"></a>
|
||||||
|
|
|
|
||||||
<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>
|
data-bind="css: {disabled: !$root.klipperViewModel.hasRightKo('CONFIG')()}, click: function() { $parent.restoreBak($data.name); }"></a>
|
||||||
|
|
|
|
||||||
|
<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>
|
||||||
|
|
|
||||||
<a href="javascript:void(0)" class="fas fa-camera" title="{{ _('Preview') }}"
|
<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>
|
data-bind="css: {disabled: !$root.klipperViewModel.hasRightKo('CONFIG')()}, click: function() { $parent.showCfg($data.name); }"></a>
|
||||||
</td>
|
</td>
|
||||||
|
|
Loading…
Reference in New Issue