1
1
import * as httpModule from 'http' ;
2
2
import * as httpsModule from 'https' ;
3
3
import { outputConsole , currentWorkspaceFolder } from '../utils' ;
4
- import { config } from '../extension' ;
4
+ const Cache = require ( 'vscode-cache' ) ;
5
+ import { config , extensionContext } from '../extension' ;
5
6
6
7
const DEFAULT_API_VERSION : number = 3 ;
7
8
8
9
export class AtelierAPI {
9
- private cookies : string [ ] = [ ] ;
10
10
private _config : any ;
11
11
private _namespace : string ;
12
+ private _cache ;
12
13
13
14
private get ns ( ) : string {
14
15
return this . _namespace || this . _config . ns ;
@@ -20,22 +21,30 @@ export class AtelierAPI {
20
21
21
22
constructor ( ) {
22
23
this . setConnection ( currentWorkspaceFolder ( ) ) ;
24
+ const { name, host, port } = this . _config ;
25
+ this . _cache = new Cache ( extensionContext , `API:${ name } :${ host } :${ port } ` ) ;
23
26
}
24
27
25
28
setNamespace ( namespace : string ) {
26
29
this . _namespace = namespace ;
27
30
}
28
31
29
- updateCookies ( cookies : string [ ] ) {
30
- cookies . forEach ( cookie => {
32
+ get cookies ( ) : string [ ] {
33
+ return this . _cache . get ( 'cookies' , [ ] ) ;
34
+ }
35
+
36
+ updateCookies ( newCookies : string [ ] ) {
37
+ let cookies = this . _cache . get ( 'cookies' , [ ] ) ;
38
+ newCookies . forEach ( cookie => {
31
39
let [ cookieName ] = cookie . split ( '=' ) ;
32
- let index = this . cookies . findIndex ( el => el . startsWith ( cookieName ) ) ;
33
- if ( index ) {
34
- this . cookies [ index ] = cookie ;
40
+ let index = cookies . findIndex ( el => el . startsWith ( cookieName ) ) ;
41
+ if ( index >= 0 ) {
42
+ cookies [ index ] = cookie ;
35
43
} else {
36
- this . cookies . push ( cookie ) ;
44
+ cookies . push ( cookie ) ;
37
45
}
38
46
} ) ;
47
+ this . _cache . put ( 'cookies' , cookies ) ;
39
48
}
40
49
41
50
setConnection ( workspaceFolderName : string ) {
0 commit comments