mirror of
https://github.com/silenty4ng/k5web
synced 2024-11-14 14:33:23 +00:00
2 lines
3.6 KiB
JavaScript
2 lines
3.6 KiB
JavaScript
import{m as A,ak as N,_ as V}from"./index.d41050dc.js";/* empty css *//* empty css *//* empty css *//* empty css *//* empty css */import{d as C,r as $,o as I,bT as O,bI as P,C as T,D as L,aI as s,aH as r,G as p,aM as _,aN as y,n as b,a$ as R,ba as S,bU as x,bG as D,bJ as H,bL as M}from"./arco.7f845a67.js";import{f as U}from"./vue.0bef8fc5.js";import{d as h,c as j,r as f,j as q,k as g,l as G,m as z,n as J}from"./serial.c6b76da8.js";import"./chart.3e6cb2f1.js";const W={class:"container"},K={style:{display:"flex","justify-content":"space-between","align-items":"center"}},Q=["innerHTML"],X={name:"Flash"},Y=C({...X,setup(Z){const m=A(),t=$({status:"\u70B9\u51FB\u66F4\u65B0\u6309\u94AE\u66F4\u65B0\u56FA\u4EF6\u5230\u8BBE\u5907<br/><br/>",binaryFile:void 0,binaryName:"",protocol:"Official"}),d=U();I(async()=>{var e;if(d.query.url){const o=await fetch(d.query.url),c=(e=o==null?void 0:o.body)==null?void 0:e.getReader();if(c){const n=[];for(;;){const{done:l,value:u}=await c.read();if(l)break;n.push(...u)}const a=new Uint8Array(n);t.binaryFile=a,t.binaryName=d.query.url.substring(d.query.url.lastIndexOf("/")+1).split("?")[0]+" "}}});const F=()=>{const e=document.createElement("input");e.type="file",e.onchange=async()=>{const o=new Blob([e.files[0]],{type:"application/octet-stream"}),c=new Uint8Array(await o.arrayBuffer());t.binaryFile=c,t.binaryName=e.files[0].name},e.click()},w=async()=>{if(!t.binaryFile){alert("\u8BF7\u9009\u62E9\u6587\u4EF6");return}m.connectPort&&await h(m.connectPort);let e=await j();await f(e,24,1e3);const o=q(t.binaryFile),c=new Uint8Array([48,5,o.length,0,...o]);t.protocol=="Official"&&(await g(e,c),await f(e,24));const n=G(t.binaryFile);if(n.length>61439)throw new Error("Last resort boundary check failed. Whoever touched the code is an idiot.");for(let a=0;a<n.length;a+=256){const l=n.slice(a,a+256),u=z(l,a,n.length);try{await g(e,u),t.protocol=="Official"?await f(e,26):await J(e)}catch(i){return console.log("Flash command rejected. Aborting."),Promise.reject(i)}t.status=t.status+`\u66F4\u65B0\u8FDB\u5EA6 ${(a/n.length*100).toFixed(1)}%<br/>`,b(()=>{const i=document==null?void 0:document.getElementById("statusArea");i&&(i.scrollTop=i==null?void 0:i.scrollHeight)})}t.status=t.status+"\u66F4\u65B0\u8FDB\u5EA6 100.0%<br/>",t.status=t.status+"\u56FA\u4EF6\u66F4\u65B0\u6210\u529F",b(()=>{const a=document==null?void 0:document.getElementById("statusArea");a&&(a.scrollTop=a==null?void 0:a.scrollHeight)}),h(e),m.updateSettings({connectState:!1})};return(e,o)=>{const c=N,n=R,a=S,l=O,u=x,i=D,B=P,v=H,k=M;return T(),L("div",W,[s(c,{items:[e.$t("menu.list"),e.$t("menu.flash")]},null,8,["items"]),s(k,{gutter:20,align:"stretch"},{default:r(()=>[s(v,{span:24},{default:r(()=>[s(B,{class:"general-card",title:e.$t("menu.flash")+e.$t("global.onBoot")},{default:r(()=>[p("div",K,[p("div",null,[s(a,null,{default:r(()=>[s(n,{onClick:F},{default:r(()=>[_(y(t.binaryFile?t.binaryName:e.$t("tool.selectFirmware")),1)]),_:1}),s(n,{type:"primary",disabled:!t.binaryFile,onClick:w},{default:r(()=>[_(y(e.$t("tool.flash")),1)]),_:1},8,["disabled"])]),_:1})]),p("div",null,[s(u,{type:"button",size:"mini",modelValue:t.protocol,"onUpdate:modelValue":o[0]||(o[0]=E=>t.protocol=E)},{default:r(()=>[s(l,{value:"Official"},{default:r(()=>[_("Official")]),_:1}),s(l,{value:"Losehu"},{default:r(()=>[_("Losehu")]),_:1})]),_:1},8,["modelValue"])])]),s(i),p("div",{id:"statusArea",style:{height:"20em","background-color":"azure",color:"silver",overflow:"auto",padding:"20px"},innerHTML:t.status},null,8,Q)]),_:1},8,["title"])]),_:1})]),_:1})])}}});const ue=V(Y,[["__scopeId","data-v-2ac2ce62"]]);export{ue as default};
|