Files
op-packages/luci-app-quickstart/htdocs/luci-static/quickstart/installClient.js
T

2 lines
3.5 KiB
JavaScript

var p=(m,b,s)=>new Promise((t,c)=>{var u=e=>{try{f(s.next(e))}catch(r){c(r)}},i=e=>{try{f(s.throw(e))}catch(r){c(r)}},f=e=>e.done?t(e.value):Promise.resolve(e.value).then(u,i);f((s=s.apply(m,b)).next())});import{o as y,q as E}from"./app.js?v=txJtMzYh";import"/luci-static/quickstart/card-runtime-v1.js";import"./vendor.js?v=B46K-l76";function v(m=fetch,b=y,s=t=>new Promise((c,u)=>{const i=()=>{clearTimeout(f),u(new DOMException("Aborted","AbortError"))},f=setTimeout(()=>{t==null||t.removeEventListener("abort",i),c()},3e3);t==null||t.addEventListener("abort",i,{once:!0}),t!=null&&t.aborted&&i()})){const t=(e,r)=>typeof window!="undefined"&&window.vue_lang==="en"?r:e,c=e=>{const r=E.find(n=>n.id===e);if(!r)throw Error("Unsupported card");return r.package};function u(e,r,n){return p(this,null,function*(){var l;const o=new AbortController,a=()=>o.abort(),w=setTimeout(a,8e3);n==null||n.addEventListener("abort",a,{once:!0}),n!=null&&n.aborted&&a();try{const d=yield m("/cgi-bin/luci/istore/app/"+e+"/",{method:"POST",credentials:"same-origin",redirect:"error",cache:"no-store",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:c(r)}),signal:o.signal});if(!d.ok||!((l=d.headers.get("Content-Type"))!=null&&l.includes("application/json")))throw Error([401,403].includes(d.status)?t("登录已失效或权限不足,请重新登录","Session expired or access denied. Sign in again."):t("无法读取安装状态,请稍后重试","Unable to read installation status. Try again."));const k=yield d.text();if(k.length>8192)throw Error("Invalid installation response");const h=JSON.parse(k);if(h.error||h.success!==void 0&&h.success!==0)throw Error(t("安装状态读取失败,请检查软件中心","Unable to confirm installation. Check the software center."));return h}finally{clearTimeout(w),n==null||n.removeEventListener("abort",a)}})}function i(e,r){return p(this,null,function*(){var a,w,l;const n=yield u("check",e,r),o=(a=n.result)==null?void 0:a.installation;return["idle","installing","completed","failed","unknown"].includes(o)?o==="installing"?"installing":o==="unknown"?"unknown":o==="failed"?"failed":((w=n.result)==null?void 0:w.status)==="uninstalled"?"uninstalled":((l=n.result)==null?void 0:l.status)!=="installed"?"unknown":(yield b.read(!0)).some(d=>d.id===e)?"ready":"update_required":"unknown"})}return{inspect:i,install(e,r){return p(this,null,function*(){const n=yield i(e,r);if(n!=="ready"){if(n==="unknown")throw Error(t("无法确认安装状态,请先在软件中心检查或升级 Quickstart","Installation status is unknown. Check the software center or update Quickstart."));if(n!=="installing")try{yield u("install",e,r)}catch(o){if(r!=null&&r.aborted)throw o}for(let o=0;o<60;o++){yield s(r);const a=yield i(e,r);if(a==="ready")return;if(a==="update_required")throw Error(t("插件已安装,但当前版本尚未提供可用卡片;请在软件中心升级或修复 FastNet","The installed version has no usable card. Update or repair FastNet in the software center."));if(a==="failed")throw Error(t("安装失败,请检查软件源后重试","Installation failed. Check the package source before retrying."));if(a==="unknown")throw Error(t("安装结果尚未确认,请先在软件中心检查","Installation is unconfirmed. Check the software center first."))}throw Error(t("安装结果尚未确认,请重新读取状态;后台安装可能仍在继续","Installation is unconfirmed. Reload its status; installation may still be running."))}})}}}const S=v();export{S as cardInstaller,v as createCardInstaller};