Skip to content

Commit

Permalink
fix: fallback to fs
Browse files Browse the repository at this point in the history
  • Loading branch information
korostelevm committed Jan 18, 2023
1 parent 3ab0f58 commit eb1abb2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
23 changes: 16 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,24 @@ class CyclicS3FS extends CyclicS3FSPromises {
}


const client = function(bucketName, config={}){
if(!process.env.AWS_SECRET_ACCESS_KEY){
console.warn('[s3fs] WARNING: AWS credentials are not set. Using local file system')
return fs
var client = new CyclicS3FS()
class FSFallback extends Function{
constructor() {
super('...args', 'return this._bound._call(...args)')
this._bound = this.bind(this)
Object.assign(this._bound,{...fs})
return this._bound
}
_call() {
let client = new FSFallback()
return client
}
return new CyclicS3FS(bucketName, config)
}

if(!process.env.AWS_SECRET_ACCESS_KEY){
console.warn('[s3fs] WARNING: AWS credentials are not set. Using local file system')
client = new FSFallback()
}



module.exports = new CyclicS3FS()
module.exports = client
28 changes: 19 additions & 9 deletions src/promises.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
const fs = require('fs/promises')
const CyclicS3FSPromises = require('./CyclicS3FSPromises')
// const client = function(bucketName, config={}){
// if(!process.env.AWS_SECRET_ACCESS_KEY){
// console.warn('[s3fs] WARNING: AWS credentials are not set. Using local file system')
// return fs
// }
// return new CyclicS3FSPromises(bucketName, config)
// }
var client = new CyclicS3FSPromises()
class FSPromisesFallback extends Function{
constructor() {
super('...args', 'return this._bound._call(...args)')
this._bound = this.bind(this)
Object.assign(this._bound,{...fs})
return this._bound
}
_call() {
let client = new FSPromisesFallback()
return client
}
}

// module.exports = client
module.exports = new CyclicS3FSPromises()
if(!process.env.AWS_SECRET_ACCESS_KEY){
console.warn('[s3fs] WARNING: AWS credentials are not set. Using local file system')
client = new FSPromisesFallback()
}

module.exports = client

0 comments on commit eb1abb2

Please sign in to comment.