Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/PhieF/CarnetElectron.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhie <phie@phie.ovh>2020-04-30 17:56:47 +0300
committerPhie <phie@phie.ovh>2020-04-30 17:57:16 +0300
commit26409945121a079ee21595a7f96a83b787d81060 (patch)
tree5316127763dfc3b37ca3aac0dcd1342dfd0c551f /importer
parentff14b7df60b0cdb0854328f0b3c3220f2e90d4be (diff)
importer make it compatible with nextcloud + other stuffs
Diffstat (limited to 'importer')
-rw-r--r--importer/google-converter.js120
-rw-r--r--importer/importer.html11
-rw-r--r--importer/importer.js26
3 files changed, 111 insertions, 46 deletions
diff --git a/importer/google-converter.js b/importer/google-converter.js
index 0afb167..5e1128e 100644
--- a/importer/google-converter.js
+++ b/importer/google-converter.js
@@ -12,6 +12,38 @@ GoogleConverter.prototype.convertNoteToSQD = function (currentZip, keepNotePath,
this.XMLConvertNoteToSQD(currentZip, keepNotePath, destFolder, callback)
}
+GoogleConverter.prototype.extractDateFromXML = function (dateDiv) {
+ console.log(dateDiv.innerText.trim())
+
+
+ console.log(escape(dateDiv.innerText.trim()).replace("%E0%20", ""))
+ var date = dateDiv.innerText.trim();
+ //escape unescape only way I've found to replace the à which didn't work with simple replace("à ","")
+ var fixedDate = unescape(escape(date).replace("%E0%20", "").replace("%E9", "e").replace("%FB", "u")).replace("at ", "").replace("à ", "")
+ .replace("&agrave; ", "")
+ .replace("juin", "june")
+ .replace("juil.", "july")
+ .replace("mars", "march")
+ .replace("oct.", "october")
+ .replace("jan.", "january")
+ .replace("janv.", "january")
+ .replace("sept.", "september")
+ .replace("déc.", "december")
+ .replace("dec.", "december")
+ .replace("fevr.", "february")
+ .replace("avr.", "april")
+ .replace("nov.", "november")
+ .replace("mai", "may")
+ .replace("aout", "august");
+ console.log(fixedDate)
+ var time = getDateFromFormat(fixedDate, "dd MMM yyyy HH:mm:ss")
+ if (time == 0) //try different
+ time = getDateFromFormat(fixedDate, "d MMM yyyy HH:mm:ss")
+ if (time == 0) //try moment
+ time = moment(fixedDate).toDate().getTime()
+ return time;
+}
+
GoogleConverter.prototype.XMLConvertNoteToSQD = function (currentZip, keepNotePath, destFolder, callback) {
var fileName = FileUtils.getFilename(keepNotePath);
var zip = new JSZip();
@@ -142,6 +174,7 @@ GoogleConverter.prototype.getListOfNotesFromZip = function (zip, callback) {
GoogleConverter.prototype.JsonConvertNoteToSQD = function (currentZip, keepNotePath, destFolder, callback) {
var importer = this
+ var originalFilename = FileUtils.stripExtensionFromName(FileUtils.getFilename(keepNotePath));
var filename = FileUtils.stripExtensionFromName(FileUtils.getFilename(keepNotePath)) + ".sqd";
currentZip.files["Takeout/Keep/" + keepNotePath].async('text').then(function (txt) {
var json = JSON.parse(txt)
@@ -156,43 +189,68 @@ GoogleConverter.prototype.JsonConvertNoteToSQD = function (currentZip, keepNoteP
</div>');
if (json['title'] == "" || json['title'] === undefined)
filename = "untitled " + filename;
- console.log("date " + json['userEditedTimestampUsec'])
- var metadata = {}
- metadata['creation_date'] = Math.round(json['userEditedTimestampUsec'] / 1000)
- metadata['title'] = json['title']
- metadata['last_modification_date'] = Math.round(json['userEditedTimestampUsec'] / 1000)
- console.log("date " + metadata['last_modification_date'])
-
- metadata['keywords'] = []
- metadata['rating'] = -1
- metadata['color'] = "none"
- metadata['urls'] = {}
- metadata['todolists'] = []
- if (json['labels'] != undefined)
- for (var label of json['labels']) {
- metadata['keywords'].push(label.name)
- }
- if (json['annotations'] != undefined) {
- for (var annotation of json['annotations']) {
- if (annotation['url'] != undefined) {
- var url = {}
- url['title'] = annotation['title']
- url['description'] = annotation['description']
- metadata['urls'][annotation['url']] = url
- }
- }
- }
- zip.file("metadata.json", JSON.stringify(metadata));
+ var mdate = Math.round(json['userEditedTimestampUsec'] / 1000);
+ if (mdate <= 0) {
+ var dateStr = originalFilename
+ dateStr = dateStr.replace(/_/g, ":")
+ mdate = Date.parse(dateStr);
+ if (!(mdate > 0)) {
+ /*console.log("mdate " + mdate)
+ //try to retrieve from xml
+ var xmlContent = currentZip.files["Takeout/Keep/" + originalFilename + ".html"].async('text').then(function (txt) {
+ var container = document.createElement("div");
+ container.innerHTML = xmlContent
+ var dateDiv = container.querySelector(".heading");
+
+ console.log("extracted date " + importer.extractDateFromXML(dateDiv))
+ })
+
+ return*/
+ importer.onDateAvailable(mdate, json, zip, filename, currentZip, keepNotePath, destFolder, callback)
+
- importer.importNoteAttachments(currentZip, zip, json['attachments'], function () {
- console.log("generateAsync")
- callback(zip, metadata, filename)
+ } else importer.onDateAvailable(mdate, json, zip, filename, currentZip, keepNotePath, destFolder, callback)
+ } else importer.onDateAvailable(mdate, json, zip, filename, currentZip, keepNotePath, destFolder, callback)
- })
})
}
+GoogleConverter.prototype.onDateAvailable = function (date, json, zip, filename, currentZip, keepNotePath, destFolder, callback) {
+ var importer = this
+ var metadata = {}
+ metadata['creation_date'] = date
+ metadata['title'] = json['title']
+ metadata['last_modification_date'] = date
+ console.log("date " + date)
+
+ metadata['keywords'] = []
+ metadata['rating'] = -1
+ metadata['color'] = "none"
+ metadata['urls'] = {}
+ metadata['todolists'] = []
+ if (json['labels'] != undefined)
+ for (var label of json['labels']) {
+ metadata['keywords'].push(label.name)
+ }
+ if (json['annotations'] != undefined) {
+ for (var annotation of json['annotations']) {
+ if (annotation['url'] != undefined) {
+ var url = {}
+ url['title'] = annotation['title']
+ url['description'] = annotation['description']
+ metadata['urls'][annotation['url']] = url
+ }
+ }
+ }
+ zip.file("metadata.json", JSON.stringify(metadata));
+
+ importer.importNoteAttachments(currentZip, zip, json['attachments'], function () {
+ console.log("json['isPinned'] " + json['isPinned'])
+ callback(zip, JSON.stringify(metadata), filename, json['isPinned'])
+
+ })
+}
GoogleConverter.prototype.importNoteAttachments = function (currentZip, destZip, attachments, callback) {
this.importNoteAttachment(currentZip, destZip, attachments, callback)
diff --git a/importer/importer.html b/importer/importer.html
index 19f39b2..f6f3581 100644
--- a/importer/importer.html
+++ b/importer/importer.html
@@ -84,7 +84,7 @@
<div class="centered-container">
<button class="mdl-button mdl-js-button mdl-button--raised import-button" style="width:370px"
- onclick="importer.importNotes()">
+ id="import-button1">
Import
</button>
<br />
@@ -97,7 +97,7 @@
</div>
<div class="centered-container" id="progress-view">
<div>
- Loading notes list
+ <span>Loading notes list</span>
<div id="p2" style="margin:auto" class="mdl-progress mdl-js-progress mdl-progress__indeterminate">
</div>
</div>
@@ -107,7 +107,7 @@
</div>
<div class="centered-container" style="margin-bottom:10px;">
<button class="mdl-button mdl-js-button mdl-button--raised import-button" style="width:370px"
- onclick="importer.importNotes()">
+ id="import-button2">
Import
</button>
</div>
@@ -145,11 +145,6 @@
</div>
<input type="file" id="input_file" style="display: none;" />
-
- <script>
-
- var importer = new Importer("/Keep");
- </script>
</div>
</body>
diff --git a/importer/importer.js b/importer/importer.js
index c0a6dd5..533344b 100644
--- a/importer/importer.js
+++ b/importer/importer.js
@@ -10,7 +10,9 @@ var Importer = function (destPath) {
$("#note-selection-view").hide();
$("#importing-view").hide();
$('#import-finished').hide();
-
+ document.getElementById("import-button1").onclick = document.getElementById("import-button2").onclick = function () {
+ importer.importNotes()
+ }
document.getElementById("select-folder-button").onclick = function () {
document.getElementById("input_file").click();
@@ -72,13 +74,14 @@ Importer.prototype.importNotes = function () {
this.notesToImport = this.getSelectedNotes()
this.timeStampedNotes = []
this.timeStampedKeywords = []
+ this.error = []
var importer = this;
importer.imported = 0;
this.importNext(function () {
$('#import-finished').show();
$('#importing-view').hide();
- $('#import-report').html(importer.imported + " note(s) imported");
+ $('#import-report').html(importer.imported + " note(s) imported <br />" + importer.error.length + " failed");
/*console.log(importer.timeStampedNotes.length + " note(s) imported " + document.getElementById("add-to-recent-cb").checked)
if (document.getElementById("add-to-recent-cb").checked) {
importer.timeStampedNotes.sort(keysrt('time'))
@@ -263,16 +266,19 @@ function DateError() { }
Importer.prototype.importNote = function (keepNotePath, destFolder, callback) {
this.importingSpan.innerHTML = FileUtils.getFilename(keepNotePath) + " (" + this.notesToImport.length + " remaining)";
- this.converter.convertNoteToSQD(this.currentZip, keepNotePath, destFolder, function (zip, metadata, fileName) {
+ this.converter.convertNoteToSQD(this.currentZip, keepNotePath, destFolder, function (zip, metadata, fileName, isPinned) {
console.log("filename " + fileName)
- importer.sendNote(zip, metadata, fileName, callback)
+ importer.sendNote(zip, metadata, fileName, isPinned, callback)
})
}
+Importer.prototype.onError = function (filename) {
+ this.error.push(filename);
+}
-
-Importer.prototype.sendNote = function (zip, metadata, filename, callback) {
+Importer.prototype.sendNote = function (zip, metadata, filename, isPinned, callback) {
var self = this
+ console.log("metadata " + metadata)
zip.generateAsync({ type: "blob" }).then(function (blob) {
var files = []
@@ -281,11 +287,13 @@ Importer.prototype.sendNote = function (zip, metadata, filename, callback) {
RequestBuilder.sRequestBuilder.postFiles("/note/import", {
add_to_recent: true,
path: "keep",
+ is_pinned: isPinned,
metadata: metadata
}, files, function (error, data) {
console.log("error " + error)
if (error) {
- self.onError()
+ self.onError(filename)
+ callback()
} else {
self.imported = self.imported + 1;
callback()
@@ -296,3 +304,7 @@ Importer.prototype.sendNote = function (zip, metadata, filename, callback) {
});
}
+var importer;
+$(document).ready(function () {
+ importer = new Importer("/Keep");
+})