This commit is contained in:
thecodrr
2021-09-01 11:02:54 +05:00
9 changed files with 299 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@@ -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": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
<div class=\\"editor-body\\">
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
</div>
</div>",
"type": "html",
},
"notebooks": Object {
"notebook": "My Notes",
"topic": "My Notes",
},
"title": "ringing the bell",
},
Object {
"content": Object {
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
<div class=\\"editor-body\\">
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
</div>
</div>",
"type": "html",
},
"notebooks": Object {
"notebook": "My Notes",
"topic": "My Notes",
},
"title": "Wow",
},
Object {
"content": Object {
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
<div class=\\"editor-body\\">
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
</div>
</div>",
"type": "html",
},
"notebooks": Object {
"notebook": "My Notes",
"topic": "My Notes",
},
"title": "This is a new day and I am writi",
},
Object {
"content": Object {
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
<div class=\\"editor-body\\">
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
</div>
</div>",
"type": "html",
},
"notebooks": Object {
"notebook": "My Notes",
"topic": "My Notes",
},
"title": "my note",
},
Object {
"content": Object {
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
<div class=\\"editor-body\\">
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
</div>
</div>",
"type": "html",
},
"notebooks": Object {
"notebook": "Bingo",
"topic": "Bingo",
},
"title": "Oh okay I am making a note now.",
},
Object {
"content": Object {
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
<div class=\\"editor-body\\">
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
</div>
</div>",
"type": "html",
},
"notebooks": Object {
"notebook": "Bingo",
"topic": "Rope",
},
"title": "New note",
},
Object {
"content": Object {
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
<div class=\\"editor-body\\">
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
</div>
</div>",
"type": "html",
},
"notebooks": Object {
"notebook": "Bingo",
"topic": "Rope",
},
"title": "New note",
},
Object {
"content": Object {
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
<div class=\\"editor-body\\">
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
</div>
</div>",
"type": "html",
},
"notebooks": Object {
"notebook": "Bingo",
"topic": "Rope",
},
"title": "home",
},
Object {
"content": Object {
"data": "<div id=\\"note-editor\\" class=\\"note-container theme-light\\" style=\\"position: relative;\\">
<div class=\\"editor-body\\">
<div class=\\"export-mode nedit-root notranslate size-normal style-normal\\" id=\\"note-root\\"><div class=\\"editable-text paragraph indent-0\\" data-block-background=\\"transparent\\" style=\\"text-align:left\\">This is a new note that I am working on</div></div>
</div>
</div>",
"type": "html",
},
"notebooks": Object {
"notebook": "Bingo",
"topic": "Rope",
},
"title": "This is a new note that I am wor",
},
]
`;

Binary file not shown.

View File

@@ -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");
});

View File

@@ -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");
});

View File

@@ -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" }];
}
/**

View File

@@ -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 = '<ul class="tox-checklist">';
for (item of keepNote.listContent) {
content += `<li class="${
item.isChecked ? "tox-checklist--checked" : ""
}" >${item.text}</li>`;
}
content += "</ul>";
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 = '<ul class="tox-checklist">';
for (item of keepNote.listContent) {
content += `<li class="${
item.isChecked ? "tox-checklist--checked" : ""
}" >${item.text}</li>`;
}
content += "</ul>";
note.content.data = content;
note.content.data = makeListHtml(keepNote);
}
if (keepNote.color && keepNote.color !== "DEFAULT") {
note.color = colors[keepNote.color.toLowerCase()];

View File

@@ -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
};