diff --git a/dist/main.js b/dist/main.js index 8ce4f21..eeb8102 100644 --- a/dist/main.js +++ b/dist/main.js @@ -13,6 +13,7 @@ const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const sharp = require("sharp"); const mime_types_1 = require("mime-types"); +const stream_1 = require("stream"); const get_sharp_options_1 = require("./get-sharp-options"); const transformer_1 = require("./transformer"); const get_filename_1 = require("./get-filename"); @@ -85,10 +86,10 @@ class S3Storage { .pipe(operators_1.map((size) => { const resizerStream = transformer_1.default(sharpOpts, size); if (size.suffix === 'original') { - size.Body = stream.pipe(sharp()); + size.Body = stream.pipe(sharp().clone()); } else { - size.Body = stream.pipe(resizerStream); + size.Body = stream.pipe(resizerStream.clone()); } return size; }), operators_1.mergeMap((size) => { @@ -101,8 +102,9 @@ class S3Storage { })); }), operators_1.mergeMap((size) => { const { Body, ContentType } = size; - let newParams = Object.assign({}, params, { Body, - ContentType, Key: `${params.Key}-${size.suffix}` }); + const streamCopy = new stream_1.PassThrough(); + Body.pipe(streamCopy); + let newParams = Object.assign({}, params, { Body: streamCopy, ContentType, Key: `${params.Key}-${size.suffix}` }); const upload = opts.s3.upload(newParams); let currentSize = { [size.suffix]: 0 }; upload.on('httpUploadProgress', function (ev) { diff --git a/dist/main.js.map b/dist/main.js.map index de780c0..27c76a8 100644 --- a/dist/main.js.map +++ b/dist/main.js.map @@ -1 +1 @@ -{"version":3,"file":"main.js","sourceRoot":"src/","sources":["main.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+BAA2B;AAC3B,8CAAuD;AACvD,+BAA8B;AAC9B,2CAAmC;AAKnC,2DAAiD;AACjD,+CAAuC;AACvC,iDAAuC;AAmBvC,MAAa,SAAS;IAQpB,YAAY,OAAyB;QACnC,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;SAC9D;QAED,IAAI,CAAC,IAAI,qBAAQ,SAAS,CAAC,cAAc,EAAK,OAAO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,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACrC,MAAM,CAAC,EAAE,CAAC,oBAAoB,EAAE,UAAS,EAAE;YACzC,IAAI,EAAE,CAAC,KAAK,EAAE;gBACZ,WAAW,GAAG,EAAE,CAAC,KAAK,CAAA;aACvB;QACH,CAAC,CAAC,CAAA;QACF,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAC/B,MAAM,MAAM,mBACV,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,IAAI,CAAC,GAAG,EACb,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,QAAQ,EACzC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,EAC3C,YAAY,EAAE,IAAI,CAAC,YAAY,EAC/B,oBAAoB,EAAE,IAAI,CAAC,oBAAoB,EAC/C,QAAQ,EAAE,IAAI,CAAC,QAAQ,IACpB,MAAM,CACV,CAAA;YACD,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QAC9C,CAAC,EAAE,EAAE,CAAC,CAAA;IACR,CAAC;;AAvPgB,wBAAc,GAAG;IAChC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,aAAa;IACzC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,IAAI;IACtC,GAAG,EAAE,sBAAU;IACf,QAAQ,EAAE,KAAK;CAChB,CAAA;AANH,8BAyPC;AAED,SAAS,SAAS,CAAC,OAAyB;IAC1C,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC;AAED,kBAAe,SAAS,CAAA"} \ No newline at end of file diff --git a/dist/types/main.d.ts.map b/dist/types/main.d.ts.map index f3cbb2c..e5fd0f5 100644 --- a/dist/types/main.d.ts.map +++ b/dist/types/main.d.ts.map @@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AO,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,IAAI,KAAK,IAAI;IAsC7E,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI;IAIvE,OAAO,CAAC,cAAc;IAoJtB,OAAO,CAAC,eAAe;CA6BxB;AAED,iBAAS,SAAS,CAAC,OAAO,EAAE,gBAAgB,aAE3C;AAED,eAAe,SAAS,CAAA"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c2906e4..0bf93dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2360,6 +2360,12 @@ "is-obj": "^1.0.0" } }, + "dotenv": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", + "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==", + "dev": true + }, "dotgitignore": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/dotgitignore/-/dotgitignore-2.1.0.tgz", diff --git a/package.json b/package.json index f90d5cf..963de68 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "@types/supertest": "^2.0.7", "aws-sdk": "^2.445.0", "codecov": "^3.7.0", + "dotenv": "^8.2.0", "express": "^4.16.4", "jest": "^24.0.12", "multer": "^1.4.1", diff --git a/src/main.ts b/src/main.ts index f297b7f..9672d2b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import { ManagedUpload } from 'aws-sdk/lib/s3/managed_upload' import { StorageEngine } from 'multer' import { Request } from 'express' import { S3 } from 'aws-sdk' +import { PassThrough } from 'stream' import getSharpOptions from './get-sharp-options' import transformer from './transformer' import defaultKey from './get-filename' @@ -121,9 +122,9 @@ export class S3Storage implements StorageEngine { map((size) => { const resizerStream = transformer(sharpOpts, size) if (size.suffix === 'original') { - size.Body = stream.pipe(sharp()) + size.Body = stream.pipe(sharp().clone()) } else { - size.Body = stream.pipe(resizerStream) + size.Body = stream.pipe(resizerStream.clone()) } return size }), @@ -145,9 +146,11 @@ export class S3Storage implements StorageEngine { }), mergeMap((size) => { const { Body, ContentType } = size + const streamCopy = new PassThrough() + Body.pipe(streamCopy) let newParams = { ...params, - Body, + Body: streamCopy, ContentType, Key: `${params.Key}-${size.suffix}`, }