@@ -13,6 +13,10 @@ export const DashdotModule = asModule({
13
13
icon : CalendarIcon ,
14
14
component : DashdotComponent ,
15
15
options : {
16
+ url : {
17
+ name : 'Dash. URL' ,
18
+ value : '' ,
19
+ } ,
16
20
cpuMultiView : {
17
21
name : 'CPU Multi-Core View' ,
18
22
value : false ,
@@ -88,23 +92,23 @@ const bytePrettyPrint = (byte: number): string =>
88
92
? `${ ( byte / 1024 ) . toFixed ( 1 ) } KiB`
89
93
: `${ byte . toFixed ( 1 ) } B` ;
90
94
91
- const useJson = ( service : serviceItem | undefined , url : string ) => {
95
+ const useJson = ( targetUrl : string , url : string ) => {
92
96
const [ data , setData ] = useState < any | undefined > ( ) ;
93
97
94
98
const doRequest = async ( ) => {
95
99
try {
96
- const resp = await axios . get ( url , { baseURL : service ?. url } ) ;
100
+ const resp = await axios . get ( `/api/modules/dashdot? url= ${ url } &base= ${ targetUrl } ` ) ;
97
101
98
102
setData ( resp . data ) ;
99
103
// eslint-disable-next-line no-empty
100
104
} catch ( e ) { }
101
105
} ;
102
106
103
107
useEffect ( ( ) => {
104
- if ( service ?. url ) {
108
+ if ( targetUrl ) {
105
109
doRequest ( ) ;
106
110
}
107
- } , [ service ?. url ] ) ;
111
+ } , [ targetUrl ] ) ;
108
112
109
113
return data ;
110
114
} ;
@@ -118,17 +122,19 @@ export function DashdotComponent() {
118
122
const dashConfig = config . modules ?. [ DashdotModule . title ]
119
123
. options as typeof DashdotModule [ 'options' ] ;
120
124
const isCompact = dashConfig ?. useCompactView ?. value ?? false ;
121
- const dashdotService = config . services . filter ( ( service ) => service . type === 'Dash.' ) [ 0 ] ;
122
-
125
+ const dashdotService : serviceItem | undefined = config . services . filter (
126
+ ( service ) => service . type === 'Dash.'
127
+ ) [ 0 ] ;
128
+ const dashdotUrl = dashdotService ?. url ?? dashConfig ?. url ?. value ?? '' ;
123
129
const enabledGraphs = dashConfig ?. graphs ?. value ?? [ 'CPU' , 'RAM' , 'Storage' , 'Network' ] ;
124
130
const cpuEnabled = enabledGraphs . includes ( 'CPU' ) ;
125
131
const storageEnabled = enabledGraphs . includes ( 'Storage' ) ;
126
132
const ramEnabled = enabledGraphs . includes ( 'RAM' ) ;
127
133
const networkEnabled = enabledGraphs . includes ( 'Network' ) ;
128
134
const gpuEnabled = enabledGraphs . includes ( 'GPU' ) ;
129
135
130
- const info = useJson ( dashdotService , '/info' ) ;
131
- const storageLoad = useJson ( dashdotService , '/load/storage' ) ;
136
+ const info = useJson ( dashdotUrl , '/info' ) ;
137
+ const storageLoad = useJson ( dashdotUrl , '/load/storage' ) ;
132
138
133
139
const totalUsed =
134
140
( storageLoad ?. layout as any [ ] ) ?. reduce ( ( acc , curr ) => ( curr . load ?? 0 ) + acc , 0 ) ?? 0 ;
@@ -166,13 +172,23 @@ export function DashdotComponent() {
166
172
} ,
167
173
] . filter ( ( g ) => g . enabled ) ;
168
174
175
+ if ( dashdotUrl === '' ) {
176
+ return (
177
+ < div >
178
+ < h2 className = { classes . heading } > Dash.</ h2 >
179
+ < p >
180
+ No dash. service found. Please add one to your Homarr dashboard or set a dashdot URL in
181
+ the module options
182
+ </ p >
183
+ </ div >
184
+ ) ;
185
+ }
186
+
169
187
return (
170
188
< div >
171
189
< h2 className = { classes . heading } > Dash.</ h2 >
172
190
173
- { ! dashdotService ? (
174
- < p > No dash. service found. Please add one to your Homarr dashboard.</ p >
175
- ) : ! info ? (
191
+ { ! info ? (
176
192
< p > Cannot acquire information from dash. - are you running the latest version?</ p >
177
193
) : (
178
194
< div className = { classes . graphsContainer } >
@@ -209,9 +225,7 @@ export function DashdotComponent() {
209
225
}
210
226
key = { graph . name }
211
227
title = { graph . name }
212
- src = { `${
213
- dashdotService . url
214
- } ?singleGraphMode=true&graph=${ graph . name . toLowerCase ( ) } &theme=${ colorScheme } &surface=${ ( colorScheme ===
228
+ src = { `${ dashdotUrl } ?singleGraphMode=true&graph=${ graph . name . toLowerCase ( ) } &theme=${ colorScheme } &surface=${ ( colorScheme ===
215
229
'dark'
216
230
? theme . colors . dark [ 7 ]
217
231
: theme . colors . gray [ 0 ]
0 commit comments