Files
wt cf25e28c28
Rust verification / test (push) Successful in 4m10s
initial commit
2026-10-28 15:59:54 +07:00

2 lines
14 KiB
JavaScript

import{u as vt,a as _t,b as gt,r as j,v as kt,o as yt,I as X,d as x,w,j as l,e as g,$ as bt,B as D,M as wt,f as k,h as n,i as a,l as u,m as t,t as o,k as d,a4 as Y,n as $,F as V,E as B,p as h,q as Z,a5 as $t,D as tt,H as Ct,_ as zt,Q as At}from"./app-dvJP63FL.js";import{F as U}from"./Form-ZbAUhXmz.js";import{u as xt}from"./bus-ChE1sp8V.js";import{U as Mt}from"./index-BJsmINgd.js";import{Q as Ft}from"./qr-code-eSL1bq0j.js";import{c as H}from"./createLucideIcon-DsaEAGzP.js";import{C as v}from"./check-CPGWPXZa.js";import{X as et}from"./x-DQVIq0xP.js";import{a as St,C as Nt}from"./circle-x-AvUNZzwX.js";const qt=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],Et=H("file-text",qt);const Pt=[["path",{d:"M12 20h-1a2 2 0 0 1-2-2 2 2 0 0 1-2 2H6",key:"1528k5"}],["path",{d:"M13 8h7a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-7",key:"13ksps"}],["path",{d:"M5 16H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h1",key:"1n9rhb"}],["path",{d:"M6 4h1a2 2 0 0 1 2 2 2 2 0 0 1 2-2h1",key:"1mj8rg"}],["path",{d:"M9 6v12",key:"velyjx"}]],Tt=H("text-cursor-input",Pt);const Vt=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],Bt=H("triangle-alert",Vt),It={class:"title"},Ot={key:0},jt={class:"block is-size-7-mobile"},Dt={class:"mb-2"},Ut={class:"columns"},Ht={class:"column"},Lt={class:"block"},Rt={class:"card"},Qt={class:"card-content"},Jt={class:"media"},Wt={class:"media-left"},Kt={class:"image is-32x32"},Gt={class:"media-content"},Xt={class:"title is-5 has-text-grey"},Yt={class:"card-footer"},Zt={class:"block"},te={class:"card"},ee={class:"card-content"},se={class:"media"},le={class:"media-left"},ie={class:"image is-32x32"},oe={class:"media-content"},ne={class:"title is-5 has-text-grey"},ae={class:"card-footer"},re={class:"block"},ue={class:"card"},de={class:"card-content"},ce={class:"media"},pe={class:"media-left"},fe={class:"image is-32x32"},me={class:"media-content"},he={class:"title is-5 has-text-grey"},ve={class:"content"},_e={class:"card-footer"},ge={class:"title is-5"},ke={class:"block is-size-7-mobile"},ye={class:"table is-size-7-mobile is-fullwidth"},be={key:1},we={class:"block is-size-7-mobile"},$e={class:"mb-2"},Ce={class:"is-flex is-justify-content-space-between"},ze=["onClick","title"],Ae=["src"],xe={key:1,class:"is-flex-grow-1 has-ellipsis"},Me={key:2,class:"tags is-flex-wrap-nowrap"},Fe=["onClick","title"],Se=["onClick","title"],Ne={key:3,class:"has-nowrap"},qe={key:0,class:"has-text-success"},Ee={key:1,class:"has-text-danger"},Pe={class:"is-size-6 is-size-7-mobile"},Te={class:"is-family-primary has-text-grey"},Ve={key:0,class:"has-text-danger"},Be={key:1,class:"has-text-warning"},Ie={key:2},Oe={key:0,class:"mt-2 is-size-7 is-pulled-right"},je={key:1,class:"mt-2 is-size-7 is-pulled-right"},De={key:0,class:"control"},Ye={__name:"Import",setup(Ue){const{t:c}=vt(),L=wt("2fauth"),f=bt(),R=_t(),I=xt(),Q=gt(),M=g(null),q=g(null),E=g(null),C=g(null),P=g(null),F=j(new U({service:"",account:"",otp_type:"",icon:"",secret:"",algorithm:"",digits:null,counter:null,period:null})),z=j(new U({file:null,withSecret:!0})),y=j(new U({qrcode:null,withSecret:!0})),A=g(!1);c("label.qr_code"),c("label.plain_text");const r=g([]),m=g(!1),S=D(()=>r.value.filter(s=>s.imported==-1&&s.id>-2).length),J=D(()=>r.value.filter(s=>s.id===-1&&s.imported===-1).length),st=D(()=>r.value.filter(s=>s.imported===1).length);kt(A,s=>{s==!1&&M.value?.clearOTP()}),yt(()=>{I.migrationUri&&(O(I.migrationUri),I.migrationUri=null)});async function O(s,e=null){m.value=!0,await X.migrate(s,{returnError:!0}).then(_=>{_.data.forEach(T=>{T.imported=-1,r.value.push(T)}),K(),C.value=P.value=null}).catch(_=>{f.alert({text:c(_.response.data.message)}),e!=null&&_.response.status===422&&(e.clear(),e.errors.set(e.extractErrors(_.response)))}).finally(()=>{m.value=!1})}function lt(){confirm(c("confirmation.discard_duplicates"))&&(f.clear(),M.value?.clearOTP(),r.value=r.value.filter(s=>s.id!==-1))}function it(){confirm(c("confirmation.discard_all"))&&(f.clear(),M.value?.clearOTP(),r.value=[])}function ot(s){confirm(c("confirmation.discard"))&&r.value.splice(s,1)}async function nt(){for(let s=0;s<r.value.length;s++)r.value[s].imported==-1&&await W(s);Q.sortDefault()}async function W(s){F.fill(r.value[s]),await F.post("/api/v1/twofaccounts",{returnError:!0}).then(e=>{r.value[s].imported=1,r.value[s].id=e.data.id,delete e.data.secret,Q.items.push(e.data)}).catch(e=>{r.value[s].imported=0,r.value[s].id=0,r.value[s].errors=F.errors.flatten()})}function at(s){F.fill(r.value[s]),A.value=!0,At().then(()=>{M.value.show()})}function rt(){z.clear(),m.value=!0,z.file=q.value.files[0],z.upload("/api/v1/twofaccounts/migration",{returnError:!0}).then(s=>{s.data.forEach(e=>{e.imported=-1,r.value.push(e)}),K()}).catch(s=>{s.response.status===422?s.response.data.errors?.file==null&&f.alert({text:c("error.invalid_2fa_data")}):f.alert({text:s.response.data.message})}).finally(()=>{m.value=!1})}function ut(){y.clear(),m.value=!0,y.qrcode=E.value.files[0],y.upload("/api/v1/qrcode/decode",{returnError:!0}).then(s=>{O(s.data.data,y)}).catch(s=>{s.response.status===422?s.response.data.errors?.qrcode==null&&f.alert({text:c("error.invalid_2fa_data")}):f.alert({text:s.response.data.message})}).finally(()=>{m.value=!1})}function K(){f.success({text:c("notification.x_valid_accounts_found",{count:S.value})})}function dt(){P.value=null,C.value?O(C.value):P.value=c("validation.required",{attribute:"Direct input"})}return(s,e)=>{const _=k("FormFieldError"),T=k("RouterLink"),ct=k("ResponsiveWidthWrapper"),pt=k("Spinner"),ft=k("Modal"),G=k("NavigationButton"),mt=k("VueFooter"),ht=k("StackLayout");return n(),x(l(Mt),null,{default:w(({mode:b})=>[a(ht,null,{content:w(()=>[a(ct,null,{default:w(()=>[t("h1",It,o(s.$t("heading.import")),1),!l(m)&&l(r).length===0?(n(),u("div",Ot,[t("div",jt,[t("p",Dt,o(s.$t("message.import_legend")),1),t("p",null,o(s.$t("message.import_legend_afterpart")),1)]),t("div",Ut,[t("div",Ht,[t("div",Lt,[t("div",Rt,[t("div",Qt,[t("div",Jt,[t("div",Wt,[t("figure",Kt,[a(l(Ft),{class:$(["icon-size-2",b=="dark"?"has-text-grey-darker":"has-text-grey-lighter"])},null,8,["class"])])]),t("div",Gt,[t("p",Xt,o(s.$t("heading.qr_code")),1),t("p",{class:$(["subtitle is-6 mt-1 is-size-7-mobile",{"has-text-grey-dark":b=="dark"}])},o(s.$t("message.supported_formats_for_qrcode_upload")),3)])]),l(y).errors.any()?(n(!0),u(V,{key:0},B(l(y).errors.all(),(i,p)=>(n(),x(_,{key:p,error:l(y).errors.get(p),field:p},null,8,["error","field"]))),128)):d("",!0)]),t("footer",Yt,[a(T,{id:"btnCapture",to:{name:"capture"},class:"card-footer-item is-link"},{default:w(()=>[h(o(s.$t("link.scan")),1)]),_:1}),t("a",{role:"button",tabindex:"0",class:"card-footer-item is-relative is-link",onClick:e[0]||(e[0]=i=>l(E).click()),onKeyup:e[1]||(e[1]=Z(i=>l(E).click(),["enter"]))},[t("input",{inert:"",tabindex:"-1",class:"file-input",type:"file",accept:"image/*",onChange:ut,ref_key:"qrcodeInput",ref:E},null,544),h(" "+o(s.$t("label.upload")),1)],32)])])]),t("div",Zt,[t("div",te,[t("div",ee,[t("div",se,[t("div",le,[t("figure",ie,[a(l(Et),{class:$(["icon-size-2",b=="dark"?"has-text-grey-darker":"has-text-grey-lighter"])},null,8,["class"])])]),t("div",oe,[t("p",ne,o(s.$t("label.text_file")),1),t("p",{class:$(["subtitle is-6 mt-1 is-size-7-mobile",{"has-text-grey-dark":b=="dark"}])},o(s.$t("message.supported_formats_for_file_upload")),3)])]),l(z).errors.any()?(n(!0),u(V,{key:0},B(l(z).errors.all(),(i,p)=>(n(),x(_,{key:p,error:l(z).errors.get(p),field:p},null,8,["error","field"]))),128)):d("",!0)]),t("footer",ae,[t("a",{role:"button",tabindex:"0",class:"card-footer-item is-relative is-link",onClick:e[2]||(e[2]=i=>l(q).click()),onKeyup:e[3]||(e[3]=Z(i=>l(q).click(),["enter"]))},[t("input",{inert:"",tabindex:"-1",class:"file-input",type:"file",accept:"text/plain,application/json,text/csv,.2fas",onChange:rt,ref_key:"fileInput",ref:q},null,544),h(" "+o(s.$t("label.upload")),1)],32)])])]),t("div",re,[t("div",ue,[t("div",de,[t("div",ce,[t("div",pe,[t("figure",fe,[a(l(Tt),{class:$(["icon-size-2",b=="dark"?"has-text-grey-darker":"has-text-grey-lighter"])},null,8,["class"])])]),t("div",me,[t("p",he,o(s.$t("message.direct_input")),1),t("p",{class:$(["subtitle is-6 mt-1 is-size-7-mobile",{"has-text-grey-dark":b=="dark"}])},o(s.$t("message.expected_format_for_direct_input")),3)])]),t("div",ve,[a(l($t),{modelValue:l(C),"onUpdate:modelValue":e[4]||(e[4]=i=>tt(C)?C.value=i:null),errorMessage:l(P),fieldName:"payload",rows:"5",size:"is-small"},null,8,["modelValue","errorMessage"])])]),t("footer",_e,[t("a",{role:"button",tabindex:"0",class:"card-footer-item is-relative is-link",onClick:Ct(dt,["stop"])},o(s.$t("label.submit")),1)])])])])]),t("h2",ge,o(s.$t("heading.supported_migration_formats")),1),t("div",ke,[a(l(Bt),{class:"inline icon-size-1 has-text-warning-30"}),h(" "+o(s.$t("message.do_not_set_password_or_encryption")),1)]),t("table",ye,[e[34]||(e[34]=t("thead",null,[t("tr",null,[t("th"),t("th",null,"Plain text"),t("th",null,"QR code"),t("th",null,"JSON")])],-1)),t("tbody",null,[t("tr",null,[e[14]||(e[14]=t("th",null,"Google Authenticator",-1)),e[15]||(e[15]=t("td",null,null,-1)),t("td",null,[a(l(v),{"stroke-width":"3",class:"icon-size-1"})]),e[16]||(e[16]=t("td",null,null,-1))]),t("tr",null,[e[17]||(e[17]=t("th",null,"Aegis Auth",-1)),t("td",null,[a(l(v),{"stroke-width":"3",class:"icon-size-1"})]),e[18]||(e[18]=t("td",null,null,-1)),t("td",null,[a(l(v),{"stroke-width":"3",class:"icon-size-1"})])]),t("tr",null,[e[19]||(e[19]=t("th",null,"2FAS auth",-1)),e[20]||(e[20]=t("td",null,null,-1)),e[21]||(e[21]=t("td",null,null,-1)),t("td",null,[a(l(v),{"stroke-width":"3",class:"icon-size-1"})])]),t("tr",null,[e[22]||(e[22]=t("th",null,"FreeOTP+",-1)),t("td",null,[a(l(v),{"stroke-width":"3",class:"icon-size-1"})]),e[23]||(e[23]=t("td",null,null,-1)),e[24]||(e[24]=t("td",null,null,-1))]),t("tr",null,[e[25]||(e[25]=t("th",null,"2FAuth",-1)),e[26]||(e[26]=t("td",null,null,-1)),e[27]||(e[27]=t("td",null,null,-1)),t("td",null,[a(l(v),{"stroke-width":"3",class:"icon-size-1"})])]),t("tr",null,[e[28]||(e[28]=t("th",null,"Bitwarden",-1)),e[29]||(e[29]=t("td",null,null,-1)),e[30]||(e[30]=t("td",null,null,-1)),t("td",null,[a(l(v),{"stroke-width":"3",class:"icon-size-1"})])]),t("tr",null,[e[31]||(e[31]=t("th",null,"Bitwarden Authenticator",-1)),e[32]||(e[32]=t("td",null,null,-1)),e[33]||(e[33]=t("td",null,null,-1)),t("td",null,[a(l(v),{"stroke-width":"3",class:"icon-size-1"})])])])])])):l(m)?d("",!0):(n(),u("div",be,[t("div",we,[t("p",$e,o(s.$t("message.submitted_data_parsed_now_accounts_are_awaiting_import")),1),t("p",null,o(s.$t("message.use_buttons_to_save_or_discard")),1)]),(n(!0),u(V,null,B(l(r),(i,p)=>(n(),u("div",{key:i.name,class:"group-item is-size-5 is-size-6-mobile"},[t("div",Ce,[i.id>-2&&i.imported!==0?(n(),u("div",{key:0,class:"is-flex-grow-1 has-ellipsis is-clickable",onClick:N=>at(p),title:s.$t("tooltip.generate_a_test_password")},[i.icon&&l(R).preferences.showAccountsIcons?(n(),u("img",{key:0,role:"presentation",class:"import-icon",src:l(L).config.subdirectory+"/storage/icons/"+i.icon,alt:""},null,8,Ae)):d("",!0),h(" "+o(i.account),1)],8,ze)):(n(),u("div",xe,o(i.account),1)),i.imported===-1?(n(),u("div",Me,[i.id>-2?(n(),u("button",{key:0,type:"button",class:"button tag is-link",onClick:N=>W(p),title:s.$t("tooltip.import_this_account")},o(s.$t("label.to_import")),9,Fe)):d("",!0),t("button",{type:"button",class:$(["button tag",{"is-dark has-text-grey-light":b=="dark"}]),onClick:N=>ot(p),title:s.$t("tooltip.discard_this_account")},[a(l(et),{class:"icon-size-1"})],10,Se)])):(n(),u("div",Ne,[i.imported===1?(n(),u("span",qe,[h(o(s.$t("message.imported"))+" ",1),a(l(v),{class:"inline"})])):(n(),u("span",Ee,[h(o(s.$t("message.failure"))+" ",1),a(l(et),{class:"inline"})]))]))]),t("div",Pe,[t("div",Te,o(s.$t("label.issuer"))+": "+o(i.service),1),i.id===-2?(n(),u("div",Ve,[a(l(St),{class:"mr-1 icon-size-1 inline"}),h(o(i.secret),1)])):d("",!0),i.id===-1&&i.imported!==1&&!i.errors?(n(),u("div",Be,[a(l(Nt),{class:"mr-1 icon-size-1 inline"}),h(o(s.$t("message.possible_duplicate")),1)])):d("",!0),i.errors?(n(),u("ul",Ie,[(n(!0),u(V,null,B(i.errors,N=>(n(),u("li",{key:N,class:"has-text-danger"},o(N),1))),128))])):d("",!0)])]))),128)),l(S)>0?(n(),u("div",Oe,[l(J)?(n(),u("button",{key:0,onClick:e[5]||(e[5]=i=>lt()),type:"button",class:"has-text-grey button is-small is-ghost"},o(s.$t("label.discard_duplicates"))+" ("+o(l(J))+")",1)):d("",!0),t("button",{onClick:e[6]||(e[6]=i=>it()),type:"button",class:"has-text-grey button is-small is-ghost"},o(s.$t("label.discard_all")),1)])):d("",!0),l(st)==l(r).length?(n(),u("div",je,[t("button",{onClick:e[7]||(e[7]=i=>r.value=[]),type:"button",class:"has-text-grey button is-small is-ghost"},o(s.$t("label.clear")),1)])):d("",!0)]))]),_:2},1024),l(m)&&l(r).length===0?(n(),x(pt,{key:0,type:"fullscreen-overlay",isVisible:!0,message:"message.parsing_data"})):d("",!0),a(ft,{"is-active":l(A),"onUpdate:isActive":e[11]||(e[11]=i=>tt(A)?A.value=i:null)},{default:w(()=>[a(l(zt),{ref_key:"otpDisplay",ref:M,accountParams:l(F).data(),preferences:l(R).preferences,twofaccountService:l(X),iconPathPrefix:l(L).config.subdirectory,onPleaseCloseMe:e[8]||(e[8]=i=>A.value=!1),onOtpCopiedToClipboard:e[9]||(e[9]=i=>l(f).success({text:l(c)("notification.copied_to_clipboard")})),onError:e[10]||(e[10]=i=>s.errorHandler.show(i))},null,8,["accountParams","preferences","twofaccountService","iconPathPrefix"])]),_:1},8,["is-active"])]),footer:w(()=>[a(mt,null,{default:w(()=>[l(S)>0?(n(),u("p",De,[t("button",{type:"button",class:"button is-link is-rounded is-focus",onClick:nt},[t("span",null,o(s.$t("label.import_all"))+" ("+o(l(S))+")",1)])])):d("",!0),l(S)>0?(n(),x(G,{key:1,action:"cancel",onCanceled:e[12]||(e[12]=i=>("router"in s?s.router:l(Y)).push({name:"accounts"}))})):(n(),x(G,{key:2,action:"close",onClosed:e[13]||(e[13]=i=>("router"in s?s.router:l(Y)).push({name:"accounts"})),"current-page-title":s.$t("title.importAccounts")},null,8,["current-page-title"]))]),_:1})]),_:2},1024)]),_:1})}}};export{Ye as default};