@@ -27,72 +27,82 @@ export const getAxios = async (force: boolean = false): Promise<AxiosInstance> =
27
27
28
28
export async function mihomoVersion ( ) : Promise < IMihomoVersion > {
29
29
const instance = await getAxios ( )
30
- return instance . get ( '/version' ) . catch ( ( e ) => {
31
- return e . response . data
32
- } )
30
+ return ( await instance . get ( '/version' ) . catch ( ( ) => {
31
+ return { version : '-' }
32
+ } ) ) as IMihomoVersion
33
33
}
34
34
35
35
export const mihomoConfig = async ( ) : Promise < IMihomoConfig > => {
36
36
const instance = await getAxios ( )
37
- return instance . get ( '/configs' ) . catch ( ( e ) => {
38
- return e . response . data
39
- } )
37
+ return ( await instance . get ( '/configs' ) . catch ( ( ) => {
38
+ return { }
39
+ } ) ) as IMihomoConfig
40
40
}
41
41
42
42
export const patchMihomoConfig = async ( patch : Partial < IMihomoConfig > ) : Promise < void > => {
43
43
const instance = await getAxios ( )
44
- return instance . patch ( '/configs' , patch ) . catch ( ( e ) => {
44
+ return ( await instance . patch ( '/configs' , patch ) . catch ( ( e ) => {
45
45
return e . response . data
46
- } )
46
+ } ) ) as Promise < void >
47
47
}
48
48
49
49
export const mihomoConnections = async ( ) : Promise < IMihomoConnectionsInfo > => {
50
50
const instance = await getAxios ( )
51
- return instance . get ( '/connections' ) . catch ( ( e ) => {
52
- return e . response . data
53
- } )
51
+ return ( await instance . get ( '/connections' ) . catch ( ( ) => {
52
+ return { downloadTotal : 0 , uploadTotal : 0 , connections : [ ] , memory : 0 }
53
+ } ) ) as IMihomoConnectionsInfo
54
54
}
55
55
56
56
export const mihomoCloseConnection = async ( id : string ) : Promise < void > => {
57
57
const instance = await getAxios ( )
58
- return instance . delete ( `/connections/${ encodeURIComponent ( id ) } ` ) . catch ( ( e ) => {
58
+ return ( await instance . delete ( `/connections/${ encodeURIComponent ( id ) } ` ) . catch ( ( e ) => {
59
59
return e . response . data
60
- } )
60
+ } ) ) as Promise < void >
61
61
}
62
62
63
63
export const mihomoCloseAllConnections = async ( ) : Promise < void > => {
64
64
const instance = await getAxios ( )
65
- return instance . delete ( '/connections' ) . catch ( ( e ) => {
65
+ return ( await instance . delete ( '/connections' ) . catch ( ( e ) => {
66
66
return e . response . data
67
- } )
67
+ } ) ) as Promise < void >
68
68
}
69
69
70
70
export const mihomoRules = async ( ) : Promise < IMihomoRulesInfo > => {
71
71
const instance = await getAxios ( )
72
- return instance . get ( '/rules' ) . catch ( ( e ) => {
73
- return e . response . data
74
- } )
72
+ return ( await instance . get ( '/rules' ) . catch ( ( ) => {
73
+ return { rules : [ ] }
74
+ } ) ) as IMihomoRulesInfo
75
75
}
76
76
77
77
export const mihomoProxies = async ( ) : Promise < IMihomoProxies > => {
78
78
const instance = await getAxios ( )
79
- return instance . get ( '/proxies' ) . catch ( ( e ) => {
80
- return e . response . data
81
- } )
79
+ return ( await instance . get ( '/proxies' ) . catch ( ( ) => {
80
+ return { proxies : { } }
81
+ } ) ) as IMihomoProxies
82
82
}
83
83
84
84
export const mihomoChangeProxy = async ( group : string , proxy : string ) : Promise < IMihomoProxy > => {
85
85
const instance = await getAxios ( )
86
- return instance . put ( `/proxies/${ encodeURIComponent ( group ) } ` , { name : proxy } ) . catch ( ( e ) => {
87
- return e . response . data
88
- } )
86
+ return ( await instance . put ( `/proxies/${ encodeURIComponent ( group ) } ` , { name : proxy } ) . catch ( ( ) => {
87
+ return {
88
+ alive : false ,
89
+ extra : { } ,
90
+ history : [ ] ,
91
+ id : '' ,
92
+ name : '' ,
93
+ tfo : false ,
94
+ type : 'Shadowsocks' ,
95
+ udp : false ,
96
+ xudp : false
97
+ }
98
+ } ) ) as IMihomoProxy
89
99
}
90
100
91
101
export const mihomoProxyDelay = async ( proxy : string , url ?: string ) : Promise < IMihomoDelay > => {
92
102
const appConfig = getAppConfig ( )
93
103
const { delayTestUrl, delayTestTimeout } = appConfig
94
104
const instance = await getAxios ( )
95
- return instance
105
+ return ( await instance
96
106
. get ( `/proxies/${ encodeURIComponent ( proxy ) } /delay` , {
97
107
params : {
98
108
url : url || delayTestUrl || 'https://www.gstatic.com/generate_204' ,
@@ -101,7 +111,7 @@ export const mihomoProxyDelay = async (proxy: string, url?: string): Promise<IMi
101
111
} )
102
112
. catch ( ( e ) => {
103
113
return e . response . data
104
- } )
114
+ } ) ) as IMihomoDelay
105
115
}
106
116
107
117
export const startMihomoTraffic = ( ) : void => {
0 commit comments