mirror of
https://github.com/luc-github/ESP3D-WEBUI.git
synced 2025-10-31 11:56:46 -07:00
Fix POST query
Allow upload on dev server on /public directory Add sample code for preferences.json upload if file does not exist
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"watch": ["src/server/"]
|
||||
"watch": ["src/server/"],
|
||||
"ignore": ["public/*"]
|
||||
}
|
||||
|
||||
78
package-lock.json
generated
78
package-lock.json
generated
@@ -743,9 +743,9 @@
|
||||
}
|
||||
},
|
||||
"@babel/plugin-transform-react-jsx": {
|
||||
"version": "7.9.1",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.9.1.tgz",
|
||||
"integrity": "sha512-+xIZ6fPoix7h57CNO/ZeYADchg1tFyX9NDsnmNFFua8e1JNPln156mzS+8AQe1On2X2GLlANHJWHIXbMCqWDkQ==",
|
||||
"version": "7.9.4",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.9.4.tgz",
|
||||
"integrity": "sha512-Mjqf3pZBNLt854CK0C/kRuXAnE6H/bo7xYojP+WGtX8glDGSibcwnsWwhwoSuRg0+EBnxPC1ouVnuetUIlPSAw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/helper-builder-react-jsx": "^7.9.0",
|
||||
@@ -942,14 +942,14 @@
|
||||
}
|
||||
},
|
||||
"@babel/preset-react": {
|
||||
"version": "7.9.1",
|
||||
"resolved": "https://registry.npmjs.org/@babel/preset-react/-/preset-react-7.9.1.tgz",
|
||||
"integrity": "sha512-aJBYF23MPj0RNdp/4bHnAP0NVqqZRr9kl0NAOP4nJCex6OYVio59+dnQzsAWFuogdLyeaKA1hmfUIVZkY5J+TQ==",
|
||||
"version": "7.9.4",
|
||||
"resolved": "https://registry.npmjs.org/@babel/preset-react/-/preset-react-7.9.4.tgz",
|
||||
"integrity": "sha512-AxylVB3FXeOTQXNXyiuAQJSvss62FEotbX2Pzx3K/7c+MKJMdSg6Ose6QYllkdCFA8EInCJVw7M/o5QbLuA4ZQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/helper-plugin-utils": "^7.8.3",
|
||||
"@babel/plugin-transform-react-display-name": "^7.8.3",
|
||||
"@babel/plugin-transform-react-jsx": "^7.9.1",
|
||||
"@babel/plugin-transform-react-jsx": "^7.9.4",
|
||||
"@babel/plugin-transform-react-jsx-development": "^7.9.0",
|
||||
"@babel/plugin-transform-react-jsx-self": "^7.9.0",
|
||||
"@babel/plugin-transform-react-jsx-source": "^7.9.0"
|
||||
@@ -2130,6 +2130,15 @@
|
||||
"integrity": "sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=",
|
||||
"dev": true
|
||||
},
|
||||
"busboy": {
|
||||
"version": "0.3.1",
|
||||
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.3.1.tgz",
|
||||
"integrity": "sha512-y7tTxhGKXcyBxRKAni+awqx8uqaJKrSFSNFSeRG5CsWNdmy2BIK+6VGWEW7TZnIO/533mtMEA4rOevQV815YJw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"dicer": "0.3.0"
|
||||
}
|
||||
},
|
||||
"bytes": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
|
||||
@@ -2340,14 +2349,12 @@
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
@@ -2362,20 +2369,17 @@
|
||||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
@@ -2492,8 +2496,7 @@
|
||||
"inherits": {
|
||||
"version": "2.0.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.5",
|
||||
@@ -2505,7 +2508,6 @@
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"number-is-nan": "^1.0.0"
|
||||
}
|
||||
@@ -2520,7 +2522,6 @@
|
||||
"version": "3.0.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
@@ -2528,14 +2529,12 @@
|
||||
"minimist": {
|
||||
"version": "1.2.5",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"minipass": {
|
||||
"version": "2.9.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"safe-buffer": "^5.1.2",
|
||||
"yallist": "^3.0.0"
|
||||
@@ -2554,7 +2553,6 @@
|
||||
"version": "0.5.3",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
@@ -2616,8 +2614,7 @@
|
||||
"npm-normalize-package-bin": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"npm-packlist": {
|
||||
"version": "1.4.8",
|
||||
@@ -2645,8 +2642,7 @@
|
||||
"number-is-nan": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true
|
||||
"dev": true
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
@@ -2658,7 +2654,6 @@
|
||||
"version": "1.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
@@ -2772,7 +2767,6 @@
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"code-point-at": "^1.0.0",
|
||||
"is-fullwidth-code-point": "^1.0.0",
|
||||
@@ -4179,6 +4173,15 @@
|
||||
"integrity": "sha512-ZIzRpLJrOj7jjP2miAtgqIfmzbxa4ZOr5jJc601zklsfEx9oTzmmj2nVpIPRpNlRTIh8lc1kyViIY7BWSGNmKw==",
|
||||
"dev": true
|
||||
},
|
||||
"dicer": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.3.0.tgz",
|
||||
"integrity": "sha512-MdceRRWqltEG2dZqO769g27N/3PXfcKl04VhYnBlo2YhH7zPi88VebsjTKclaOyiuMaGU72hTfw3VkUitGcVCA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"streamsearch": "0.1.2"
|
||||
}
|
||||
},
|
||||
"diffie-hellman": {
|
||||
"version": "5.0.3",
|
||||
"resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
|
||||
@@ -4700,6 +4703,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"express-fileupload": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-1.1.6.tgz",
|
||||
"integrity": "sha512-w24zPWT8DkoIxSVkbxYPo9hkTiLpCQQzNsLRTCnecBhfbYv+IkIC5uLw2MIUAxBZ+7UMmXPjGxlhzUXo4RcbZw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"busboy": "^0.3.1"
|
||||
}
|
||||
},
|
||||
"express-ws": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/express-ws/-/express-ws-4.0.0.tgz",
|
||||
@@ -10482,6 +10494,12 @@
|
||||
"integrity": "sha512-AiisoFqQ0vbGcZgQPY1cdP2I76glaVA/RauYR4G4thNFgkTqr90yXTo4LYX60Jl+sIlPNHHdGSwo01AvbKUSVQ==",
|
||||
"dev": true
|
||||
},
|
||||
"streamsearch": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
|
||||
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo=",
|
||||
"dev": true
|
||||
},
|
||||
"strict-uri-encode": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz",
|
||||
|
||||
@@ -48,7 +48,8 @@
|
||||
"express": "latest",
|
||||
"nodemon": "latest",
|
||||
"concurrently": "latest",
|
||||
"express-ws": "latest"
|
||||
"express-ws": "latest",
|
||||
"express-fileupload": "latest"
|
||||
},
|
||||
"dependencies": {
|
||||
"bootstrap": "latest",
|
||||
|
||||
@@ -22,11 +22,14 @@ import { h } from "preact"
|
||||
import "../stylesheets/application.scss"
|
||||
import { useEffect, useReducer } from "preact/hooks"
|
||||
import { Esp3dVersion } from "./version"
|
||||
import { SendGetHttp } from "./http"
|
||||
import { SendGetHttp, SendPostHttp } from "./http"
|
||||
import { setupWebSocket } from "./websocket"
|
||||
import { DialogPage } from "./dialog"
|
||||
import { setLang, T } from "./translations"
|
||||
let isPreferencesLoaded = false
|
||||
|
||||
const default_preferences = '{"language":"en"}'
|
||||
|
||||
/*
|
||||
* Hook variable for communication with UI
|
||||
*/
|
||||
@@ -65,6 +68,13 @@ function loadPreferencesSuccess(responseText) {
|
||||
* Load Firmware settings query error
|
||||
*/
|
||||
function loadPreferencesError(errorCode, responseText) {
|
||||
var blob = new Blob([default_preferences], { type: "application/json" })
|
||||
var file = new File([blob], "preferences.json")
|
||||
var formData = new FormData()
|
||||
var url = "/files"
|
||||
formData.append("path", "/")
|
||||
formData.append("myfile", file, "preferences.json")
|
||||
SendPostHttp(url, formData)
|
||||
globaldispatch({
|
||||
type: "FETCH_FW_ERROR",
|
||||
errorcode: errorCode,
|
||||
|
||||
@@ -91,6 +91,7 @@ function requestAuthentication() {
|
||||
* Go to next command in queries list
|
||||
*/
|
||||
function nextCommand() {
|
||||
console.log("pop " + httpCommandList[0].uri)
|
||||
httpCommandList.shift()
|
||||
isProcessingHttpCommand = false
|
||||
processCommands()
|
||||
@@ -176,8 +177,8 @@ function SendPostHttp(
|
||||
progressfn: progress_fn,
|
||||
id: cmd_id,
|
||||
}
|
||||
http_cmd_list.push(cmd)
|
||||
process_cmd()
|
||||
httpCommandList.push(cmd)
|
||||
processCommands()
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -185,7 +186,12 @@ function SendPostHttp(
|
||||
*/
|
||||
function processCommands() {
|
||||
if (httpCommandList.length > 0 && !isProcessingHttpCommand) {
|
||||
console.log("Processing command")
|
||||
console.log(
|
||||
"Processing " +
|
||||
httpCommandList[0].type +
|
||||
" command:" +
|
||||
httpCommandList[0].uri
|
||||
)
|
||||
if (
|
||||
httpCommandList[0].type == "GET" ||
|
||||
httpCommandList[0].type == "POST"
|
||||
@@ -218,17 +224,20 @@ function processCommands() {
|
||||
httpCommandList[0].progressfn,
|
||||
false
|
||||
)
|
||||
if (httpCommandList[0].type == "POST") {
|
||||
console.log("Post query")
|
||||
console.log(httpCommandList[0].data)
|
||||
}
|
||||
currentHttpCommand.send(
|
||||
httpCommandList[0].type == "POST"
|
||||
? httpCommandList[0].postdata
|
||||
? httpCommandList[0].data
|
||||
: null
|
||||
)
|
||||
} else {
|
||||
console.log("Unknow request")
|
||||
}
|
||||
} else {
|
||||
if (isProcessingHttpCommand) console.log("Busy, process ongoing")
|
||||
else console.log("Command list is empty")
|
||||
if (httpCommandList.length == 0) console.log("Command list is empty")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,13 @@ const express = require("express")
|
||||
const WebSocket = require("ws")
|
||||
var currentID = 0
|
||||
const app = express()
|
||||
const fileUpload = require("express-fileupload")
|
||||
let firstconnection = true
|
||||
app.use(express.static("dist"))
|
||||
app.use(
|
||||
express.static("dist"),
|
||||
fileUpload({ preserveExtension: true, debug: true })
|
||||
)
|
||||
|
||||
app.get("/command", function(req, res) {
|
||||
var url = req.originalUrl
|
||||
if (url.indexOf("ESP800") != -1) {
|
||||
@@ -31,6 +36,19 @@ app.get("/command", function(req, res) {
|
||||
}
|
||||
})
|
||||
|
||||
app.post("/files", function(req, res) {
|
||||
if (!req.files || Object.keys(req.files).length === 0) {
|
||||
return res.status(400).send("No files were uploaded.")
|
||||
}
|
||||
let myFile = req.files.myfile
|
||||
myFile.mv(__dirname + "/public/" + myFile.name, function(err) {
|
||||
if (err) return res.status(500).send(err)
|
||||
|
||||
res.send("File uploaded!")
|
||||
})
|
||||
console.log("POST CATCHED ")
|
||||
})
|
||||
|
||||
app.listen(process.env.PORT || 8080, () =>
|
||||
console.log(`Listening on port ${process.env.PORT || 8080}!`)
|
||||
)
|
||||
|
||||
@@ -1,33 +1 @@
|
||||
{
|
||||
"language": "zh_cn",
|
||||
"enable_camera": "false",
|
||||
"auto_load_camera": "false",
|
||||
"camera_address": "",
|
||||
"enable_DHT": "false",
|
||||
"enable_lock_UI": "false",
|
||||
"enable_ping": "true",
|
||||
"is_mixed_extruder": "false",
|
||||
"number_extruders": "1",
|
||||
"enable_bed": "false",
|
||||
"enable_fan": "false",
|
||||
"enable_control_panel": "true",
|
||||
"enable_grbl_probe_panel": "false",
|
||||
"enable_temperatures_panel": "true",
|
||||
"enable_extruder_panel": "true",
|
||||
"enable_grbl_panel": "true",
|
||||
"enable_files_panel": "true",
|
||||
"probemaxtravel": "40",
|
||||
"probefeedrate": "100",
|
||||
"probetouchplatethickness": "0.5",
|
||||
"interval_positions": "3",
|
||||
"interval_status": "3",
|
||||
"xy_feedrate": "1000",
|
||||
"z_feedrate": "100",
|
||||
"interval_temperatures": "3",
|
||||
"e_feedrate": "400",
|
||||
"e_distance": "5",
|
||||
"f_filters": "g;G;gco;GCO;gcode;GCODE",
|
||||
"enable_autoscroll": "true",
|
||||
"enable_verbose_mode": "true",
|
||||
"enable_commands_panel": "true"
|
||||
}
|
||||
{"language":"en"}
|
||||
@@ -10,6 +10,7 @@ module.exports = merge(environment, {
|
||||
open: true,
|
||||
proxy: {
|
||||
"/command": "http://localhost:8080",
|
||||
"/files": "http://localhost:8080",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user