Browse Source

OTA Update and OTA filesystem navigator and uploader

(This is a huge update if you don't get it)
Emil 3 năm trước cách đây
mục cha
commit
b8950e16ed
2 tập tin đã thay đổi với 93 bổ sung3 xóa
  1. 80 1
      js/spotlight.js
  2. 13 2
      spotlights.html

+ 80 - 1
js/spotlight.js

@@ -226,8 +226,87 @@ function topBarClick(id) {
 
 
 function resetESP() {
-    sendWebRequest("http://192.168.1.170/reset", "", "POST")
+    sendWebRequest("http://192.168.1.170/admin/reset", "", "POST")
 }
 
 
+function updateFirmware() {
+    if (getEByID("updateFirmwareInput").files.length > 0) {
+        const file = getEByID("updateFirmwareInput").files[0]
+        let formData = new FormData();
+        formData.set('update', file);
+        fetch("http://192.168.1.170/admin/doUpdate", {
+            method: "POST",
+            body: formData
+        })
+    }
+}
+
+
+function uploadFile() {
+    if (getEByID("fileUpload").files.length > 0) {
+        const file = getEByID("fileUpload").files[0]
+        let formData = new FormData();
+        formData.set('data', file);
+        fetch("http://192.168.1.170/admin/upload_file", {
+            method: "POST",
+            body: formData
+        }).then(_ => {
+            getEByID("fileUpload").value = ""
+            listESPFiles()
+        })
+    }
+}
+
+function listESPFiles() {
+    const xmlhttp = new XMLHttpRequest()
+    xmlhttp.open("GET", "/admin/listfiles", false)
+    xmlhttp.send()
+    document.getElementById("fileListerDiv").innerHTML = xmlhttp.responseText
+}
+
+async function reloadFiles1Sec() {
+    await new Promise(r => setTimeout(r, 1000));
+    listESPFiles()
+}
+
+function deleteFile(file) {
+    fetch("http://192.168.1.170/admin/del_file", {
+        method: 'POST',
+        headers: new Headers({'name': file}),
+    }).then(_ => {
+        listESPFiles()
+    })
+}
+
+async function setSDCursor() {
+    let location = getEByID("cursorSet").value
+    console.log(location)
+    if (location === "/js" || location === "/css" || location === "/" || true) {
+        fetch("http://192.168.1.170/admin/set_sd_cursor", {
+            method: 'POST',
+            headers: new Headers({'value': location}),
+        })
+    }
+    reloadFiles1Sec()
+}
+
+function openDirectory(path) {
+    getEByID("cursorSet").value = path
+    setSDCursor()
+}
+
+function getCursorValue() {
+    fetch("http://192.168.1.170/admin/get_sd_cursor", {
+        method: 'GET',
+    }).then(res => res.text().then(t => {
+        console.log(t)
+        getEByID("cursorSet").value = t
+        })
+    )
+}
+
+listESPFiles()
+getCursorValue()
+
 updateConfig()

+ 13 - 2
spotlights.html

@@ -76,10 +76,21 @@
 
     <div id="spotlightAdminContainer" class="hidden">
         <h2>Uppdatera firmware</h2>
-        <form method='POST' action='/doUpdate' enctype='multipart/form-data'><input type='file' name='update'><input type='submit' value='Update'></form>
+        <!--<form method='POST' action='/admin/doUpdate' enctype='multipart/form-data'><input type='file' name='update'><input type='submit' value='Update'></form>-->
+        <input type="file" id="updateFirmwareInput"/><button onclick="updateFirmware()">Update</button>
         <h2>Uppdatera SD-kort</h2>
-        <p>Placeholder</p>
+        <!--<form method="POST" action="/admin/upload_file" enctype="multipart/form-data"><input type="file" name="data"/><input type="submit" name="upload" value="Upload" title="Upload File"></form>-->
+        <input type="file" id="fileUpload"/><button onclick="uploadFile()">Upload</button>
         <button onclick="resetESP()">Reset ESP</button>
+
+        <h2>Set SD Cursor</h2>
+        <input type='text' id="cursorSet">
+        <button onclick="setSDCursor()">Send cursor value</button>
+
+        <h2>Files</h2>
+        <div id="fileListerDiv"></div>
+        <button onclick="listESPFiles()">Reload list</button>
+        <button onclick="openDirectory('/')">Back to /</button>
     </div>
 
     <script src="js/spotlight.js"></script>