written xml request func

This commit is contained in:
sanjayk03-dev
2024-01-12 02:10:49 +05:30
parent be14b3b202
commit ac3e744787
2 changed files with 43 additions and 33 deletions

View File

@@ -43,7 +43,6 @@ module.exports = {
utils.clickFileInput("gcode-file-input"); utils.clickFileInput("gcode-file-input");
}, },
load: function () { load: function () {
const file_time = this.state.selected_time;
const file = this.state.selected; const file = this.state.selected;
this.$broadcast("gcode-load", file); this.$broadcast("gcode-load", file);
this.$broadcast("gcode-line", this.state.line); this.$broadcast("gcode-line", this.state.line);
@@ -77,6 +76,34 @@ module.exports = {
}, },
}); });
}, },
uploadGCode: function (filename,file) {
const xhr = new XMLHttpRequest();
console.log(xhr);
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 300) {
console.log("File uploaded successfully");
} else {
console.error("File upload failed:", xhr.statusText);
}
};
xhr.onerror = function () {
console.error("Network error during file upload");
};
xhr.upload.onprogress = function (event) {
if (event.lengthComputable) {
const progress = (event.loaded / event.total) * 100;
console.log("Upload progress:", progress);
}
};
xhr.open("PUT", `/api/file/${encodeURIComponent(filename)}`, true);
xhr.send(file);
},
saveMacros: async function () { saveMacros: async function () {
var macrosName = document.getElementById( var macrosName = document.getElementById(
`macros-name-${this.tab - 1}` `macros-name-${this.tab - 1}`
@@ -85,28 +112,16 @@ module.exports = {
`macros-color-${this.tab - 1}` `macros-color-${this.tab - 1}`
).value; ).value;
console.log(this.newGcode[this.tab-1]); if (this.state.selected == "default") {
var file = this.newGcode[this.tab - 1];
if(this.state.selected =='default'){ this.uploadGCode(macrosName,file);
const file = this.newGcode[this.tab-1];
SvelteComponents.showDialog("Upload", {
file,
onComplete: () => {
this.last_file_time = macrosName;
// this.$broadcast("gcode-reload", file.name);
},
});
} }
console.log(this.tab-1);
this.config.macros[this.tab - 1].name = macrosName; this.config.macros[this.tab - 1].name = macrosName;
console.log(this.config.macros[this.tab-1].name);
this.config.macros[this.tab - 1].color = macrosColor; this.config.macros[this.tab - 1].color = macrosColor;
this.config.macros[this.tab - 1].gcode_file_name = file.name; this.config.macros[this.tab - 1].gcode_file_name = file.name;
this.config.macros[this.tab - 1].gcode_file_time = this.config.macros[this.tab - 1].gcode_file_time =
this.state.selected_time; this.state.selected_time;
console.log(this.config.macros);
this.cancelMacros(this.tab - 1); this.cancelMacros(this.tab - 1);
this.confirmSave = false; this.confirmSave = false;
try { try {

View File

@@ -39,8 +39,6 @@
} }
}; };
console.log(xhr);
xhr.upload.onerror = () => { xhr.upload.onerror = () => {
open = false; open = false;
alert("Upload failed."); alert("Upload failed.");
@@ -54,9 +52,6 @@
progress = event.loaded / event.total; progress = event.loaded / event.total;
}; };
console.log(file);
console.log(file.name);
xhr.open("PUT", `/api/file/${encodeURIComponent(file.name)}`); xhr.open("PUT", `/api/file/${encodeURIComponent(file.name)}`);
xhr.send(file); xhr.send(file);
} }