k5web/assets/index.21ba7545.js
2024-07-02 10:58:02 +08:00

2 lines
3.7 KiB
JavaScript

import{m as A,ak as N,_ as V}from"./index.84328ebd.js";/* empty css *//* empty css *//* empty css *//* empty css *//* empty css */import{d as C,r as O,o as $,bT as I,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.95d38b48.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(),e=O({status:"\u70B9\u51FB\u66F4\u65B0\u6309\u94AE\u66F4\u65B0\u56FA\u4EF6\u5230\u8BBE\u5907<br/><br/>",binaryFile:void 0,binaryName:"",protocol:"Official"}),d=U();$(async()=>{var t;if(d.query.url){const o=await fetch(d.query.url),l=(t=o==null?void 0:o.body)==null?void 0:t.getReader();if(l){const n=[];for(;;){const{done:c,value:u}=await l.read();if(c)break;n.push(...u)}const a=new Uint8Array(n);e.binaryFile=a,e.binaryName=d.query.url.substring(d.query.url.lastIndexOf("/")+1).split("?")[0]+" "}}});const F=()=>{const t=document.createElement("input");t.type="file",t.onchange=async()=>{const o=new Blob([t.files[0]],{type:"application/octet-stream"}),l=new Uint8Array(await o.arrayBuffer());e.binaryFile=l,e.binaryName=t.files[0].name},t.click()},w=async()=>{if(!e.binaryFile){alert("\u8BF7\u9009\u62E9\u6587\u4EF6");return}m.connectPort&&await h(m.connectPort);let t=await j();e.protocol=="Official"&&await f(t,24,1e3);const o=q(e.binaryFile),l=new Uint8Array([48,5,o.length,0,...o]);e.protocol=="Official"&&(await g(t,l),await f(t,24));const n=G(e.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 g(t,u),e.protocol=="Official"?await f(t,26):await J(t)}catch(i){return console.log("Flash command rejected. Aborting."),Promise.reject(i)}e.status=e.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)})}e.status=e.status+"\u66F4\u65B0\u8FDB\u5EA6 100.0%<br/>",e.status=e.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(t),m.updateSettings({connectState:!1})};return(t,o)=>{const l=N,n=R,a=S,c=I,u=x,i=D,B=P,v=H,k=M;return T(),L("div",W,[s(l,{items:[t.$t("menu.list"),t.$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:t.$t("menu.flash")+t.$t("global.onBoot")},{default:r(()=>[p("div",K,[p("div",null,[s(a,null,{default:r(()=>[s(n,{onClick:F},{default:r(()=>[_(y(e.binaryFile?e.binaryName:t.$t("tool.selectFirmware")),1)]),_:1}),s(n,{type:"primary",disabled:!e.binaryFile,onClick:w},{default:r(()=>[_(y(t.$t("tool.flash")),1)]),_:1},8,["disabled"])]),_:1})]),p("div",null,[s(u,{type:"button",size:"mini",modelValue:e.protocol,"onUpdate:modelValue":o[0]||(o[0]=E=>e.protocol=E)},{default:r(()=>[s(c,{value:"Official"},{default:r(()=>[_("Official")]),_:1}),s(c,{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:e.status},null,8,Q)]),_:1},8,["title"])]),_:1})]),_:1})])}}});const ut=V(Y,[["__scopeId","data-v-7a197c45"]]);export{ut as default};