diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..fca24df --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "trailingComma": "none", + "tabWidth": 2, + "semi": true, + "singleQuote": false +} diff --git a/src/upload.js b/src/upload.js index 5c00501..a731c1d 100644 --- a/src/upload.js +++ b/src/upload.js @@ -125,7 +125,11 @@ export default class Upload extends EventEmitter { this.options = opts; this.filename = filename; this.handle = createHandle(filename); - this.metadata = createMetaData(filename, chunkCount); + this.metadata = createMetaData({ + fileName: filename, + numberOfChunks: chunkCount, + custom: opts.custom + }); this.genesisHash = genesisHash(this.handle); this.key = bytesFromHandle(this.handle); this.numberOfChunks = totalChunks; diff --git a/src/utils/file-processor.js b/src/utils/file-processor.js index 868752e..fdcc26b 100644 --- a/src/utils/file-processor.js +++ b/src/utils/file-processor.js @@ -1,10 +1,11 @@ -export function createMetaData(fileName, numberOfChunks) { +export function createMetaData({ fileName, numberOfChunks, custom }) { const fileExtension = fileName.split(".").pop(); const meta = { fileName: fileName.substr(0, 500), ext: fileExtension, - numberOfChunks + numberOfChunks, + custom: custom || {} }; return meta; diff --git a/src/utils/file-processor.test.js b/src/utils/file-processor.test.js new file mode 100644 index 0000000..f8f99c9 --- /dev/null +++ b/src/utils/file-processor.test.js @@ -0,0 +1,28 @@ +import * as fileProcessor from "./file-processor.js"; + +test("createMetaData without custom params", () => { + const fileName = "foobar.txt"; + const numberOfChunks = 10; + + expect(fileProcessor.createMetaData({ fileName, numberOfChunks })).toEqual({ + fileName: "foobar.txt", + ext: "txt", + numberOfChunks, + custom: {} + }); +}); + +test("createMetaData with custom params", () => { + const fileName = "foobar.txt"; + const numberOfChunks = 10; + const custom = { foo: "bar" }; + + expect( + fileProcessor.createMetaData({ fileName, numberOfChunks, custom }) + ).toEqual({ + fileName: "foobar.txt", + ext: "txt", + numberOfChunks, + custom + }); +});