diff --git a/packages/importer/__tests__/__snapshots__/keep.test.js.snap b/packages/importer/__tests__/__snapshots__/keep.test.js.snap new file mode 100644 index 000000000..991d2d515 --- /dev/null +++ b/packages/importer/__tests__/__snapshots__/keep.test.js.snap @@ -0,0 +1,52 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`convert google keep backup: keep-backup 1`] = ` +Array [ + Object { + "content": Object { + "data": "

a simple drawing

", + "type": "html", + }, + "dateEdited": 1629964212062, + "title": "another note", + }, + Object { + "color": "blue", + "content": Object { + "data": "

a simple drawing

", + "type": "html", + }, + "dateEdited": 1629964242424, + "tags": Array [ + "cats", + "run", + ], + "title": "Untitled list 1", + }, + Object { + "color": "red", + "content": Object { + "data": "

a simple drawing

", + "type": "html", + }, + "dateEdited": 1629964346280, + "title": "good place", + }, + Object { + "content": Object { + "data": "

a simple drawing

", + "type": "html", + }, + "dateEdited": 1629964207042, + "title": "hello world", + }, + Object { + "content": Object { + "data": "

a simple drawing

", + "type": "html", + }, + "dateEdited": 1629964316377, + "title": "draw", + }, +] +`; diff --git a/packages/importer/__tests__/__snapshots__/nimbus.test.js.snap b/packages/importer/__tests__/__snapshots__/nimbus.test.js.snap new file mode 100644 index 000000000..d0947bf51 --- /dev/null +++ b/packages/importer/__tests__/__snapshots__/nimbus.test.js.snap @@ -0,0 +1,141 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`convert simplenote backup zip file: nimbus-export 1`] = ` +Array [ + Object { + "content": Object { + "data": "
+
+
This is a new note that I am working on
+
+
", + "type": "html", + }, + "notebooks": Object { + "notebook": "My Notes", + "topic": "My Notes", + }, + "title": "ringing the bell", + }, + Object { + "content": Object { + "data": "
+
+
This is a new note that I am working on
+
+
", + "type": "html", + }, + "notebooks": Object { + "notebook": "My Notes", + "topic": "My Notes", + }, + "title": "Wow", + }, + Object { + "content": Object { + "data": "
+
+
This is a new note that I am working on
+
+
", + "type": "html", + }, + "notebooks": Object { + "notebook": "My Notes", + "topic": "My Notes", + }, + "title": "This is a new day and I am writi", + }, + Object { + "content": Object { + "data": "
+
+
This is a new note that I am working on
+
+
", + "type": "html", + }, + "notebooks": Object { + "notebook": "My Notes", + "topic": "My Notes", + }, + "title": "my note", + }, + Object { + "content": Object { + "data": "
+
+
This is a new note that I am working on
+
+
", + "type": "html", + }, + "notebooks": Object { + "notebook": "Bingo", + "topic": "Bingo", + }, + "title": "Oh okay I am making a note now.", + }, + Object { + "content": Object { + "data": "
+
+
This is a new note that I am working on
+
+
", + "type": "html", + }, + "notebooks": Object { + "notebook": "Bingo", + "topic": "Rope", + }, + "title": "New note", + }, + Object { + "content": Object { + "data": "
+
+
This is a new note that I am working on
+
+
", + "type": "html", + }, + "notebooks": Object { + "notebook": "Bingo", + "topic": "Rope", + }, + "title": "New note", + }, + Object { + "content": Object { + "data": "
+
+
This is a new note that I am working on
+
+
", + "type": "html", + }, + "notebooks": Object { + "notebook": "Bingo", + "topic": "Rope", + }, + "title": "home", + }, + Object { + "content": Object { + "data": "
+
+
This is a new note that I am working on
+
+
", + "type": "html", + }, + "notebooks": Object { + "notebook": "Bingo", + "topic": "Rope", + }, + "title": "This is a new note that I am wor", + }, +] +`; diff --git a/packages/importer/__tests__/fixtures/export-2021-08-27_10-11-56.zip b/packages/importer/__tests__/fixtures/export-2021-08-27_10-11-56.zip new file mode 100644 index 000000000..b9bfacbcb Binary files /dev/null and b/packages/importer/__tests__/fixtures/export-2021-08-27_10-11-56.zip differ diff --git a/packages/importer/__tests__/fixtures/takeout.zip b/packages/importer/__tests__/fixtures/takeout.zip new file mode 100644 index 000000000..89e6155ba Binary files /dev/null and b/packages/importer/__tests__/fixtures/takeout.zip differ diff --git a/packages/importer/__tests__/keep.test.js b/packages/importer/__tests__/keep.test.js new file mode 100644 index 000000000..b21e48edf --- /dev/null +++ b/packages/importer/__tests__/keep.test.js @@ -0,0 +1,8 @@ +const keep = require("../providers/keep"); +const utils = require("./utils"); + +test("convert google keep backup", () => { + let file = utils.getFile("takeout.zip"); + + expect(keep.convert([file])).toMatchSnapshot("keep-backup"); +}); \ No newline at end of file diff --git a/packages/importer/__tests__/nimbus.test.js b/packages/importer/__tests__/nimbus.test.js new file mode 100644 index 000000000..be1d52064 --- /dev/null +++ b/packages/importer/__tests__/nimbus.test.js @@ -0,0 +1,7 @@ +const nimbusnote = require("../providers/nimbusnote"); +const utils = require("./utils"); + +test("convert simplenote backup zip file", () => { + let file = utils.getFile("export-2021-08-27_10-11-56.zip"); + expect(nimbusnote.convert([file])).toMatchSnapshot("nimbus-export"); +}); diff --git a/packages/importer/providers/evernote.js b/packages/importer/providers/evernote.js index 20e57071c..2d082f410 100644 --- a/packages/importer/providers/evernote.js +++ b/packages/importer/providers/evernote.js @@ -69,7 +69,7 @@ function isNotebook(notes, fileName) { * @returns the created notebook using file name */ function getNotebooks(fileName) { - return [{ notebook: getName(fileName), topic: "All notes" }]; + return [{ notebook: extension.getName(fileName), topic: "All notes" }]; } /** diff --git a/packages/importer/providers/keep.js b/packages/importer/providers/keep.js index 927fa9656..f671debbc 100644 --- a/packages/importer/providers/keep.js +++ b/packages/importer/providers/keep.js @@ -18,6 +18,22 @@ const colors = { brown: "orange" }; +/** + * + * @param {object} keepNote A google keep note object + * @returns parsed html list from json. + */ +function makeListHtml(keepNote) { + let content = '"; + return content; +} + /** * * @param {Array<{data:string | Buffer,createdAt:number,modifiedAt:number,fileName:string}>} files @@ -34,7 +50,7 @@ function convert(files) { let imageKeys = items.filter( (i) => i.endsWith("png") || i.endsWith("jpg") || i.endsWith("jpeg") ); - + for (let key of noteKeys) { let keepNote = JSON.parse(Buffer.from(unzip[key].buffer).toString()); let note = templates.note(); @@ -62,14 +78,7 @@ function convert(files) { note.tags = keepNote.labels.map((label) => label.name); } if (keepNote.listContent) { - let content = '"; - note.content.data = content; + note.content.data = makeListHtml(keepNote); } if (keepNote.color && keepNote.color !== "DEFAULT") { note.color = colors[keepNote.color.toLowerCase()]; diff --git a/packages/importer/providers/nimbusnote.js b/packages/importer/providers/nimbusnote.js new file mode 100644 index 000000000..a3ec15804 --- /dev/null +++ b/packages/importer/providers/nimbusnote.js @@ -0,0 +1,72 @@ +const templates = require("../utils/template"); +const uzip = require("uzip"); +const extension = require("../utils/extension"); +const parser = new window.DOMParser(); + +function getNotebook(path) { + let parts = path.split("/"); + let notebook = parts[2]; + let topic = "All notes"; + if (parts.length > 3) { + topic = parts[parts.length - 2]; + } + + return { + notebook, + topic + }; +} + +/** + * + * @param {Array<{data:string | Buffer,createdAt:number,modifiedAt:number,fileName:string}>} files + * @returns array of notes + */ +function convert(files) { + let notes = []; + + for (var file of files) { + let unzip = uzip.parse(file.data); + let items = Object.keys(unzip); + let zipName = extension.getName(file.fileName); + items = items.filter((i) => i.startsWith(zipName) && extension.get(i)); + + if (items.find((i) => i.includes(`${zipName}/All Notes`))) { + for (zip of items) { + let raw = uzip.parse(unzip[zip]); + let html = Buffer.from(raw["note.html"].buffer).toString(); + html = parser.parseFromString(html, "text/html"); + + let note = templates.note(); + note.title = html.title; + note.notebooks = getNotebook(zip); + let images = html.getElementsByClassName("image-wrapper"); + if (images.length > 0) { + for (let image of images) { + let imageNode = image.querySelector("img"); + if (imageNode) { + let base64 = Buffer.from( + raw[imageNode.src.replace("./", "")].buffer + ).toString("base64"); + let img = html.createElement("img"); + img.src = base64; + img.width = imageNode.width; + image.parentElement.replaceChild(img, image); + } + } + } + note.content.data = html.body.innerHTML.trim(); + notes.push(note); + } + } else { + console.warn( + `${file.fileName} is not a nimbus note exported zip file, skipping` + ); + } + } + return notes; +} + +module.exports = { + convert +};