uploading zip
This commit is contained in:
@@ -7,11 +7,11 @@ const merge = require("lodash.merge");
|
|||||||
const config_defaults = require("../resources/onefinity_defaults.json");
|
const config_defaults = require("../resources/onefinity_defaults.json");
|
||||||
|
|
||||||
const variant_defaults = {
|
const variant_defaults = {
|
||||||
machinist_x35: require("../resources/onefinity_machinist_x35_defaults.json"),
|
machinist_x35: require("../resources/onefinity_machinist_x35_defaults.json"),
|
||||||
woodworker_x35: require("../resources/onefinity_woodworker_x35_defaults.json"),
|
woodworker_x35: require("../resources/onefinity_woodworker_x35_defaults.json"),
|
||||||
woodworker_x50: require("../resources/onefinity_woodworker_x50_defaults.json"),
|
woodworker_x50: require("../resources/onefinity_woodworker_x50_defaults.json"),
|
||||||
journeyman_x50: require("../resources/onefinity_journeyman_x50_defaults.json"),
|
journeyman_x50: require("../resources/onefinity_journeyman_x50_defaults.json"),
|
||||||
foreman_pro: require('../resources/onefinity_foreman_pro_defaults.json')
|
foreman_pro: require("../resources/onefinity_foreman_pro_defaults.json"),
|
||||||
};
|
};
|
||||||
|
|
||||||
const z_slider_defaults = {
|
const z_slider_defaults = {
|
||||||
@@ -25,135 +25,138 @@ const z_slider_defaults = {
|
|||||||
"min-soft-limit": -160,
|
"min-soft-limit": -160,
|
||||||
"max-velocity": 7,
|
"max-velocity": 7,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
template: "#admin-general-view-template",
|
template: "#admin-general-view-template",
|
||||||
props: [ "config", "state" ],
|
props: ["config", "state"],
|
||||||
|
|
||||||
data: function() {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
confirmReset: false,
|
confirmReset: false,
|
||||||
autoCheckUpgrade: true,
|
autoCheckUpgrade: true,
|
||||||
reset_variant: "",
|
reset_variant: "",
|
||||||
z_slider: false,
|
z_slider: false,
|
||||||
z_slider_variant:" ",
|
z_slider_variant: " ",
|
||||||
config:""
|
config: "",
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
ready: function () {
|
||||||
|
this.autoCheckUpgrade = this.config.admin["auto-check-upgrade"];
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
backup: function () {
|
||||||
|
document.getElementById("download-target").src =
|
||||||
|
"/api/config/download/" + this.state.macros_list.map(item => item.file_name).join(",");
|
||||||
},
|
},
|
||||||
|
|
||||||
ready: function() {
|
restore_config: function () {
|
||||||
this.autoCheckUpgrade = this.config.admin["auto-check-upgrade"];
|
utils.clickFileInput("restore-config");
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
restore: async function (e) {
|
||||||
backup: function() {
|
const files = e.target.files || e.dataTransfer.files;
|
||||||
document.getElementById("download-target").src = "/api/config/download/"+ this.state.macros_list.map(item => item.file_name).join(",");
|
if (!files.length) {
|
||||||
},
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await api.put("/api/config/restore", files[0]);
|
||||||
|
SvelteComponents.showDialog("Message", {
|
||||||
|
title: "Success",
|
||||||
|
message: "Configuration restored",
|
||||||
|
});
|
||||||
|
this.confirmReset = false;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Restore Failed: ", error);
|
||||||
|
alert("Restore failed");
|
||||||
|
}
|
||||||
|
|
||||||
restore_config: function() {
|
// const fileReader = new FileReader();
|
||||||
utils.clickFileInput("restore-config");
|
// fileReader.onload = async ({ target }) => {
|
||||||
},
|
// let config;
|
||||||
|
// try {
|
||||||
|
// config = JSON.parse(target.result);
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error("Invalid config file:", error);
|
||||||
|
// alert("Invalid config file");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
restore: function(e) {
|
// try {
|
||||||
const files = e.target.files || e.dataTransfer.files;
|
// await api.put("config/save", config);
|
||||||
if (!files.length) {
|
// this.$dispatch("update");
|
||||||
return;
|
// SvelteComponents.showDialog("Message", {
|
||||||
}
|
// title: "Success",
|
||||||
|
// message: "Configuration restored"
|
||||||
|
// });
|
||||||
|
// this.confirmReset= false
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error("Restore failed:", error);
|
||||||
|
// alert("Restore failed");
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
console.log(files);
|
// fileReader.readAsText(files[0]);
|
||||||
|
},
|
||||||
|
|
||||||
// const fileReader = new FileReader();
|
next: async function () {
|
||||||
// fileReader.onload = async ({ target }) => {
|
const config = merge({}, config_defaults, variant_defaults[this.reset_variant]);
|
||||||
// let config;
|
|
||||||
// try {
|
|
||||||
// config = JSON.parse(target.result);
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error("Invalid config file:", error);
|
|
||||||
// alert("Invalid config file");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// try {
|
try {
|
||||||
// await api.put("config/save", config);
|
await api.put("config/save", config);
|
||||||
// this.$dispatch("update");
|
this.confirmReset = false;
|
||||||
// SvelteComponents.showDialog("Message", {
|
this.$dispatch("update");
|
||||||
// title: "Success",
|
this.config = config;
|
||||||
// message: "Configuration restored"
|
this.z_slider = true;
|
||||||
// });
|
} catch (error) {
|
||||||
// this.confirmReset= false
|
console.error("Restore failed:", error);
|
||||||
// } catch (error) {
|
alert("Restore failed");
|
||||||
// console.error("Restore failed:", error);
|
}
|
||||||
// alert("Restore failed");
|
},
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// fileReader.readAsText(files[0]);
|
set_z_slider: async function () {
|
||||||
},
|
const z_variant = merge({}, this.config.motors[3], z_slider_defaults[this.z_slider_variant]);
|
||||||
|
|
||||||
next: async function() {
|
|
||||||
const config = merge(
|
|
||||||
{},
|
|
||||||
config_defaults,
|
|
||||||
variant_defaults[this.reset_variant]
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await api.put("config/save", config);
|
|
||||||
this.confirmReset = false;
|
|
||||||
this.$dispatch("update");
|
|
||||||
this.config= config
|
|
||||||
this.z_slider = true;
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Restore failed:", error);
|
|
||||||
alert("Restore failed");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
set_z_slider: async function(){
|
|
||||||
const z_variant = merge(
|
|
||||||
{},
|
|
||||||
this.config.motors[3],
|
|
||||||
z_slider_defaults[this.z_slider_variant],
|
|
||||||
);
|
|
||||||
|
|
||||||
this.config.motors[3] = z_variant;
|
|
||||||
try {
|
|
||||||
await api.put("config/save", this.config);
|
|
||||||
this.$dispatch("update");
|
|
||||||
SvelteComponents.showDialog("Message", {
|
|
||||||
title: "Success",
|
|
||||||
message: "Configuration restored",
|
|
||||||
});
|
|
||||||
this.z_slider = false;
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Z slider failed:", error);
|
|
||||||
alert("failed to set Z slider ");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
check: function() {
|
|
||||||
this.$dispatch("check");
|
|
||||||
},
|
|
||||||
|
|
||||||
upgrade: function() {
|
this.config.motors[3] = z_variant;
|
||||||
this.$dispatch("upgrade");
|
try {
|
||||||
},
|
await api.put("config/save", this.config);
|
||||||
|
this.$dispatch("update");
|
||||||
|
SvelteComponents.showDialog("Message", {
|
||||||
|
title: "Success",
|
||||||
|
message: "Configuration restored",
|
||||||
|
});
|
||||||
|
this.z_slider = false;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Z slider failed:", error);
|
||||||
|
alert("failed to set Z slider ");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
check: function () {
|
||||||
|
this.$dispatch("check");
|
||||||
|
},
|
||||||
|
|
||||||
upload_firmware: function() {
|
upgrade: function () {
|
||||||
utils.clickFileInput("upload-firmware");
|
this.$dispatch("upgrade");
|
||||||
},
|
},
|
||||||
|
|
||||||
upload: function(e) {
|
upload_firmware: function () {
|
||||||
const files = e.target.files || e.dataTransfer.files;
|
utils.clickFileInput("upload-firmware");
|
||||||
if (!files.length) {
|
},
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.$dispatch("upload", files[0]);
|
|
||||||
},
|
|
||||||
|
|
||||||
change_auto_check_upgrade: function() {
|
upload: function (e) {
|
||||||
this.config.admin["auto-check-upgrade"] = this.autoCheckUpgrade;
|
const files = e.target.files || e.dataTransfer.files;
|
||||||
this.$dispatch("config-changed");
|
if (!files.length) {
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
this.$dispatch("upload", files[0]);
|
||||||
|
},
|
||||||
|
|
||||||
|
change_auto_check_upgrade: function () {
|
||||||
|
this.config.admin["auto-check-upgrade"] = this.autoCheckUpgrade;
|
||||||
|
this.$dispatch("config-changed");
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -293,6 +293,30 @@ class ConfigDownloadHandler(bbctrl.APIHandler):
|
|||||||
self.write(buffer.getvalue())
|
self.write(buffer.getvalue())
|
||||||
self.finish()
|
self.finish()
|
||||||
|
|
||||||
|
class ConfigRestoreHandler(bbctrl.APIHandler):
|
||||||
|
def put(self):
|
||||||
|
zip_file = self.request.files['file'][0]
|
||||||
|
if not os.path.exists('./config-temp'):
|
||||||
|
os.mkdir('./config-temp')
|
||||||
|
|
||||||
|
if not os.path.exists(self.get_upload()):
|
||||||
|
os.mkdir(self.get_upload())
|
||||||
|
|
||||||
|
zip_path = os.path.join("./temp", zip_file['filename'])
|
||||||
|
print(zip_path)
|
||||||
|
# with open(zip_path, 'wb') as f:
|
||||||
|
# f.write(zip_file['body'])
|
||||||
|
|
||||||
|
# with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||||
|
# zip_ref.extractall("./temp")
|
||||||
|
|
||||||
|
# for root, dirs, files in os.walk("./temp"):
|
||||||
|
# for files in files:
|
||||||
|
|
||||||
|
|
||||||
|
self.write("File processed successfully.")
|
||||||
|
self.finish()
|
||||||
|
|
||||||
|
|
||||||
class ConfigSaveHandler(bbctrl.APIHandler):
|
class ConfigSaveHandler(bbctrl.APIHandler):
|
||||||
def put_ok(self): self.get_ctrl().config.save(self.json)
|
def put_ok(self): self.get_ctrl().config.save(self.json)
|
||||||
@@ -640,31 +664,6 @@ class StaticFileHandler(tornado.web.StaticFileHandler):
|
|||||||
self.set_header('Cache-Control',
|
self.set_header('Cache-Control',
|
||||||
'no-store, no-cache, must-revalidate, max-age=0')
|
'no-store, no-cache, must-revalidate, max-age=0')
|
||||||
|
|
||||||
class MacrosUploadHandler(bbctrl.APIHandler):
|
|
||||||
def post(self):
|
|
||||||
zip_file = self.request.files['file'][0]
|
|
||||||
|
|
||||||
if not os.path.exists('./config-temp'):
|
|
||||||
os.mkdir('./config-temp')
|
|
||||||
|
|
||||||
if not os.path.exists(self.get_upload()):
|
|
||||||
os.mkdir(self.get_upload())
|
|
||||||
|
|
||||||
# zip_path = os.path.join("./temp", zip_file['filename'])
|
|
||||||
# with open(zip_path, 'wb') as f:
|
|
||||||
# f.write(zip_file['body'])
|
|
||||||
|
|
||||||
# with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
|
||||||
# zip_ref.extractall("./temp")
|
|
||||||
|
|
||||||
# for root, dirs, files in os.walk("./temp"):
|
|
||||||
# for files in files:
|
|
||||||
|
|
||||||
|
|
||||||
self.write("File processed successfully.")
|
|
||||||
self.finish()
|
|
||||||
|
|
||||||
|
|
||||||
class Web(tornado.web.Application):
|
class Web(tornado.web.Application):
|
||||||
def __init__(self, args, ioloop):
|
def __init__(self, args, ioloop):
|
||||||
self.args = args
|
self.args = args
|
||||||
@@ -699,10 +698,10 @@ class Web(tornado.web.Application):
|
|||||||
(r'/api/config/download(/[^/]+)?', ConfigDownloadHandler),
|
(r'/api/config/download(/[^/]+)?', ConfigDownloadHandler),
|
||||||
(r'/api/config/save', ConfigSaveHandler),
|
(r'/api/config/save', ConfigSaveHandler),
|
||||||
(r'/api/config/reset', ConfigResetHandler),
|
(r'/api/config/reset', ConfigResetHandler),
|
||||||
|
(r'/api/config/restore',ConfigRestoreHandler),
|
||||||
(r'/api/firmware/update', FirmwareUpdateHandler),
|
(r'/api/firmware/update', FirmwareUpdateHandler),
|
||||||
(r'/api/upgrade', UpgradeHandler),
|
(r'/api/upgrade', UpgradeHandler),
|
||||||
(r'/api/file(/[^/]+)?', bbctrl.FileHandler),
|
(r'/api/file(/[^/]+)?', bbctrl.FileHandler),
|
||||||
(r'/api/macros/upload',MacrosUploadHandler),
|
|
||||||
(r'/api/path/([^/]+)((/positions)|(/speeds))?', PathHandler),
|
(r'/api/path/([^/]+)((/positions)|(/speeds))?', PathHandler),
|
||||||
(r'/api/home(/[xyzabcXYZABC]((/set)|(/clear))?)?', HomeHandler),
|
(r'/api/home(/[xyzabcXYZABC]((/set)|(/clear))?)?', HomeHandler),
|
||||||
(r'/api/start', StartHandler),
|
(r'/api/start', StartHandler),
|
||||||
|
|||||||
Reference in New Issue
Block a user