From 5d03d4b10873d512d481ea9c576b54448ff3046d Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Fri, 27 Oct 2023 16:59:14 +0200 Subject: [PATCH] changed: use only one vault, with sync option --- main.js | 82 ++++++++++++++----------------------------------------- readme.md | 12 ++++---- 2 files changed, 26 insertions(+), 68 deletions(-) diff --git a/main.js b/main.js index ce7a6cc..72884c7 100644 --- a/main.js +++ b/main.js @@ -16,7 +16,8 @@ var defaultsettings = linksinnewtab: true, colors: true, bulletrendering: "•", - password: "" + password: "", + sync: false }; //builtin @@ -34,7 +35,6 @@ var lastsaved = ""; var pending = false; var settings = null; var tags = null; -var currentvault = ""; var currenttag = ""; var stat = @@ -171,11 +171,6 @@ var commands = [ action: shownotelinks, shortcut: "ctrl+l" }, -{ - hint: "Switch local/remote vault", - action: switchvault, - shortcut: "ctrl+shift+V" -}, { hint: "Add tag filter", action: addtagfilter, @@ -220,17 +215,18 @@ var commands = [ action: downloadnotewithsubs }, { - hint: "Download all notes in a zip file", + hint: "Download all notes (zip file)", action: downloadnotes, shortcut: "ctrl+shift+S" }, { - hint: "Download current vault", - action: downloadvault + hint: "Download all notes (json file)", + action: downloadnotesjson }, { - hint: "Download all vaults", - action: downloadallvaults + hint: "Download all notes (encrypted json file)", + action: downloadencrypted, + remoteonly: true }, { hint: "Insert text in todo", @@ -272,11 +268,6 @@ var commands = [ { hint: "Sort todo.txt list", action: sorttodotxt -}, -{ - hint: "Download encrypted data", - remoteonly: true, - action: downloadencrypted }]; var snippets = [ @@ -500,7 +491,7 @@ function showinfo() var tags = gettags(currentnote); showtemporaryinfo( [ - "vault: " + currentvault, + "sync: " + (settings.sync ? "en" : "dis") + "abled", "title: " + currentnote.title, "saved: " + saved + " (" + lastsaved + ")", "line count: " + md.value.split("\n").length, @@ -547,21 +538,6 @@ function addtagfilter() } } -function applyvault(vault) -{ - window.localStorage.setItem("vault", vault); - init(); -} - -function switchvault() -{ - var newvault = currentvault == "local" ? "remote" : "local"; - if (confirm("Switch to " + newvault + "?")) - { - applyvault(newvault); - } -} - function descendants(note) { var list = [note]; @@ -954,7 +930,7 @@ function editpgpkeys() bindfile( { title: "pgpkeys", - content: localStorage.getItem("pgpkeys") + content: localStorage.getItem("pgpkeys") || "" }); } @@ -987,7 +963,7 @@ function togglesplit() function isremote() { - return currentvault == "remote"; + return settings.sync; } function tagslist() @@ -1083,7 +1059,7 @@ function downloadnotes() zip.generateAsync({type:"blob"}) .then(function(content) { - saveAs(content, "notes " + timestamp() + " " + currentvault + ".zip"); + saveAs(content, "notes-" + timestamp() + ".zip"); }); } @@ -1123,29 +1099,17 @@ function inserttodo() } } -function downloadallvaults() +function downloadnotesjson() { - var data = - { - local: JSON.parse(window.localStorage.getItem("local")), - remote: JSON.parse(window.localStorage.getItem("remote")), - trash: JSON.parse(window.localStorage.getItem("trash")), - }; - download("notes " + timestamp() + ".json", JSON.stringify(data)); + download("notes-" + timestamp() + ".json", window.localStorage.getItem("data")); } -function downloadvault() -{ - download("notes " + timestamp() + " " + currentvault + ".json", window.localStorage.getItem(currentvault)); -} - - function downloadencrypted() { encryptstring(JSON.stringify(localdata)) .then(encrypted => { - download("encrypted notes " + timestamp() + " " + currentvault + ".acs", encrypted); + download("notes-encrypted-" + timestamp() + ".acs", encrypted); }); } @@ -1193,7 +1157,7 @@ function gotoline(line) function loadstorage() { - var item = window.localStorage.getItem(currentvault); + var item = window.localStorage.getItem("data"); localdata = item ? JSON.parse(item) : []; var params = new URLSearchParams(window.location.search); @@ -1301,15 +1265,9 @@ function initsnippets() }); } -function initvault() -{ - currentvault = window.localStorage.getItem("vault") || "local"; -} - function init() { loadsettings(); - initvault(); window.onbeforeunload = checksaved; window.onclick = focuseditor; @@ -1325,7 +1283,7 @@ function init() queryremote({action: "fetch"}) .then(data => { - window.localStorage.setItem("remote", JSON.stringify(data)); + window.localStorage.setItem("data", JSON.stringify(data)); loadstorage(); }) .catch(err => @@ -1337,9 +1295,9 @@ function init() } else { - showtemporaryinfo("Pgp key empty or invalid. Switching to local."); - currentvault = "local"; loadstorage(); + editpgpkeys(); + showtemporaryinfo("Pgp key empty or invalid. Enter PGP keys and refresh."); } } else @@ -1878,7 +1836,7 @@ function save() currentnote.content = content; putontop(); - window.localStorage.setItem(currentvault, JSON.stringify(localdata)); + window.localStorage.setItem("data", JSON.stringify(localdata)); console.log("data serialized in local storage") if (isremote()) diff --git a/readme.md b/readme.md index 7445ca3..11bbe28 100644 --- a/readme.md +++ b/readme.md @@ -11,18 +11,18 @@ Your notes are stored in your browser local storage. * command palette: ctrl+shift+p * notes list: ctrl+p -## Remote mode +## Sync feature -You can use remote mode with your own php server to access your notes from the cloud: +To sync your notes in the cloud: * put the source files on your php server * browse index.html -* launch command "edit pgp keys" and paste your public and private keys as a single file (passphrase is not supported) -* switch to remote mode: ctrl+shift+V +* paste your public and private PGP keys as a single file (passphrase is not supported) +* refresh the page -Your data file will always be encrypted before reaching the server. +Your data is always encrypted before reaching the server. -To protect your data file access by a password, edit settings.php and change `$password` variable. Your password will be sent from browser to server through a post http query, encrypted with ssl if enabled. It is stored unencrypted in your browser local storage and in the settings.php file on server side. +To protect your data file access by a password, edit settings.php and change `$password` variable. The password is sent from browser to server through a post http query, encrypted with ssl if enabled. It is stored unencrypted in your browser local storage and in the settings.php file on server side. ## Cli tool