From dfb5092d109671b1a58b2cd2ad9b62b359e211d8 Mon Sep 17 00:00:00 2001 From: Edmund Mai Date: Sun, 28 Oct 2018 16:17:05 +0700 Subject: [PATCH 1/6] adds tests for file processor --- src/utils/file-processor.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/utils/file-processor.test.js diff --git a/src/utils/file-processor.test.js b/src/utils/file-processor.test.js new file mode 100644 index 0000000..d7966a7 --- /dev/null +++ b/src/utils/file-processor.test.js @@ -0,0 +1,12 @@ +import * as fileProcessor from "./file-processor.js"; + +test("createMetaData", () => { + const fileName = "foobar.txt"; + const numberOfChunks = 10; + + expect(fileProcessor.createMetaData(fileName, numberOfChunks)).toEqual({ + fileName: "foobar.txt", + ext: "txt", + numberOfChunks + }); +}); From 210ee31c5c6f51dd481ab376b43892d5861eca50 Mon Sep 17 00:00:00 2001 From: Edmund Mai Date: Sun, 28 Oct 2018 16:18:45 +0700 Subject: [PATCH 2/6] refactor method --- src/upload.js | 5 ++++- src/utils/file-processor.js | 2 +- src/utils/file-processor.test.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/upload.js b/src/upload.js index 5c00501..ca61696 100644 --- a/src/upload.js +++ b/src/upload.js @@ -125,7 +125,10 @@ 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 + }); 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..4b6f6e9 100644 --- a/src/utils/file-processor.js +++ b/src/utils/file-processor.js @@ -1,4 +1,4 @@ -export function createMetaData(fileName, numberOfChunks) { +export function createMetaData({ fileName, numberOfChunks }) { const fileExtension = fileName.split(".").pop(); const meta = { diff --git a/src/utils/file-processor.test.js b/src/utils/file-processor.test.js index d7966a7..59acfdb 100644 --- a/src/utils/file-processor.test.js +++ b/src/utils/file-processor.test.js @@ -4,7 +4,7 @@ test("createMetaData", () => { const fileName = "foobar.txt"; const numberOfChunks = 10; - expect(fileProcessor.createMetaData(fileName, numberOfChunks)).toEqual({ + expect(fileProcessor.createMetaData({ fileName, numberOfChunks })).toEqual({ fileName: "foobar.txt", ext: "txt", numberOfChunks From bda76c8d8bf2ec8fb04d7b78eb7ee65bab0d0199 Mon Sep 17 00:00:00 2001 From: Edmund Mai Date: Sun, 28 Oct 2018 16:20:41 +0700 Subject: [PATCH 3/6] adds alpha and beta to metadata --- src/upload.js | 2 ++ src/utils/file-processor.js | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/upload.js b/src/upload.js index ca61696..aae2b81 100644 --- a/src/upload.js +++ b/src/upload.js @@ -126,6 +126,8 @@ export default class Upload extends EventEmitter { this.filename = filename; this.handle = createHandle(filename); this.metadata = createMetaData({ + alpha, + beta, fileName: filename, numberOfChunks: chunkCount }); diff --git a/src/utils/file-processor.js b/src/utils/file-processor.js index 4b6f6e9..5ea50b3 100644 --- a/src/utils/file-processor.js +++ b/src/utils/file-processor.js @@ -1,9 +1,11 @@ -export function createMetaData({ fileName, numberOfChunks }) { +export function createMetaData({ fileName, numberOfChunks, alpha, beta }) { const fileExtension = fileName.split(".").pop(); const meta = { - fileName: fileName.substr(0, 500), + alpha, + beta, ext: fileExtension, + fileName: fileName.substr(0, 500), numberOfChunks }; From b0db3e0ca82417721401080db1c3809ebf05d4c5 Mon Sep 17 00:00:00 2001 From: Edmund Mai Date: Sun, 28 Oct 2018 16:22:11 +0700 Subject: [PATCH 4/6] adds local prettier config --- .prettierrc.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .prettierrc.json 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 +} From 010215a263fa9876ebd5d8db4ae547d8e969f8d3 Mon Sep 17 00:00:00 2001 From: Edmund Mai Date: Tue, 30 Oct 2018 00:09:29 +0700 Subject: [PATCH 5/6] Revert "adds alpha and beta to metadata" This reverts commit bda76c8d8bf2ec8fb04d7b78eb7ee65bab0d0199. --- src/upload.js | 2 -- src/utils/file-processor.js | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/upload.js b/src/upload.js index aae2b81..ca61696 100644 --- a/src/upload.js +++ b/src/upload.js @@ -126,8 +126,6 @@ export default class Upload extends EventEmitter { this.filename = filename; this.handle = createHandle(filename); this.metadata = createMetaData({ - alpha, - beta, fileName: filename, numberOfChunks: chunkCount }); diff --git a/src/utils/file-processor.js b/src/utils/file-processor.js index 5ea50b3..4b6f6e9 100644 --- a/src/utils/file-processor.js +++ b/src/utils/file-processor.js @@ -1,11 +1,9 @@ -export function createMetaData({ fileName, numberOfChunks, alpha, beta }) { +export function createMetaData({ fileName, numberOfChunks }) { const fileExtension = fileName.split(".").pop(); const meta = { - alpha, - beta, - ext: fileExtension, fileName: fileName.substr(0, 500), + ext: fileExtension, numberOfChunks }; From 720cdae2bcc3f033593117b516404ad577ea2f32 Mon Sep 17 00:00:00 2001 From: Edmund Mai Date: Thu, 1 Nov 2018 14:44:23 +0700 Subject: [PATCH 6/6] adds custom params --- src/upload.js | 3 ++- src/utils/file-processor.js | 5 +++-- src/utils/file-processor.test.js | 20 ++++++++++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/upload.js b/src/upload.js index ca61696..a731c1d 100644 --- a/src/upload.js +++ b/src/upload.js @@ -127,7 +127,8 @@ export default class Upload extends EventEmitter { this.handle = createHandle(filename); this.metadata = createMetaData({ fileName: filename, - numberOfChunks: chunkCount + numberOfChunks: chunkCount, + custom: opts.custom }); this.genesisHash = genesisHash(this.handle); this.key = bytesFromHandle(this.handle); diff --git a/src/utils/file-processor.js b/src/utils/file-processor.js index 4b6f6e9..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 index 59acfdb..f8f99c9 100644 --- a/src/utils/file-processor.test.js +++ b/src/utils/file-processor.test.js @@ -1,12 +1,28 @@ import * as fileProcessor from "./file-processor.js"; -test("createMetaData", () => { +test("createMetaData without custom params", () => { const fileName = "foobar.txt"; const numberOfChunks = 10; expect(fileProcessor.createMetaData({ fileName, numberOfChunks })).toEqual({ fileName: "foobar.txt", ext: "txt", - numberOfChunks + 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 }); });