Skip to content

Commit

Permalink
Merge pull request #3 from fleetbase/dev-v0.0.3
Browse files Browse the repository at this point in the history
v0.0.3
  • Loading branch information
roncodes authored Aug 7, 2024
2 parents 917e994 + 6bc5e21 commit cc9a22a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -217,7 +219,7 @@ class S3Database {
});
}
else {
this.logger.trace('s3: [_getData] already exist');
this.logger.debug('s3: [_getData] already exist');
}
return this._localData;
}
Expand Down Expand Up @@ -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}');
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export default class S3Database implements IPluginStorage<S3Config> {
}

public async getAsync(): Promise<string[]> {
this.logger.debug('s3: [getAsync]');
return new Promise((resolve, reject) => {
this.get((err, data) => {
if (err) {
Expand Down Expand Up @@ -212,6 +213,7 @@ export default class S3Database implements IPluginStorage<S3Config> {
}

private async _getData(): Promise<LocalStorage> {
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;
Expand Down Expand Up @@ -244,7 +246,7 @@ export default class S3Database implements IPluginStorage<S3Config> {
);
});
} else {
this.logger.trace('s3: [_getData] already exist');
this.logger.debug('s3: [_getData] already exist');
}

return this._localData as LocalStorage;
Expand Down Expand Up @@ -353,6 +355,9 @@ export default class S3Database implements IPluginStorage<S3Config> {
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();

Expand Down Expand Up @@ -420,7 +425,7 @@ export default class S3Database implements IPluginStorage<S3Config> {

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,
Expand Down

0 comments on commit cc9a22a

Please sign in to comment.