From 6bc5e215705e752634d77216d14efda84877847c Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Wed, 7 Aug 2024 14:16:18 +0800 Subject: [PATCH] more debug logging and reset `_localData` when calling `getAllComposerJson` --- lib/index.d.ts.map | 2 +- lib/index.js | 8 ++++++-- package-lock.json | 4 ++-- package.json | 2 +- src/index.ts | 9 +++++++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/index.d.ts.map b/lib/index.d.ts.map index 3625446..bda00fa 100644 --- a/lib/index.d.ts.map +++ b/lib/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAIpI,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAKlD,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,MAAM,CAAC,OAAO,OAAO,UAAW,YAAW,cAAc,CAAC,QAAQ,CAAC;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,QAAQ,CAAC;IACxB,OAAO,CAAC,EAAE,CAAK;IACf,OAAO,CAAC,UAAU,CAAsB;gBAErB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC;IAoDtD,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAI5B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAkBrC,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;YAS1D,iB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mB,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IA6BrC,kBAAkB,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE;YAAE,CAAC,WAAW,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAA;KAAE,CAAC;IA6CxF,OAAO,CAAC,eAAe;IAoBvB,OAAO,CAAC,qBAAqB;CAsBhC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 071cd84..77ede84 100644 --- a/lib/index.js +++ b/lib/index.js @@ -150,6 +150,7 @@ class S3Database { this._getData().then((data) => callback(null, data.list)); } async getAsync() { + this.logger.debug('s3: [getAsync]'); return new Promise((resolve, reject) => { this.get((err, data) => { if (err) { @@ -187,6 +188,7 @@ class S3Database { return new s3PackageManager_1.default(this.config, packageName, this.logger); } async _getData() { + this.logger.debug({ localData: this._localData }, 's3: [getAsync] localData: @{localData}'); if (!this._localData) { this._localData = await new Promise((resolve, reject) => { const { bucket, keyPrefix } = this.config; @@ -217,7 +219,7 @@ class S3Database { }); } else { - this.logger.trace('s3: [_getData] already exist'); + this.logger.debug('s3: [_getData] already exist'); } return this._localData; } @@ -306,6 +308,8 @@ class S3Database { async getAllComposerJson() { this.logger.debug('s3: [getAllComposerJson]'); const composerPackages = {}; + // Reset _localData + this._localData = null; // Use the new getAsync method const packages = await this.getAsync(); this.logger.debug({ packages }, 's3: [getAllComposerJson] found packages: @{packages}'); @@ -359,7 +363,7 @@ class S3Database { } const fileName = `${nameWithoutScope}-${version}.tgz`; const tarballPath = this._getPackagePath(packageName, fileName); - const signedUrlExpireSeconds = 60 * 30; + const signedUrlExpireSeconds = 60 * 5; let url = this.s3.getSignedUrl('getObject', { Bucket: this.config.bucket, Key: tarballPath, diff --git a/package-lock.json b/package-lock.json index fd13507..7307c20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@fleetbase/verdaccio-fleetbase-s3-storage", - "version": "0.0.1", + "version": "0.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@fleetbase/verdaccio-fleetbase-s3-storage", - "version": "0.0.1", + "version": "0.0.3", "license": "AGPL-3.0-or-later", "dependencies": { "@verdaccio/commons-api": "10.2.0", diff --git a/package.json b/package.json index 3473446..0dc2c6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fleetbase/verdaccio-fleetbase-s3-storage", - "version": "0.0.2", + "version": "0.0.3", "description": "AWS S3 storage implementation for Verdaccio modified for Fleetbase extensions.", "keywords": [ "fleetbase", diff --git a/src/index.ts b/src/index.ts index a4f0d8c..7f1a4a3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -169,6 +169,7 @@ export default class S3Database implements IPluginStorage { } public async getAsync(): Promise { + this.logger.debug('s3: [getAsync]'); return new Promise((resolve, reject) => { this.get((err, data) => { if (err) { @@ -212,6 +213,7 @@ export default class S3Database implements IPluginStorage { } private async _getData(): Promise { + this.logger.debug({ localData: this._localData }, 's3: [getAsync] localData: @{localData}'); if (!this._localData) { this._localData = await new Promise((resolve, reject): void => { const { bucket, keyPrefix } = this.config; @@ -244,7 +246,7 @@ export default class S3Database implements IPluginStorage { ); }); } else { - this.logger.trace('s3: [_getData] already exist'); + this.logger.debug('s3: [_getData] already exist'); } return this._localData as LocalStorage; @@ -353,6 +355,9 @@ export default class S3Database implements IPluginStorage { this.logger.debug('s3: [getAllComposerJson]'); const composerPackages: { [packageName: string]: any } = {}; + // Reset _localData + this._localData = null; + // Use the new getAsync method const packages = await this.getAsync(); @@ -420,7 +425,7 @@ export default class S3Database implements IPluginStorage { const fileName = `${nameWithoutScope}-${version}.tgz`; const tarballPath = this._getPackagePath(packageName, fileName); - const signedUrlExpireSeconds = 60 * 30; + const signedUrlExpireSeconds = 60 * 5; let url = this.s3.getSignedUrl('getObject', { Bucket: this.config.bucket,