@@ -4,19 +4,21 @@ import cache from 'memory-cache';
4
4
export default class Api {
5
5
cache : any ;
6
6
baseUrl : string ;
7
+ params : string ;
7
8
lastCacheDuration : number | undefined ;
8
9
9
- constructor ( baseUrl : string ) {
10
+ constructor ( baseUrl : string , params : string ) {
10
11
this . baseUrl = baseUrl ;
12
+ this . params = params ;
11
13
this . cache = new cache . Cache ( ) ;
12
14
}
13
15
14
16
/**
15
17
* Queries the API and returns the response data.
16
18
*/
17
- async get ( params ?: string ) {
19
+ async get ( ) {
18
20
const req = {
19
- url : `${ this . baseUrl } ${ params ? .length ? `?${ params } ` : '' } ` ,
21
+ url : `${ this . baseUrl } ${ this . params . length ? `?${ this . params } ` : '' } ` ,
20
22
method : 'GET' ,
21
23
} ;
22
24
@@ -28,9 +30,9 @@ export default class Api {
28
30
/**
29
31
* Used as a health check.
30
32
*/
31
- async test ( params ?: string ) {
33
+ async test ( ) {
32
34
const req = {
33
- url : `${ this . baseUrl } ${ params ? .length ? `?${ params } ` : '' } ` ,
35
+ url : `${ this . baseUrl } ${ this . params . length ? `?${ this . params } ` : '' } ` ,
34
36
method : 'GET' ,
35
37
} ;
36
38
return getBackendSrv ( ) . datasourceRequest ( req ) ;
@@ -41,7 +43,7 @@ export default class Api {
41
43
*/
42
44
async cachedGet ( cacheDurationSeconds : number , params ?: string ) {
43
45
if ( cacheDurationSeconds === 0 ) {
44
- return await this . get ( params ) ;
46
+ return await this . get ( ) ;
45
47
}
46
48
47
49
const force = this . lastCacheDuration !== cacheDurationSeconds ;
@@ -56,7 +58,7 @@ export default class Api {
56
58
}
57
59
this . lastCacheDuration = cacheDurationSeconds ;
58
60
59
- const result = await this . get ( params ) ;
61
+ const result = await this . get ( ) ;
60
62
61
63
this . cache . put ( this . baseUrl , result , Math . max ( cacheDurationSeconds * 1000 , 1 ) ) ;
62
64
0 commit comments