2FAuth/public/build/assets/Import-6ebcd5b1.js

2 lines
11 KiB
JavaScript
Raw Normal View History

2024-02-23 15:31:08 +01:00
import{Q as nt,b as lt,a as rt,c as ct,r as k,d as q,I as f,v as V,x as ut,o as dt,K as ft,e as h,f as n,g as r,m as c,p as v,i as a,E as pt,h as e,t as i,U as E,n as B,k as M,l as d,j as p,w as R,F as L,G as j,V as _t,P as mt}from"./app-06176200.js";import{F as T}from"./Form-87bc0477.js";import{_ as ht}from"./OtpDisplay-6b6605f3.js";import{S as vt}from"./Spinner-1a29b2e3.js";import{u as gt}from"./bus-01c5df37.js";/*! 2FAuth version 5.0.4 - Copyright (c) 2023 Bubka - https://github.com/Bubka/2FAuth */const wt={class:"title has-text-grey-dark"},kt={key:0},yt={class:"block is-size-7-mobile"},bt={class:"mb-2"},$t={class:"columns"},Ct={class:"column"},At={class:"block"},xt={class:"card"},Ft={class:"card-content"},zt={class:"media"},St={class:"media-left"},qt={class:"image is-32x32"},Vt={class:"media-content"},Et=["innerHTML"],Bt={class:"subtitle is-6 is-size-7-mobile"},Tt={class:"card-footer"},Nt={class:"block"},Ot={class:"card"},Pt={class:"card-content"},Ut={class:"media"},It={class:"media-left"},Mt={class:"image is-32x32"},Rt={class:"media-content"},Lt={class:"title is-5 has-text-grey"},jt={class:"subtitle is-6 is-size-7-mobile"},Dt={class:"card-footer"},Jt={class:"title is-5 has-text-grey-dark"},Kt={class:"block is-size-7-mobile"},Wt={class:"table is-size-7-mobile is-fullwidth"},Gt=e("thead",null,[e("tr",null,[e("th"),e("th",null,"Plain text"),e("th",null,"QR code"),e("th",null,"JSON")])],-1),Ht=e("th",null,"Google Authenticator",-1),Qt=e("td",null,null,-1),Xt=e("td",null,null,-1),Yt=e("th",null,"Aegis Auth",-1),Zt=e("td",null,null,-1),te=e("th",null,"2FAS auth",-1),ee=e("td",null,null,-1),se=e("td",null,null,-1),oe=e("th",null,"2FAuth",-1),ie=e("td",null,null,-1),ae=e("td",null,null,-1),ne={key:1},le={key:2},re={class:"block is-size-7-mobile"},ce={class:"mb-2"},ue={class:"is-flex is-justify-content-space-between"},de=["onClick","title"],fe=["src","alt"],pe={key:1,class:"is-flex-grow-1 has-ellipsis"},_e={key:2,class:"tags is-flex-wrap-nowrap"},me=["onClick","title"],he=["onClick","title"],ve={key:3,class:"has-nowrap"},ge={key:0,class:"has-text-success"},we={key:1,class:"has-text-danger"},ke={class:"is-size-6 is-size-7-mobile"},ye={class:"is-family-primary has-text-grey"},be={key:0,class:"has-text-danger"},$e={key:1,class:"has-text-warning"},Ce={key:2},Ae={key:0,class:"mt-2 is-size-7 is-pulled-right"},xe={key:1,class:"mt-2 is-size-7 is-pulled-right"},Fe={key:0,class:"control"},Ne={__name:"Import",setup(ze){const D=nt("2fauth"),_=lt(),J=rt(),x=gt(),K=ct(),y=k(null),F=k(null),z=k(null),b=q(new T({service:"",account:"",otp_type:"",icon:"",secret:"",algorithm:"",digits:null,counter:null,period:null})),$=q(new T({file:null,withSecret:!0})),C=q(new T({qrcode:null,withSecret:!0})),g=k(!1);f("twofaccounts.import.qr_code"),f("twofaccounts.import.plain_text");const l=k([]),m=k(!1),A=V(()=>l.value.filter(t=>t.imported==-1&&t.id>-2).length),N=V(()=>l.value.filter(t=>t.id===-1&&t.imported===-1).length),W=V(()=>l.value.filter(t=>t.imported===1).length);ut(g,t=>{var s;t==!1&&((s=y.value)==null||s.clearOTP())}),dt(()=>{x.migrationUri&&(O(x.migrationUri),x.migrationUri=null)});async function O(t){m.value=!0,await ft.migrate(t,{returnError:!0}).then(s=>{s.data.forEach(u=>{u.imported=-1,l.value.push(u)}),U()}).catch(s=>{_.alert({text:f(s.response.data.message)})}),m.value=!1}function G(){var t;confirm(f("twofaccounts.confirm.discard_duplicates"))&&(_.clear(),(t=y.value)==null||t.clearOTP(),l.value=l.value.filter(s=>s.id!==-1))}function H(){var t;confirm(f("twofaccounts.confirm.discard_all"))&&(_.clear(),(t=y.value)==null||t.clearOTP(),l.value=[])}function Q(t){confirm(f("twofaccounts.confirm.discard"))&&l.value.splice(t,1)}async function X(){for(let t=0;t<l.value.length;t++)l.value[t].imported==-1&&await P(t)}async function P(t){b.fill(l.value[t]),await b.post("/api/v1/twofaccounts",{returnError:!0}).then(s=>{l.value[t].imported=1,l.value[t].id=s.data.id,delete s.data.secret,K.items.push(s.data)}).catch(s=>{l.value[t].imported=0,l.value[t].id=0,l.value[t].errors=b.errors.flatten()})}function Y(t){b.fill(l.value[t]),g.value=!0,mt().then(()=>