1- import axios from " axios" ;
2- import { secondsToDhm } from " src/boot/utils" ;
1+ import axios from ' axios'
2+ import { secondsToDhm } from ' src/boot/utils'
33
44var saas = {
5- slideimg : " assets/images/hero/bitcoin-accounts.png" ,
6- url : "https://api.lnbits.com" ,
5+ slideimg : ' assets/images/hero/bitcoin-accounts.png' ,
6+ // url: "https://api.lnbits.com",
77 // for local development togegther with Caddy
8- // url: " /api" ,
8+ url : ' /api' ,
99 serverTime : null ,
1010
11- username : localStorage . getItem ( " username" ) ,
11+ username : localStorage . getItem ( ' username' ) ,
1212
1313 signup : async function ( username , password , password2 ) {
14- const { data } = await axios ( {
15- method : " POST" ,
16- url : this . url + " /signup" ,
14+ const { data} = await axios ( {
15+ method : ' POST' ,
16+ url : this . url + ' /signup' ,
1717 withCredentials : true ,
1818 data : {
1919 username,
2020 password,
21- password_repeat : password2 ,
22- } ,
23- } ) ;
21+ password_repeat : password2
22+ }
23+ } )
2424
25- localStorage . setItem ( " username" , username ) ;
25+ localStorage . setItem ( ' username' , username )
2626
27- return data ;
27+ return data
2828 } ,
2929 login : async function ( username , password ) {
30- const formData = new FormData ( ) ;
31- formData . append ( " username" , username ) ;
32- formData . append ( " password" , password ) ;
33- const { data } = await axios ( {
34- method : " POST" ,
35- url : this . url + " /login" ,
30+ const formData = new FormData ( )
31+ formData . append ( ' username' , username )
32+ formData . append ( ' password' , password )
33+ const { data} = await axios ( {
34+ method : ' POST' ,
35+ url : this . url + ' /login' ,
3636 data : formData ,
3737 withCredentials : true ,
3838 headers : {
39- " Content-Type" : " multipart/form-data" ,
40- } ,
41- } ) ;
42- localStorage . setItem ( " username" , username ) ;
39+ ' Content-Type' : ' multipart/form-data'
40+ }
41+ } )
42+ localStorage . setItem ( ' username' , username )
4343
44- return data ;
44+ return data
4545 } ,
4646
4747 createInstance : async function ( ) {
4848 return axios ( {
49- method : " POST" ,
50- url : this . url + " /instance" ,
51- withCredentials : true ,
52- } ) ;
49+ method : ' POST' ,
50+ url : this . url + ' /instance' ,
51+ withCredentials : true
52+ } )
5353 } ,
5454
5555 updateInstance : function ( id , action ) {
5656 return axios ( {
57- method : " PUT" ,
58- url : this . url + " /instance" ,
57+ method : ' PUT' ,
58+ url : this . url + ' /instance' ,
5959 withCredentials : true ,
6060 data : {
6161 action : action ,
62- instance_id : id ,
63- } ,
64- } ) ;
62+ instance_id : id
63+ }
64+ } )
6565 } ,
6666 getInstances : async function ( ) {
6767 const response = await axios ( {
68- method : "GET" ,
69- url : this . url + "/instance" ,
70- withCredentials : true ,
71- } ) ;
72-
73- return response ;
68+ method : 'GET' ,
69+ url : this . url + '/instance' ,
70+ withCredentials : true
71+ } )
72+ return response
7473 } ,
7574 getUserInstancesLogs : async function ( ) {
7675 const response = await axios ( {
77- method : " GET" ,
78- url : this . url + " /instance/logs" ,
79- withCredentials : true ,
80- } ) ;
76+ method : ' GET' ,
77+ url : this . url + ' /instance/logs' ,
78+ withCredentials : true
79+ } )
8180
82- return response ;
81+ return response
8382 } ,
8483 getInstancesLogs : async function ( id ) {
8584 const response = await axios ( {
86- method : " GET" ,
85+ method : ' GET' ,
8786 url : this . url + `/instance/${ id } /logs` ,
88- withCredentials : true ,
89- } ) ;
87+ withCredentials : true
88+ } )
9089
91- return response ;
90+ return response
9291 } ,
9392 status : async function ( ) {
9493 const response = await axios ( {
95- method : " GET" ,
94+ method : ' GET' ,
9695 url : this . url ,
97- withCredentials : true ,
98- } ) ;
96+ withCredentials : true
97+ } )
9998
100- this . serverTime = response . data . timestamp ;
99+ this . serverTime = response . data . timestamp
101100
102- return response ;
101+ return response
103102 } ,
104103 logout : async function ( ) {
105104 const response = await axios ( {
106- method : " POST" ,
107- url : this . url + " /logout" ,
108- withCredentials : true ,
109- } ) ;
110- this . username = null ;
111- localStorage . clear ( ) ;
112- return response ;
105+ method : ' POST' ,
106+ url : this . url + ' /logout' ,
107+ withCredentials : true
108+ } )
109+ this . username = null
110+ localStorage . clear ( )
111+ return response
113112 } ,
114113
115114 mapInstance : function ( instance ) {
116115 const progress = ( start , stop , serverTime ) => {
117116 if ( ! serverTime ) {
118- return 0 ;
117+ return 0
119118 }
120119 if ( stop - start <= 0 || stop - serverTime <= 0 ) {
121- return 100 ;
120+ return 100
122121 }
123122
124- const percentage = ( 1 - ( stop - serverTime ) / ( stop - start ) ) * 100 ;
123+ const percentage = ( 1 - ( stop - serverTime ) / ( stop - start ) ) * 100
125124
126- return Math . floor ( percentage ) ;
127- } ;
125+ return Math . floor ( percentage )
126+ }
128127
129128 const status = ( active , enabled ) => {
130- if ( ! active ) {
131- return " Not Paid"
129+ if ( ! active ) {
130+ return ' Not Paid'
132131 }
133132 if ( ! enabled ) {
134- return " Disabled"
133+ return ' Disabled'
135134 }
136- return " Running"
135+ return ' Running'
137136 }
138137
139138 const timeLeft = Math . floor (
140139 Math . max ( instance . timestamp_stop - this . serverTime , 0 )
141- ) ;
140+ )
142141 return {
143142 id : instance . id ,
144143 instanceLink : `https://${ instance . domain } /wallet` ,
@@ -160,34 +159,34 @@ var saas = {
160159 instance . timestamp_start || instance . timestamp ,
161160 instance . timestamp_stop ,
162161 this . serverTime
163- ) ,
164- } ;
162+ )
163+ }
165164 } ,
166165 mapErrorToString ( error ) {
167- const data = error . response ?. data ;
166+ const data = error . response ?. data
168167 if ( ! data ) {
169- return ;
168+ return
170169 }
171- if ( typeof data === " string" ) {
172- return data ;
170+ if ( typeof data === ' string' ) {
171+ return data
173172 }
174- return data ?. detail ?. map ( ( d ) => d . msg ) . join ( ", " ) ;
175- } ,
176- } ;
173+ return data ?. detail ?. map ( d => d . msg ) . join ( ', ' )
174+ }
175+ }
177176
178- ( async ( ) => {
177+ ; ( async ( ) => {
179178 axios . interceptors . response . use (
180- ( response ) => response ,
181- ( err ) => {
179+ response => response ,
180+ err => {
182181 if ( err ?. response ?. status === 401 ) {
183- saas . logout ( ) ;
184- if ( window . location . pathname !== " /login" ) {
185- setTimeout ( ( ) => ( window . location . href = " /login" ) , 500 ) ;
182+ saas . logout ( )
183+ if ( window . location . pathname !== ' /login' ) {
184+ setTimeout ( ( ) => ( window . location . href = ' /login' ) , 500 )
186185 }
187186 }
188- return Promise . reject ( err ) ;
187+ return Promise . reject ( err )
189188 }
190- ) ;
191- } ) ( ) ;
189+ )
190+ } ) ( )
192191
193- export { saas } ;
192+ export { saas }
0 commit comments