diff --git a/package.json b/package.json index ddd7631..b73cd2e 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "jest": "^26.0.1" }, "dependencies": { - "aws-sdk": "^2.989.0", + "aws-sdk": "=2.1311.0", "axios": "^0.21.1", "multiformats": "^9.4.7", "s3-streaming-upload": "^0.3.4" diff --git a/utils/stream-upload.js b/utils/stream-upload.js index fdb6e0c..86c6ab5 100644 --- a/utils/stream-upload.js +++ b/utils/stream-upload.js @@ -11,27 +11,31 @@ const streamUploadFile = (s3, params) => (new Promise((resolve, reject) => { }); request.send((err, data) => { - if (err) { - reject(err); - } - const { ETag } = data; + try { + if (err) { + reject(err); + } + const { ETag } = data; - const hash = ETag.replace(/^"|"$/g, ''); + const hash = ETag.replace(/^"|"$/g, ''); - const cidObj = CID.parse(hash); - - let cidv0; - - const cidv1 = cidObj.toV1().toString(); + const cidObj = CID.parse(hash); + + let cidv0; + + const cidv1 = cidObj.toV1().toString(); - try { - cidv0 = cidObj.toV0().toString(); + try { + cidv0 = cidObj.toV0().toString(); + } catch (e) { + // fallback when cbor is used + cidv0 = cidv1; + } + + resolve ({ hash: cidv1, hashV0: cidv0 }); } catch (e) { - // fallback when cbor is used - cidv0 = cidv1; + reject(e); } - - resolve ({ hash: cidv1, hashV0: cidv0 }); }); }));