Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@edenjs/b2

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@edenjs/b2 - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

64

bundles/backblaze/transports/b2.js

@@ -30,8 +30,9 @@ // Require base

// Get bucket
this._setBucket();
}
async _setBucket() {
this.bucket = new Promise(async (res) => {
// authorize
await this.store.authorize();
// resolve got bucket
res(await this.store.getBucket({

@@ -41,4 +42,20 @@ bucketName : config.get('b2.bucket'),

});
// so re-calls to this method can know the process has finished
await this.bucket;
}
async _safeExec(cb, times = 0) {
try {
return await cb();
} catch (err) {
if (err.response.status === 401 && times < (config.get('b2.authRetries') || 5)) {
await this._setBucket();
return await this._safeExec(cb, times + 1);
} else {
throw err;
}
}
}
/**

@@ -75,5 +92,7 @@ * Gets asset url

// get upload url
const uploadUrl = await this.store.getUploadUrl({
bucketId : bucket.data.buckets[0].bucketId,
});
const uploadUrl = await this._safeExec(async () => {
return await this.store.getUploadUrl({
bucketId : bucket.data.buckets[0].bucketId,
});
})

@@ -87,14 +106,15 @@ // Augment date

// await
const { data } = (await this.store.uploadFile({
data : await fs.readFile(tmp), // this is expecting a Buffer, not an encoded string
fileName : `${asset.get('path')}/${label ? `${label}.${asset.get(`thumbs.${label}.ext`)}` : `full.${asset.get('ext')}`}`,
uploadUrl : uploadUrl.data.uploadUrl,
uploadAuthToken : uploadUrl.data.authorizationToken,
info : {
str : date,
hash : asset.get('hash'),
},
onUploadProgress : () => {}, // progress monitoring
// ...common arguments (optional)
}));
const { data } = await this._safeExec(async () => {
return await this.store.uploadFile({
data : await fs.readFile(tmp), // this is expecting a Buffer, not an encoded string
fileName : `${asset.get('path')}/${label ? `${label}.${asset.get(`thumbs.${label}.ext`)}` : `full.${asset.get('ext')}`}`,
uploadUrl : uploadUrl.data.uploadUrl,
uploadAuthToken : uploadUrl.data.authorizationToken,
info : {
str : date,
hash : asset.get('hash'),
},
onUploadProgress : () => {},
});
});

@@ -138,5 +158,7 @@ // set b2 info

// delete file version
await this.store.deleteFileVersion({
fileId : asset.get(`${label ? `thumbs.${label}.` : ''}b2.fileId`),
fileName : `${asset.get('path')}/${label ? `${label}.${asset.get(`thumbs.${label}.ext`)}` : `full.${asset.get('ext')}`}`,
await this._safeExec(async () => {
return await this.store.deleteFileVersion({
fileId : asset.get(`${label ? `thumbs.${label}.` : ''}b2.fileId`),
fileName : `${asset.get('path')}/${label ? `${label}.${asset.get(`thumbs.${label}.ext`)}` : `full.${asset.get('ext')}`}`,
});
});

@@ -143,0 +165,0 @@ }

{
"name": "@edenjs/b2",
"description": "nothing yet",
"version": "1.0.5",
"version": "1.0.6",
"dependencies": {

@@ -6,0 +6,0 @@ "backblaze-b2": "^1.3.1"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc