2024-02-23 15:31:08 +01:00
|
|
|
import{r as s,v as C,o as R,s as Z,f as u,g as f,F as ee,G as te,i as n,n as N,a as oe,b as ae,Q as ne,S as se,_ as re,x as le,e as ue,h as O,l as A,m as M,p as ie,t as b,w as ce,Y as pe,U as ve,A as q,B as G,k as z,D as de,K as B,I as E,P as Q}from"./app-06176200.js";import{S as fe}from"./Spinner-1a29b2e3.js";/*! 2FAuth version 5.0.4 - Copyright (c) 2023 Bubka - https://github.com/Bubka/2FAuth */const ye={__name:"TotpLooper",props:{step_count:{type:Number,default:10},period:Number,generated_at:Number,autostart:{type:Boolean,default:!0}},emits:["loop-started","loop-ended","stepped-up"],setup(k,{expose:T,emit:l}){const o=k,r=s(null),i=s(null),S=s(null),y=s(null),c=s(null),p=C(()=>r.value%o.period),h=C(()=>o.period-p.value),w=C(()=>o.period/o.step_count),e=C(()=>{let v=p.value*o.step_count/o.period;return Math.floor(v)+0}),m=(v=null)=>{_(),r.value=v??o.generated_at,l("loop-started",e.value),c.value=e.value,i.value=setTimeout(function(){_(),l("loop-ended")},h.value*1e3);let g=Math.ceil(p.value/w.value)*w.value-p.value;S.value=setTimeout(function(){g>0&&(c.value+=1,l("stepped-up",c.value)),y.value=setInterval(function(){c.value+=1,l("stepped-up",c.value)},w.value*1e3)},g*1e3)},_=()=>{clearTimeout(i.value),clearTimeout(S.value),clearInterval(y.value),c.value=r.value=null};return R(()=>{o.autostart==!0&&m()}),Z(()=>{_()}),T({startLoop:m,clearLooper:_,props:o}),(v,g)=>(u(),f("div"))}},me=["data-is-active"],_e={__name:"Dots",props:{stepCount:{type:Number,default:10},initialIndex:{type:Number,default:null},period:{type:Number,default:null}},setup(k,{expose:T}){const l=k,o=s(0),r=C(()=>o.value==-1);function i(y){o.value=y<l.stepCount?y+1:1}function S(){o.value=-1}return R(()=>{isNaN(l.initialIndex)||i(l.initialIndex)}),T({turnOn:i,turnOff:S,props:l}),(y,c)=>(u(),f("ul",{class:N(["dots",{off:n(r)}])},[(u(!0),f(ee,null,te(k.stepCount,p=>(u(),f("li",{key:p,"data-is-active":p==n(o)?!0:null},null,8,me))),128))],2))}},ge=["src","alt"],he=["title"],we={key:1,tabindex:"0",class:"otp is-size-1"},ke={key:0,class:"mt-3"},Oe={__name:"OtpDisplay",props:{otp_type:String,account:String,service:String,icon:String,secret:String,digits:Number,algorithm:String,period:null,counter:null,image:String,qrcode:null,uri:String},emits:["please-close-me","increment-hotp","validation-error"],setup(k,{expose:T,emit:l}){const o=k,r=oe(),i=ae(),S=ne("2fauth"),{copy:y,copied:c}=se({legacy:!0}),p=re(),h=s(null),w=s(null),e=s({otp_type:"",account:"",service:"",icon:"",secret:"",digits:null,algorithm:"",period:null,counter:null,image:""}),m=s(""),_=s(null),v=s(!1),g=s(!1),x=s(!1),D=s(),I=s(),V=s();le(()=>o.icon,a=>{a!=null&&(e.value.icon=a)});const Y=async a=>{if(x.value=!1,e.value.otp_type=o.otp_type,e.value.account=o.account,e.value.service=o.service,e.value.icon=o.icon,e.value.secret=o.secret,e.value.digits=o.digits,e.value.algorithm=o.algorithm,e.value.period=o.period,e.value.counter=o.counter,K(),a){h.value=a;const{data:t}=await B.get(h.value);e.value.service=t.service,e.value.account=t.account,e.value.icon=t.icon,e.value.otp_type=t.otp_type,P(t.otp_type)&&t.counter&&(e.value.counter=t.counter)}else o.uri?(w.value=o.uri,e.value.otp_type=o.uri.slice(0,15).toLowerCase()==="otpauth://totp/"?"totp":"hotp"):o.secret?!U(e.value.otp_type)&&!P(e.value.otp_type)&&i.error(new Error(E("errors.not_a_supported_otp_type"))):i.error(new Error(E("errors.cannot_create_otp_without_secret")));try{await F(),W()}catch{L()}};async function F(){K(),await J().then(a=>{let t=a.data;m.value=t.password,r.preferences.copyOtpOnDisplay&&$(t.password),U(t.otp_type)?(_.value=t.generated_at,e.value.period=t.period,v.value=!0,Q().then(()=>{I.value.startLoop()})):P(t.otp_type)&&(e.value.counter=t.counter,l("increment-hotp",{nextHotpCounter:t.counter,nextUri:t.uri}))}).catch(a=>{a.response.status===422&&l("validation-error",a.response)}).finally(()=>{g.value=!1})}function K(){g.value=!0,D.value.turnOff()}function J(){return h.value?B.getOtpById(h.value):w.value?B.getOtpByUri(w.value):B.getOtpByParams(e.value)}function L(){var a;h.value=e.value.counter=_.value=null,e.value.service=e.value.account
|