Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitsinghal624 committed Aug 2, 2021
0 parents commit 110a033
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
96 changes: 96 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
############################
# OS X
############################

.DS_Store
.AppleDouble
.LSOverride
Icon
.Spotlight-V100
.Trashes
._*


############################
# Linux
############################

*~


############################
# Windows
############################

Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msm
*.msp


############################
# Packages
############################

*.7z
*.csv
*.dat
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.com
*.class
*.dll
*.exe
*.o
*.seed
*.so
*.swo
*.swp
*.swn
*.swm
*.out
*.pid


############################
# Logs and databases
############################

.tmp
*.log
*.sql
*.sqlite


############################
# Misc.
############################

*#
.idea
nbproject


############################
# Node.js
############################

lib-cov
lcov.info
pids
logs
results
build
node_modules
.node_history
package-lock.json

109 changes: 109 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
############################
# OS X
############################

.DS_Store
.AppleDouble
.LSOverride
Icon
.Spotlight-V100
.Trashes
._*


############################
# Linux
############################

*~


############################
# Windows
############################

Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msm
*.msp


############################
# Packages
############################

*.7z
*.csv
*.dat
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.com
*.class
*.dll
*.exe
*.o
*.seed
*.so
*.swo
*.swp
*.swn
*.swm
*.out
*.pid


############################
# Logs and databases
############################

.tmp
*.log
*.sql
*.sqlite


############################
# Misc.
############################

*#
ssl
.editorconfig
.gitattributes
.idea
nbproject


############################
# Node.js
############################

lib-cov
lcov.info
pids
logs
results
build
node_modules
.node_history
.snyk



############################
# Tests
############################

test
tests
__tests__
jest.config.js
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Small modification to [strapi-provider-upload-aws-s3](https://www.npmjs.com/package/strapi-provider-upload-aws-s3) to support an optional baseUrl configuration.
If `baseUrl` is not specified, it works the same as the official aws-s3 plugin.

Original source is [here](https://github.com/strapi/strapi/tree/master/packages/strapi-provider-upload-aws-s3).

package.json:

```
{
//...
"dependencies": {
//...
"strapi-provider-upload-aws-s3": "npm:@chakrahq/strapi-provider-upload-aws-s3@3.6.5",
//...
},
// ...
}
```

config/plugins.js:

```
module.exports = ({ env }) => {
//...
upload: {
provider: 'aws-s3',
providerOptions: {
accessKeyId: env('AWS_S3_KEY'),
secretAccessKey: env('AWS_S3_SECRET'),
region: env('AWS_S3_REGION'),
params: {
Bucket: env('AWS_S3_BUCKET'),
},
baseUrl: env('AWS_S3_CDN')
},
},
//...
};
```

Note:
`baseUrl` param should be a full URL without a trailing slash.
Example: `https://cdn.example.com`
72 changes: 72 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'use strict'

/**
* References:
* - https://strapi.io/documentation/developer-docs/latest/development/plugins/upload.html#create-providers
* - https://github.com/strapi/strapi/tree/master/packages/strapi-provider-upload-aws-s3
*/

/**
* Module dependencies
*/

const AWS = require('aws-sdk');

module.exports = {
init(config) {
const S3 = new AWS.S3({
apiVersion: '2006-03-01',
...config,
});

return {
upload(file, customParams = {}) {
return new Promise((resolve, reject) => {
// upload file on S3 bucket
const path = file.path ? `${file.path}/` : '';
S3.upload(
{
Key: `${path}${file.hash}${file.ext}`,
Body: Buffer.from(file.buffer, 'binary'),
ACL: 'public-read',
ContentType: file.mime,
...customParams,
},
(err, data) => {
if (err) {
return reject(err);
}

// set the bucket file url
if (config.baseUrl) {
file.url = `${config.baseUrl}/${data.Key}`;
} else {
file.url = data.Location;
}

resolve();
}
);
});
},
delete(file, customParams = {}) {
return new Promise((resolve, reject) => {
// delete file on S3 bucket
const path = file.path ? `${file.path}/` : '';
S3.deleteObject(
{
Key: `${path}${file.hash}${file.ext}`,
...customParams,
},
(err) => {
if (err) {
return reject(err);
}
resolve();
}
);
});
},
};
},
};
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@chakrahq/strapi-provider-upload-aws-s3",
"version": "0.1.0",
"description": "AWS S3 provider for strapi upload, with additional optional features over the official AWS S3 provider",
"keywords": [
"upload",
"aws",
"s3",
"strapi"
],
"directories": {
"lib": "./lib"
},
"main": "./lib",
"dependencies": {
"aws-sdk": "^2.892.0"
},
"strapi": {
"isProvider": true
},
"engines": {
"node": ">=10.16.0 <=14.x.x",
"npm": ">=6.0.0"
},
"scripts": {
"test": "echo \"no tests yet\""
},
"repository": {
"type": "git",
"url": "git://github.com/chakrahq/strapi-provider-upload-aws-s3.git"
}
}

0 comments on commit 110a033

Please sign in to comment.