Skip to content

Commit a5928f3

Browse files
committed
remove unused dependencies
1 parent a69cb5b commit a5928f3

File tree

3 files changed

+194
-124
lines changed

3 files changed

+194
-124
lines changed

lib/optionsFromArguments.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ const optionsFromArguments = function optionsFromArguments(args) {
4242
} else if (args.length === 2) {
4343
options.bucket = stringOrOptions;
4444
if (typeof args[1] !== 'object') {
45-
throw new Error('Failed to configure S3Adapter. Arguments don\'t make sense');
45+
throw new Error("Failed to configure S3Adapter. Arguments don't make sense");
4646
}
4747
otherOptions = args[1];
4848
} else if (args.length > 2) {
4949
if (typeof args[1] !== 'string' || typeof args[2] !== 'string') {
50-
throw new Error('Failed to configure S3Adapter. Arguments don\'t make sense');
50+
throw new Error("Failed to configure S3Adapter. Arguments don't make sense");
5151
}
5252
options.accessKey = args[0];
5353
options.secretKey = args[1];
@@ -81,7 +81,7 @@ const optionsFromArguments = function optionsFromArguments(args) {
8181
options.bucket = s3overrides.params.Bucket;
8282
}
8383
} else if (args.length > 2) {
84-
throw new Error('Failed to configure S3Adapter. Arguments don\'t make sense');
84+
throw new Error("Failed to configure S3Adapter. Arguments don't make sense");
8585
}
8686

8787
options = fromOptionsDictionaryOrDefault(options, 's3overrides', s3overrides);
@@ -95,9 +95,19 @@ const optionsFromArguments = function optionsFromArguments(args) {
9595
options = fromEnvironmentOrDefault(options, 'baseUrl', 'S3_BASE_URL', null);
9696
options = fromEnvironmentOrDefault(options, 'baseUrlDirect', 'S3_BASE_URL_DIRECT', false);
9797
options = fromEnvironmentOrDefault(options, 'signatureVersion', 'S3_SIGNATURE_VERSION', 'v4');
98-
options = fromEnvironmentOrDefault(options, 'globalCacheControl', 'S3_GLOBAL_CACHE_CONTROL', null);
98+
options = fromEnvironmentOrDefault(
99+
options,
100+
'globalCacheControl',
101+
'S3_GLOBAL_CACHE_CONTROL',
102+
null
103+
);
99104
options = fromEnvironmentOrDefault(options, 'presignedUrl', 'S3_PRESIGNED_URL', false);
100-
options = fromEnvironmentOrDefault(options, 'presignedUrlExpires', 'S3_PRESIGNED_URL_EXPIRES', null);
105+
options = fromEnvironmentOrDefault(
106+
options,
107+
'presignedUrlExpires',
108+
'S3_PRESIGNED_URL_EXPIRES',
109+
null
110+
);
101111
options = fromOptionsDictionaryOrDefault(options, 'generateKey', null);
102112
options = fromOptionsDictionaryOrDefault(options, 'validateFilename', null);
103113

spec/mocks/s3adapter.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const { Readable } = require('stream');
2+
const S3Adapter = require('../../index.js');
3+
const { GetObjectCommand, PutObjectCommand, DeleteObjectCommand } = require('@aws-sdk/client-s3');
4+
5+
function makeS3Adapter(options) {
6+
let s3;
7+
8+
if (
9+
process.env.TEST_S3_ACCESS_KEY &&
10+
process.env.TEST_S3_SECRET_KEY &&
11+
process.env.TEST_S3_BUCKET
12+
) {
13+
// Should be initialized from the env
14+
s3 = new S3Adapter(
15+
Object.assign(
16+
{
17+
accessKey: process.env.TEST_S3_ACCESS_KEY,
18+
secretKey: process.env.TEST_S3_SECRET_KEY,
19+
bucket: process.env.TEST_S3_BUCKET,
20+
region: process.env.TEST_S3_REGION,
21+
},
22+
options
23+
)
24+
);
25+
} else {
26+
const bucket = 'FAKE_BUCKET';
27+
const region = 'us-east-1';
28+
29+
s3 = new S3Adapter('FAKE_ACCESS_KEY', 'FAKE_SECRET_KEY', bucket, options);
30+
31+
const objects = {};
32+
33+
s3._s3Client = {
34+
send: command => {
35+
if (command instanceof PutObjectCommand) {
36+
const { Key, Body } = command.input;
37+
38+
objects[Key] = Body;
39+
40+
return Promise.resolve({
41+
Location: `https://${bucket}.s3.${region}.amazonaws.com/${Key}`,
42+
});
43+
}
44+
if (command instanceof DeleteObjectCommand) {
45+
const { Key } = command.input;
46+
47+
delete objects[Key];
48+
49+
return Promise.resolve({});
50+
}
51+
if (command instanceof GetObjectCommand) {
52+
const { Key } = command.input;
53+
54+
if (objects[Key]) {
55+
const stream = new Readable();
56+
stream.push('hello world');
57+
stream.push(null); // End of stream
58+
59+
return {
60+
Body: stream,
61+
AcceptRanges: 'bytes',
62+
ContentLength: 36,
63+
ContentRange: 'bytes 0-35/36',
64+
ContentType: 'text/plain',
65+
};
66+
} else {
67+
return Promise.reject(new Error('Not found'));
68+
}
69+
}
70+
return Promise.resolve();
71+
},
72+
};
73+
}
74+
return s3;
75+
}
76+
77+
module.exports = {makeS3Adapter}

0 commit comments

Comments
 (0)