-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.h
14 lines (11 loc) · 4.42 KB
/
upload.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// file: upload.h
// contains the minimal html for uploading files
// minimized from setup.htm: configure the network
static const char setupContent[] PROGMEM =
R"==(<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport"content="width=device-width,initial-scale=1"><title>Setup WiFi</title></head><body style="width:300px"><h1>Setup WiFi</h1><div style="display:grid;grid-template-columns:10ch auto;grid-gap:1ch"><label>Devicename:</label><span id="d">.</span> <label>Network:</label><span><select id="n"style="width:12em"><option selected="selected"disabled="disabled">scanning...</option></select></span><label>Passphrase:</label><input id="pass"type="password"style="width:12em"><label>format:</label><span><input id="fmt"type="checkbox"></span></div><div style="text-align:right"><button id="b">Connect</button></div><script>var timer,dn,d=document,s=0,oSel=d.getElementById("n"),oBtn=d.getElementById("b");async function check(){let e,t;0==s?(s=1,e=await fetch("/api/sysinfo"),t=await e.text(),t.length>0&&(dn=JSON.parse(t).devicename,d.getElementById("d").textContent=dn,s=2)):2==s?(s=3,e=await fetch("/api/scan"),t=await e.text(),0==t.length?s=2:(scanned(JSON.parse(t)),s=4)):4==s&&(window.clearInterval(timer),timer=0)}function scanned(e){oSel.innerHTML="";var t=d.createElement("option");t.value=0,t.text="select...",t.disabled=!0,oSel.options.add(t),e.forEach((function(e){var t=d.createElement("option");t.value=t.text=e.id,oSel.options.add(t)}))}oBtn.addEventListener("click",(async()=>{if(4==s){let e=`/api/connect?n=${oSel.value}&p=${d.getElementById("pass").value}`;d.getElementById("fmt").checked&&(e+="f=1");try{await fetch(e)}catch(e){}s=5,oBtn.textContent=">>>"}else 5==s&&(location.href=`//${dn}/$update.htm`)})),timer=window.setInterval(check,300)</script></body></html>)==";
// minimized from upload.htm
static const char uploadContent[] PROGMEM =
R"==(<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport"content="width=device-width,initial-scale=1"><title>Upload</title></head><body style="width:300px"><h1>Upload</h1><div id="zone"style="width:260px;height:5em;padding:20px;background-color:#ddd">Drop here</div><a href="#i">I-Upload</a><hr><p style="text-align:right"><a href="/microide.htm">>>></a></p><script>function dragHelper(e){e.stopPropagation(),e.preventDefault()}function dropped(e){dragHelper(e);for(var n=e.dataTransfer.files,r=new FormData,t="/"+(location.hash?location.hash.substring(1)+"/":""),a=0;a<n.length;a++)r.append("file",n[a],t+n[a].name);fetch("/",{method:"POST",body:r}).then((function(){window.alert("done.")}))}var zoneObj=document.getElementById("zone");zoneObj.addEventListener("dragenter",dragHelper,!1),zoneObj.addEventListener("dragover",dragHelper,!1),zoneObj.addEventListener("drop",dropped,!1)</script></body></html>)==";
// minimized from boot.htm
static const char updateContent[] PROGMEM =
R"==(<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport"content="width=device-width,initial-scale=1"><title>Web Update</title></head><body style="width:300px"><h1>Web Update</h1><div style="display:grid"><progress value="0"max="20"></progress><span id="l"style="height:2rem"></span></div><div style="text-align:right"><button>Start</button></div><script>var w,si,r,d=document,s=0,repo="https://homeding.github.io/",eBar=d.querySelector("progress"),oBtn=d.querySelector("button"),x=0,a=0,t=0,seed="?"+(new Date).valueOf();function log(e){d.querySelector("#l").innerText=e}async function doF(){var e=w.shift();if(log(e),"-"!==e[0]){r=await fetch(repo+e+seed),r=await r.arrayBuffer();var t=new FormData;t.append("file",new Blob([r]),"/"+e),await fetch("/",{method:"POST",body:t})}}location.hash?repo+=location.hash.substring(1)+"/":repo+="v09/",log("loading from:\n"+repo),d.querySelector("button").addEventListener("click",(()=>{0===s?(oBtn.textContent="-",t=window.setInterval((async function(){a||(a=1,0==s?(log("sysinfo..."),r=await fetch("/api/sysinfo"+seed),si=await r.text()):1==s?(log("list..."),(si=JSON.parse(si)).fsTotalBytes<2e5&&(repo=repo.replace(/(v\d+)\/$/,"$1m/")),r=await fetch(repo+"list.txt"+seed),r=await r.text(),w=r.replace(/\r?\n/g,";").replace(/;$/,"").split(";"),eBar.max=w.length+3):2==s?(log("clean..."),await fetch("/api/cleanweb")):3==s?w.length>0&&(await doF(),s--):4==s&&(window.clearInterval(t),log("done"),oBtn.textContent=">>>"),eBar.value=++x,s++,a=0)}),100)):5===s&&(location.href="/updateicons.htm")}))</script></body></html>)==";