-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 110a033
Showing
6 changed files
with
368 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
); | ||
}); | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |