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

catbox-s3

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

catbox-s3 - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

55

lib/index.js
'use strict';
// Load modules
const Wreck = require('wreck');
const Hoek = require('hoek');

@@ -36,9 +35,9 @@ const AWS = require('aws-sdk');

internals.parseBody = function (res, body) {
internals.parseBody = function (contentType, body) {
if (res.headers['content-type'] === 'text/plain' && Buffer.isBuffer(body)) {
if (contentType === 'text/plain' && Buffer.isBuffer(body)) {
body = body.toString();
}
if (res.headers['content-type'] === 'application/json') {
if (contentType === 'application/json') {
/* eslint-disable brace-style */

@@ -55,13 +54,16 @@ try {

internals.testBucketAccess = function (client, bucket, callback) {
internals.testBucketAccess = function (client, settings, callback) {
const putParams = {
Bucket : bucket,
Bucket : settings.bucket,
Key : internals.getStoragePathForKey({ segment: 'catbox-s3', id: 'accesstest' }),
ACL : 'public-read',
Body : 'ok'
};
if (settings.setACL !== false) {
putParams.ACL = settings.ACL ? settings.ACL : 'public-read';
}
const getParams = {
Bucket : bucket,
Bucket : settings.bucket,
Key : internals.getStoragePathForKey({ segment: 'catbox-s3', id: 'accesstest' })

@@ -72,7 +74,7 @@ };

Hoek.assert(!err, `Error writing to bucket ${bucket}`);
Hoek.assert(!err, `Error writing to bucket ${settings.bucket} ${err}`);
client.getObject(getParams, (err, data) => {
Hoek.assert(!err && data.Body.toString('utf8') === 'ok', `Error reading from bucket ${bucket}`);
Hoek.assert(!err && data.Body.toString('utf8') === 'ok', `Error reading from bucket ${settings.bucket} ${err}`);
callback();

@@ -109,5 +111,9 @@ });

if (this.settings.endpoint) {
clientOptions.endpoint = this.settings.endpoint;
}
this.client = new AWS.S3(clientOptions);
internals.testBucketAccess(this.client, this.settings.bucket, (err, data) => {
internals.testBucketAccess(this.client, this.settings, (err, data) => {

@@ -164,15 +170,10 @@ if (err) {

const baseUrl = this.settings.region ?
`http://s3-${this.settings.region}.amazonaws.com/` :
'http://s3.amazonaws.com/';
const params = {
Bucket : this.settings.bucket,
Key : internals.getStoragePathForKey(key)
};
const url = `${baseUrl}${this.settings.bucket}/${internals.getStoragePathForKey(key)}`;
this.client.getObject(params, (err, data) => {
Wreck.get(url, (err, res, body) => {
if (err) {
return callback(err);
}
if (res.statusCode !== 200) {
return callback(null, null);

@@ -182,4 +183,4 @@ }

const now = new Date().getTime();
const stored = new Date(res.headers['x-amz-meta-catbox-stored']);
let ttl = Number(res.headers['x-amz-meta-catbox-ttl']) || 0;
const stored = new Date(data.Metadata['catbox-stored']);
let ttl = Number(data.Metadata['catbox-ttl']) || 0;

@@ -195,3 +196,3 @@ // Calculate remaining ttl

const result = {
item : internals.parseBody(res, body),
item : internals.parseBody(data.ContentType, data.Body),
stored : stored,

@@ -202,2 +203,3 @@ ttl : ttl

callback(null, result);
});

@@ -234,3 +236,2 @@ };

Key : internals.getStoragePathForKey(key),
ACL : 'public-read',
Expires : new Date(now.getTime() + ttl),

@@ -241,2 +242,6 @@ ContentType : type,

if (this.settings.setACL !== false) {
params.ACL = this.settings.ACL ? this.settings.ACL : 'public-read';
}
const req = this.client.putObject(params);

@@ -243,0 +248,0 @@ req.on('build', () => {

{
"name": "catbox-s3",
"description": "Amazon S3 adapter for catbox",
"version": "2.0.0",
"version": "2.1.0",
"author": "Frederic Hemberger (https://frederic-hemberger.de)",

@@ -35,4 +35,3 @@ "main": "index.js",

"aws-sdk": "2.4.x",
"hoek": "4.x.x",
"wreck": "9.x.x"
"hoek": "4.x.x"
},

@@ -39,0 +38,0 @@ "devDependencies": {

@@ -13,2 +13,5 @@ # catbox-s3

- `region` - the Amazon S3 region. (If you don't specify a region, the bucket will be created in US Standard.)
- `endpoint` - the S3 endpoint URL. (If you don't specify an endpoint, the bucket will be created at Amazon S3 using the provided region if any)
- `setACL` - defaults to true, if set to false, not acl is set for the objects
- `ACL` - the ACL to set if setACL is not false, defaults to `public-read`

@@ -29,3 +32,3 @@

secretAccessKey : /* ... */,
region : /* ... */,
region : /* ... (optional) */,
bucket : /* ... */

@@ -32,0 +35,0 @@ });

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