@@ -43,6 +43,7 @@ import type {
43
43
Attributes ,
44
44
FileEntry ,
45
45
} from 'ssh2' ;
46
+ import type { AuthTokenManager } from './AuthTokenManager' ;
46
47
47
48
const isRootPath = ( requestedPath : string ) : boolean => (
48
49
requestedPath === '/'
@@ -79,10 +80,10 @@ export class PermanentFileSystem {
79
80
80
81
private archivesCache ?: Archive [ ] ;
81
82
82
- private readonly authToken ;
83
+ private readonly authTokenManager ;
83
84
84
- public constructor ( authToken : string ) {
85
- this . authToken = authToken ;
85
+ public constructor ( authTokenManager : AuthTokenManager ) {
86
+ this . authTokenManager = authTokenManager ;
86
87
}
87
88
88
89
private static loadRootFileEntries ( ) : FileEntry [ ] {
@@ -191,7 +192,7 @@ export class PermanentFileSystem {
191
192
const childName = path . basename ( requestedPath ) ;
192
193
const parentFolder = await this . loadFolder ( parentPath ) ;
193
194
return createFolder (
194
- this . getClientConfiguration ( ) ,
195
+ await this . getClientConfiguration ( ) ,
195
196
{
196
197
name : childName ,
197
198
} ,
@@ -201,7 +202,7 @@ export class PermanentFileSystem {
201
202
202
203
public async deleteDirectory ( requestedPath : string ) : Promise < void > {
203
204
const account = await getAuthenticatedAccount (
204
- this . getClientConfiguration ( ) ,
205
+ await this . getClientConfiguration ( ) ,
205
206
) ;
206
207
if ( ! account . isSftpDeletionEnabled ) {
207
208
throw new OperationNotAllowedError ( 'You must enable SFTP deletion directly in your account settings.' ) ;
@@ -220,7 +221,7 @@ export class PermanentFileSystem {
220
221
const folder = await this . loadFolder ( requestedPath ) ;
221
222
222
223
await deleteFolder (
223
- this . getClientConfiguration ( ) ,
224
+ await this . getClientConfiguration ( ) ,
224
225
folder . id ,
225
226
) ;
226
227
}
@@ -242,14 +243,14 @@ export class PermanentFileSystem {
242
243
fileSystemCompatibleName : archiveRecordName ,
243
244
} ;
244
245
const s3Url = await uploadFile (
245
- this . getClientConfiguration ( ) ,
246
+ await this . getClientConfiguration ( ) ,
246
247
dataStream ,
247
248
fileFragment ,
248
249
archiveRecordfragment ,
249
250
parentFolder ,
250
251
) ;
251
252
await createArchiveRecord (
252
- this . getClientConfiguration ( ) ,
253
+ await this . getClientConfiguration ( ) ,
253
254
s3Url ,
254
255
fileFragment ,
255
256
archiveRecordfragment ,
@@ -259,7 +260,7 @@ export class PermanentFileSystem {
259
260
260
261
public async deleteFile ( requestedPath : string ) : Promise < void > {
261
262
const account = await getAuthenticatedAccount (
262
- this . getClientConfiguration ( ) ,
263
+ await this . getClientConfiguration ( ) ,
263
264
) ;
264
265
if ( ! account . isSftpDeletionEnabled ) {
265
266
throw new OperationNotAllowedError ( 'You must enable SFTP deletion directly in your account settings.' ) ;
@@ -274,7 +275,7 @@ export class PermanentFileSystem {
274
275
) ;
275
276
276
277
await deleteArchiveRecord (
277
- this . getClientConfiguration ( ) ,
278
+ await this . getClientConfiguration ( ) ,
278
279
archiveRecord . id ,
279
280
) ;
280
281
}
@@ -338,7 +339,7 @@ export class PermanentFileSystem {
338
339
childName ,
339
340
) ;
340
341
const populatedArchiveRecord = await getArchiveRecord (
341
- this . getClientConfiguration ( ) ,
342
+ await this . getClientConfiguration ( ) ,
342
343
archiveRecord . id ,
343
344
archiveId ,
344
345
) ;
@@ -380,17 +381,18 @@ export class PermanentFileSystem {
380
381
return this . loadArchiveRecords ( archiveRecordPaths ) ;
381
382
}
382
383
383
- private getClientConfiguration ( ) : ClientConfiguration {
384
+ private async getClientConfiguration ( ) : Promise < ClientConfiguration > {
385
+ const authToken = await this . authTokenManager . getAuthToken ( ) ;
384
386
return {
385
- bearerToken : this . authToken ,
387
+ bearerToken : authToken ,
386
388
baseUrl : process . env . PERMANENT_API_BASE_PATH ,
387
389
} ;
388
390
}
389
391
390
392
private async loadArchives ( ) : Promise < Archive [ ] > {
391
393
if ( ! this . archivesCache ) {
392
394
this . archivesCache = await getArchives (
393
- this . getClientConfiguration ( ) ,
395
+ await this . getClientConfiguration ( ) ,
394
396
) ;
395
397
}
396
398
return this . archivesCache ;
@@ -417,7 +419,7 @@ export class PermanentFileSystem {
417
419
return cachedArchiveFolders ;
418
420
}
419
421
const archiveFolders = await getArchiveFolders (
420
- this . getClientConfiguration ( ) ,
422
+ await this . getClientConfiguration ( ) ,
421
423
archiveId ,
422
424
) ;
423
425
this . archiveFoldersCache . set ( archiveId , archiveFolders ) ;
@@ -506,7 +508,7 @@ export class PermanentFileSystem {
506
508
childName ,
507
509
) ;
508
510
const populatedTargetFolder = await getFolder (
509
- this . getClientConfiguration ( ) ,
511
+ await this . getClientConfiguration ( ) ,
510
512
targetFolder . id ,
511
513
archiveId ,
512
514
) ;
0 commit comments