v1.0.2: improve docs and error messages

This commit is contained in:
AJ ONeal 2020-03-16 19:58:31 -06:00
parent b5a06a587f
commit 857a7aa76c
7 changed files with 19 additions and 9 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.env .env
.env*
node_modules node_modules
.*.sw* .*.sw*

View File

@ -17,6 +17,14 @@ s3.set({
bucket, bucket,
prefix, prefix,
key, key,
body body,
size
}) })
``` ```
If the body is a stream then `size` must be set to `fs.statSync(filePath).size`, or the request will fail:
```
501
<Code>NotImplemented</Code><Message>A header you provided implies functionality that is not implemented</Message>
```

View File

@ -4,7 +4,7 @@ require('dotenv').config();
var env = process.env; var env = process.env;
var s3 = require('../index.js'); var s3 = require('../index.js');
var accessKeyId = env.AWS_ACCESS_KEY; var accessKeyId = env.AWS_ACCESS_KEY || env.AWS_ACCESS_KEY_ID;
var secretAccessKey = env.AWS_SECRET_ACCESS_KEY; var secretAccessKey = env.AWS_SECRET_ACCESS_KEY;
var region = env.AWS_REGION; var region = env.AWS_REGION;
var bucket = env.AWS_BUCKET; var bucket = env.AWS_BUCKET;
@ -36,11 +36,12 @@ async function run() {
}) })
.catch(function(err) { .catch(function(err) {
console.error('Error:'); console.error('Error:');
console.error('GET Response:');
if (err.response) { if (err.response) {
console.error(err.url);
console.error('GET Response:');
console.error(err.response.statusCode); console.error(err.response.statusCode);
console.error(err.response.headers); console.error(err.response.headers);
console.error(err.url); console.error(err.response.body.toString('utf8'));
} else { } else {
console.error(err); console.error(err);
} }

View File

@ -28,8 +28,8 @@ module.exports = {
} }
*/ */
/* /*
if (env.AWS_ACCESS_KEY) { if (env.AWS_ACCESS_KEY || env.AWS_ACCESS_KEY_ID) {
accessKeyId = accessKeyId || env.AWS_ACCESS_KEY; accessKeyId = accessKeyId || env.AWS_ACCESS_KEY || env.AWS_ACCESS_KEY_ID;
secretAccessKey = secretAccessKey || env.AWS_SECRET_ACCESS_KEY; secretAccessKey = secretAccessKey || env.AWS_SECRET_ACCESS_KEY;
bucket = bucket || env.AWS_BUCKET; bucket = bucket || env.AWS_BUCKET;
prefix = prefix || env.AWS_BUCKET_PREFIX; prefix = prefix || env.AWS_BUCKET_PREFIX;

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@root/s3", "name": "@root/s3",
"version": "1.0.1", "version": "1.0.2",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@root/s3", "name": "@root/s3",
"version": "1.0.1", "version": "1.0.2",
"description": "A simple, lightweight s3 client with only 2 dependencies", "description": "A simple, lightweight s3 client with only 2 dependencies",
"main": "index.js", "main": "index.js",
"files": [ "files": [

View File

@ -4,7 +4,7 @@ require('dotenv').config();
var env = process.env; var env = process.env;
var s3 = require('./index.js'); var s3 = require('./index.js');
var accessKeyId = env.AWS_ACCESS_KEY; var accessKeyId = env.AWS_ACCESS_KEY || env.AWS_ACCESS_KEY_ID;
var secretAccessKey = env.AWS_SECRET_ACCESS_KEY; var secretAccessKey = env.AWS_SECRET_ACCESS_KEY;
var region = env.AWS_REGION; var region = env.AWS_REGION;
var bucket = env.AWS_BUCKET; var bucket = env.AWS_BUCKET;