Skip to content

Commit

Permalink
Fix save renders into S3
Browse files Browse the repository at this point in the history
  • Loading branch information
steevepay committed May 21, 2024
1 parent f68d735 commit ab7420a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.4.1
- Released the 2024/05/21
- Fixed: Generated documents are saved in S3 even if the `reportName` rendering option is not provided. It was throwing the error: `Status: 409 | Body: BucketAlreadyOwnedByYou`. Now, the document filename is the Render ID.

## 1.4.0
- Released the 2024/04/30
- S3 Bucket Connection is not listing Buckets anymore, but only verifying if `templatesBucket` and `rendersBucket` are accessible with a `HEAD /bucket` request. If options `BUCKET_TEMPLATES/templatesBucket` or `BUCKET_RENDER/rendersBucket` are missing, it won't try to connect.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "carbone-ee-plugin-s3",
"version": "1.4.0",
"version": "1.4.1",
"description": "S3 Plugin for Carbone On-premise & On-AWS (carbone-ee) ",
"main": "null",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ function afterRender (req, res, err, reportPath, reportName, stats, callback) {
if (!config.getConfig()?.rendersBucket) {
return callback();
}
s3.uploadFile(config.getConfig().rendersBucket, reportName, reportPath, (err, resp) => {
const _filename = reportName && reportName?.length > 0 ? reportName : path.basename(reportPath);
s3.uploadFile(config.getConfig().rendersBucket, _filename, reportPath, (err, resp) => {
if (err) {
return callback(err);
}
Expand Down
12 changes: 12 additions & 0 deletions test/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ describe('Storage', function () {
});
});

it('should save a generated doccument into the Renders Bucket even if the filename is not provided', function(done) {
const _expectedFilename = path.basename(pathFileTxt);
nock(url1S3)
.put(uri => uri.includes(`/${_rendersBucket}/${_expectedFilename}`))
.reply(200);

storage.afterRender({}, {}, null, pathFileTxt, '', {}, (err) => {
assert.strictEqual(err, undefined);
done();
});
});

it('should return an error if the rendering failled', function(done) {
storage.afterRender({}, {}, new Error('Something went wrong'), pathFileTxt, _renderName, {}, (err) => {
assert.strictEqual(err.toString(), 'Error: Something went wrong');
Expand Down

0 comments on commit ab7420a

Please sign in to comment.