mirror of
https://github.com/silenty4ng/k5web
synced 2024-11-14 22:35:31 +00:00
2 lines
3.7 KiB
JavaScript
2 lines
3.7 KiB
JavaScript
import{m as A,ak as N,_ as V}from"./index.e1698f3e.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 l,G as p,aM as _,aN as b,n as h,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 w,c as j,r as m,j as q,k as y,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 f=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),i=(e=o==null?void 0:o.body)==null?void 0:e.getReader();if(i){const n=[];for(;;){const{done:c,value:u}=await i.read();if(c)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 g=()=>{const e=document.createElement("input");e.type="file",e.onchange=async()=>{const o=new Blob([e.files[0]],{type:"application/octet-stream"}),i=new Uint8Array(await o.arrayBuffer());t.binaryFile=i,t.binaryName=e.files[0].name},e.click()},F=async()=>{if(!t.binaryFile){alert("\u8BF7\u9009\u62E9\u6587\u4EF6");return}f.connectPort&&await w(f.connectPort);let e=await j();await m(e,24,1e3);const o=q(t.binaryFile),i=new Uint8Array([48,5,o.length,0,...o]);await y(e,i),await m(e,24),t.protocol=="Official"&&(await y(e,i),await m(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 c=n.slice(a,a+256),u=z(c,a,n.length);try{await y(e,u),t.protocol=="Official"?await m(e,26):await J(e)}catch(r){return console.log("Flash command rejected. Aborting."),Promise.reject(r)}t.status=t.status+`\u66F4\u65B0\u8FDB\u5EA6 ${(a/n.length*100).toFixed(1)}%<br/>`,h(()=>{const r=document==null?void 0:document.getElementById("statusArea");r&&(r.scrollTop=r==null?void 0:r.scrollHeight)})}t.status=t.status+"\u66F4\u65B0\u8FDB\u5EA6 100.0%<br/>",t.status=t.status+"\u56FA\u4EF6\u66F4\u65B0\u6210\u529F",h(()=>{const a=document==null?void 0:document.getElementById("statusArea");a&&(a.scrollTop=a==null?void 0:a.scrollHeight)}),w(e),f.updateSettings({connectState:!1})};return(e,o)=>{const i=N,n=R,a=S,c=O,u=x,r=D,B=P,v=H,k=M;return T(),L("div",W,[s(i,{items:[e.$t("menu.list"),e.$t("menu.flash")]},null,8,["items"]),s(k,{gutter:20,align:"stretch"},{default:l(()=>[s(v,{span:24},{default:l(()=>[s(B,{class:"general-card",title:e.$t("menu.flash")+e.$t("global.onBoot")},{default:l(()=>[p("div",K,[p("div",null,[s(a,null,{default:l(()=>[s(n,{onClick:g},{default:l(()=>[_(b(t.binaryFile?t.binaryName:e.$t("tool.selectFirmware")),1)]),_:1}),s(n,{type:"primary",disabled:!t.binaryFile,onClick:F},{default:l(()=>[_(b(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:l(()=>[s(c,{value:"Official"},{default:l(()=>[_("Official")]),_:1}),s(c,{value:"Losehu"},{default:l(()=>[_("Losehu")]),_:1})]),_:1},8,["modelValue"])])]),s(r),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-ca233ee4"]]);export{ue as default};
|