2FAuth/public/build/assets/OtpDisplay-D0I30jj_.js

2 lines
6.8 KiB
JavaScript
Raw Normal View History

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