Skip to content

Commit

Permalink
fix(s3): disable S3Client logger (#664)
Browse files Browse the repository at this point in the history
set environment variable `S3_DEBUG` to enable
  • Loading branch information
kukhariev authored Jun 10, 2023
1 parent 681f30f commit 833867f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GCS_KEYFILE=~/.gcs-credentials.json
# See also https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/loading-node-credentials-environment.html
S3_BUCKET=uploadx
S3_ENDPOINT=https://s3.us-west-002.backblazeb2.com
S3_DEBUG=false
# Path to file with accessKeyId and secretAccessKey and region(optional)
# S3_KEYFILE=.s3-config.example

4 changes: 4 additions & 0 deletions packages/core/src/utils/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,7 @@ export const memoize = <T, K>(fn: (arg: T) => K): ((arg: T) => K) => {
};

export const hash = memoize(fnv64);

export const toBoolean = (val?: unknown): boolean => {
return ['true', '1', 'y', 'yes'].includes(String(val).trim().toLowerCase());
};
9 changes: 6 additions & 3 deletions packages/s3/src/s3-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
mapValues,
MetaStorage,
partMatch,
toBoolean,
toSeconds,
updateSize
} from '@uploadx/core';
Expand Down Expand Up @@ -120,7 +121,7 @@ export class S3Storage extends BaseStorage<S3File> {
checksumTypes = ['md5'];
private readonly _partSize = PART_SIZE;

constructor(public config: S3StorageOptions) {
constructor(public config: S3StorageOptions = {}) {
super(config);
this.bucket = config.bucket || process.env.S3_BUCKET || BUCKET_NAME;
const keyFile = config.keyFile || process.env.S3_KEYFILE;
Expand All @@ -132,11 +133,13 @@ export class S3Storage extends BaseStorage<S3File> {
if (this.config.clientDirectUpload) {
this.onCreate = async file => ({ body: file }); // TODO: remove hook
}
this.client = new S3Client(config);
const clientConfig = { ...config };
clientConfig.logger = toBoolean(process.env.S3_DEBUG) ? this.logger : undefined;
this.client = new S3Client(clientConfig);
if (config.metaStorage) {
this.meta = config.metaStorage;
} else {
const metaConfig = { ...config, ...(config.metaStorageConfig || {}), logger: this.logger };
const metaConfig = { ...clientConfig, ...clientConfig.metaStorageConfig };
this.meta =
'directory' in metaConfig
? new LocalMetaStorage(metaConfig)
Expand Down

0 comments on commit 833867f

Please sign in to comment.