SlicerCaCertCard-sXxZPJUn.js 7.4 KB

1
  1. import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{A as t,E as n,T as r,p as i,w as a}from"./client-DJ2k8Bkd.js";import{n as o}from"./QueryClientProvider-NYoTmQud.js";import{t as s}from"./useQuery-CeIc68fT.js";import{t as c}from"./useMutation-XVnfRW5u.js";import{t as l}from"./check-B5nucgMH.js";import{n as u}from"./ToastContext-PXQkWm-m.js";import{t as d}from"./copy-UQ03FQV4.js";import{t as f}from"./download-Dmz4c59u.js";import{t as p}from"./eye-off-BMqX6p0W.js";import{t as m}from"./eye-CdzlZ5JD.js";import{t as h}from"./key-round-5Gk_E60m.js";import{t as g}from"./loader-circle-s_Jy23um.js";import{t as _}from"./refresh-cw-Ce-HgRMQ.js";import{n as v}from"./AuthContext-BGjptJyl.js";import{n as y,t as b}from"./Card-ToEWQYwA.js";import{t as x}from"./ConfirmModal-DtebArJX.js";var S=a(`shield-check`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),C=e(t(),1);async function w(e){if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{return t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.parentNode&&t.parentNode.removeChild(t)}}function T(e,t,n=`text/plain`){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}var E=r();function D(){let{t:e}=n(),{showToast:t}=u(),r=o(),{user:a,authEnabled:f}=v(),[S,T]=(0,C.useState)(!1),[D,O]=(0,C.useState)(!1),[k,A]=(0,C.useState)(!1),j=[`my-slicer-access-code`,a?.id??null],M=f&&!!a,{data:N,isLoading:P,isError:F}=s({queryKey:j,queryFn:i.getMyAccessCode,enabled:M,gcTime:0}),I=c({mutationFn:i.renewMyAccessCode,onSuccess:n=>{r.setQueryData(j,n),T(!0),t(e(`slicerAccessCode.renewed`))},onError:n=>t(n.message||e(`slicerAccessCode.loadFailed`),`error`)});if(!M)return null;let L=async()=>{N&&(await w(N.code)?(O(!0),setTimeout(()=>O(!1),2e3)):t(e(`slicerAccessCode.copyFailed`),`error`))},R=`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`;return(0,E.jsxs)(b,{children:[(0,E.jsx)(y,{className:`py-3 px-4`,children:(0,E.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,E.jsx)(h,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,E.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,E.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`slicerAccessCode.title`)}),P?(0,E.jsx)(g,{className:`w-4 h-4 animate-spin text-bambu-green`}):F||!N?(0,E.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:e(`slicerAccessCode.loadFailed`)}):(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,E.jsx)(`code`,{"data-testid":`slicer-access-code`,className:`font-mono text-sm tracking-[0.25em] text-white bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-2 py-0.5`,children:S?N.code:`•`.repeat(N.code.length)}),(0,E.jsx)(`button`,{onClick:()=>T(!S),"aria-label":e(S?`slicerAccessCode.hide`:`slicerAccessCode.show`),className:R,children:S?(0,E.jsx)(p,{className:`w-3.5 h-3.5`}):(0,E.jsx)(m,{className:`w-3.5 h-3.5`})}),(0,E.jsx)(`button`,{onClick:L,"aria-label":e(`slicerAccessCode.copy`),className:R,children:D?(0,E.jsx)(l,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,E.jsx)(d,{className:`w-3.5 h-3.5`})}),(0,E.jsxs)(`button`,{onClick:()=>A(!0),disabled:I.isPending,className:R,children:[I.isPending?(0,E.jsx)(g,{className:`w-3.5 h-3.5 animate-spin`}):(0,E.jsx)(_,{className:`w-3.5 h-3.5`}),e(`slicerAccessCode.renew`)]})]})]}),(0,E.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`slicerAccessCode.description`)}),(0,E.jsxs)(`ul`,{className:`text-xs text-bambu-gray list-disc pl-4 mt-1 space-y-0.5`,children:[(0,E.jsx)(`li`,{children:e(`slicerAccessCode.hintChecked`)}),(0,E.jsx)(`li`,{children:e(`slicerAccessCode.hintCamera`)}),(0,E.jsx)(`li`,{children:e(`slicerAccessCode.hintSecret`)})]})]})]})}),k&&(0,E.jsx)(x,{title:e(`slicerAccessCode.renewTitle`),message:e(`slicerAccessCode.renewConfirm`),confirmText:e(`slicerAccessCode.renew`),variant:`warning`,onConfirm:()=>{A(!1),I.mutate()},onCancel:()=>A(!1)})]})}var O=[[`windows`,`Windows`],[`unix`,`Linux / macOS`]];function k(){let{t:e}=n(),{showToast:t}=u(),{data:r}=s({queryKey:[`vp-ca-certificate`],queryFn:i.getCaCertificate,staleTime:1/0}),[a,o]=(0,C.useState)(!1),c=async()=>{r&&(await w(r.pem)?(o(!0),t(e(`virtualPrinter.caCert.copied`)),setTimeout(()=>o(!1),2e3)):t(e(`virtualPrinter.toast.copyFailed`),`error`))},p=()=>{r&&T(r.pem,`bambuddy-virtual-printer-ca.crt`,`application/x-pem-file`)},[m,h]=(0,C.useState)(null),_=async n=>{h(n);try{let e=await i.getCaCertificateInstaller(n);T(e.content,e.filename,`application/octet-stream`)}catch(n){t(n.message||e(`virtualPrinter.caCert.installerFailed`),`error`)}finally{h(null)}};return(0,E.jsx)(b,{children:(0,E.jsx)(y,{className:`py-3 px-4`,children:(0,E.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,E.jsx)(S,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,E.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.caCert.title`)}),(0,E.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,E.jsxs)(`button`,{onClick:c,disabled:!r,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[a?(0,E.jsx)(l,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,E.jsx)(d,{className:`w-3.5 h-3.5`}),e(a?`virtualPrinter.caCert.copied`:`virtualPrinter.caCert.copy`)]}),(0,E.jsxs)(`button`,{onClick:p,disabled:!r,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[(0,E.jsx)(f,{className:`w-3.5 h-3.5`}),e(`virtualPrinter.caCert.download`)]})]})]}),(0,E.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.caCert.description`)}),(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mt-2`,children:[(0,E.jsx)(`span`,{className:`text-xs text-white`,children:e(`virtualPrinter.caCert.installerTitle`)}),O.map(([e,t])=>(0,E.jsxs)(`button`,{onClick:()=>_(e),disabled:m!==null,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[m===e?(0,E.jsx)(g,{className:`w-3.5 h-3.5 animate-spin`}):(0,E.jsx)(f,{className:`w-3.5 h-3.5`}),t]},e))]}),(0,E.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.caCert.installerHint`)}),r&&(0,E.jsxs)(`p`,{className:`text-[10px] text-bambu-gray font-mono mt-1 truncate`,title:r.fingerprint_sha256,children:[e(`virtualPrinter.caCert.fingerprint`),`: `,r.fingerprint_sha256]})]})]})})})}export{S as i,D as n,w as r,k as t};