1
1
import { browser } from '$app/environment' ;
2
- import { RV_API_URL , RV_STATUS_URL } from '$env/static/public' ;
2
+ import { RV_API_URL , RV_EMAIL , RV_STATUS_URL } from '$env/static/public' ;
3
3
4
4
export const default_api_url = RV_API_URL ;
5
5
export const default_status_url = RV_STATUS_URL ;
6
+ export const default_email = RV_EMAIL ;
6
7
7
8
const URL_KEY = 'revanced_api_url' ;
8
9
const STATUS_KEY = 'revanced_status_url' ;
9
-
10
- function set_status_url ( apiUrl : string ) {
11
- fetch ( `${ apiUrl } /v4/about` )
12
- . then ( ( response ) => ( response . ok ? response . json ( ) : null ) )
13
- . then ( ( data ) => {
14
- if ( data ?. status ) {
15
- localStorage . setItem ( STATUS_KEY , data . status ) ;
16
- console . log ( 'Status is now:' , localStorage . getItem ( STATUS_KEY ) ) ;
17
- }
18
- } ) ;
19
- }
10
+ const EMAIL_KEY = 'revanced_email' ;
20
11
21
12
export const API_VERSION = 'v4' ;
22
13
@@ -25,9 +16,7 @@ export function api_base_url(): string {
25
16
if ( browser ) {
26
17
const apiUrl = localStorage . getItem ( URL_KEY ) || default_api_url ;
27
18
28
- if ( ! localStorage . getItem ( STATUS_KEY ) ) {
29
- set_status_url ( apiUrl ) ;
30
- }
19
+ set_about_info ( apiUrl ) ;
31
20
32
21
return apiUrl ;
33
22
}
@@ -43,12 +32,35 @@ export function status_url(): string {
43
32
return default_status_url ;
44
33
}
45
34
35
+ export function email ( ) : string {
36
+ if ( browser ) {
37
+ return localStorage . getItem ( EMAIL_KEY ) || default_email ;
38
+ }
39
+
40
+ return default_email ;
41
+ }
42
+
46
43
// (re)set base URL.
47
44
export function set_api_base_url ( url ?: string ) {
48
45
if ( ! url ) {
49
46
localStorage . removeItem ( URL_KEY ) ;
50
47
} else {
51
48
localStorage . setItem ( URL_KEY , url ) ;
52
- set_status_url ( url ) ;
49
+ set_about_info ( url ) ;
50
+ }
51
+ }
52
+
53
+ function set_about_info ( apiUrl : string ) {
54
+ if ( ! localStorage . getItem ( STATUS_KEY ) || ! localStorage . getItem ( EMAIL_KEY ) ) {
55
+ fetch ( `${ apiUrl } /v4/about` )
56
+ . then ( ( response ) => ( response . ok ? response . json ( ) : null ) )
57
+ . then ( ( data ) => {
58
+ if ( data ?. status ) {
59
+ localStorage . setItem ( STATUS_KEY , data . status ) ;
60
+ localStorage . setItem ( EMAIL_KEY , data . contact . email ) ;
61
+ console . log ( 'Status is now:' , localStorage . getItem ( STATUS_KEY ) ) ;
62
+ console . log ( 'Email is now:' , localStorage . getItem ( EMAIL_KEY ) ) ;
63
+ }
64
+ } ) ;
53
65
}
54
66
}
0 commit comments