11import { 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' ;
33
44export const default_api_url = RV_API_URL ;
55export const default_status_url = RV_STATUS_URL ;
6+ export const default_email = RV_EMAIL ;
67
78const URL_KEY = 'revanced_api_url' ;
89const 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' ;
2011
2112export const API_VERSION = 'v4' ;
2213
@@ -25,9 +16,7 @@ export function api_base_url(): string {
2516 if ( browser ) {
2617 const apiUrl = localStorage . getItem ( URL_KEY ) || default_api_url ;
2718
28- if ( ! localStorage . getItem ( STATUS_KEY ) ) {
29- set_status_url ( apiUrl ) ;
30- }
19+ set_about_info ( apiUrl ) ;
3120
3221 return apiUrl ;
3322 }
@@ -43,12 +32,35 @@ export function status_url(): string {
4332 return default_status_url ;
4433}
4534
35+ export function email ( ) : string {
36+ if ( browser ) {
37+ return localStorage . getItem ( EMAIL_KEY ) || default_email ;
38+ }
39+
40+ return default_email ;
41+ }
42+
4643// (re)set base URL.
4744export function set_api_base_url ( url ?: string ) {
4845 if ( ! url ) {
4946 localStorage . removeItem ( URL_KEY ) ;
5047 } else {
5148 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+ } ) ;
5365 }
5466}
0 commit comments