2FAuth/public/build/assets/OtpDisplay-4c8a5daa.js

2 lines
6.6 KiB
JavaScript
Raw Normal View History

2024-03-15 15:37:37 +01:00
import{r,v as C,o as R,s as Z,f as u,g as d,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 x,l as A,m as G,p as ie,t as b,w as ce,Y as pe,U as ve,A as j,B as q,k as M,D as fe,K as D,I as z,P as Q}from"./app-94c6def1.js";import{S as de}from"./Spinner-f03b508f.js";/*! 2FAuth version 5.1.0 - 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,s=r(null),i=r(null),S=r(null),y=r(null),c=r(null),p=C(()=>s.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)=>{_(),s.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=s.value=null};return R(()=>{o.autostart==!0&&m()}),Z(()=>{_()}),T({startLoop:m,clearLooper:_,props:o}),(v,g)=>(u(),d("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=r(0),s=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(),d("ul",{class:N(["dots",{off:n(s)}])},[(u(!0),d(ee,null,te(k.stepCount,p=>(u(),d("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"},xe={__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,s=oe(),i=ae(),S=ne("2fauth"),{copy:y,copied:c}=se({legacy:!0}),p=re(),h=r(null),w=r(null),e=r({otp_type:"",account:"",service:"",icon:"",secret:"",digits:null,algorithm:"",period:null,counter:null,image:""}),m=r(""),_=r(null),v=r(!1),g=r(!1),O=r(!1),B=r(),I=r(),E=r();le(()=>o.icon,a=>{a!=null&&(e.value.icon=a)});const Y=async a=>{if(O.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,F(),a){h.value=a;const{data:t}=await D.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(z("errors.not_a_supported_otp_type"))):i.error(new Error(z("errors.cannot_create_otp_without_secret")));try{await V(),W()}catch{L()}};async function V(){F(),await J().then(a=>{let t=a.data;m.value=t.password,s.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 F(){g.value=!0,B.value.turnOff()}function J(){return h.value?D.getOtpById(h.value):w.value?D.getOtpByUri(w.value):D.getOtpByParams(e.value)}function L(){var a;h.value=e.value.counter=_.value=null,e.value.service=e.value.account=e.va