changed: use only one vault, with sync option

This commit is contained in:
quenousimporte 2023-10-27 16:59:14 +02:00
parent cc0b0ad328
commit 5d03d4b108
2 changed files with 26 additions and 68 deletions

82
main.js
View File

@ -16,7 +16,8 @@ var defaultsettings =
linksinnewtab: true, linksinnewtab: true,
colors: true, colors: true,
bulletrendering: "•", bulletrendering: "•",
password: "" password: "",
sync: false
}; };
//builtin //builtin
@ -34,7 +35,6 @@ var lastsaved = "";
var pending = false; var pending = false;
var settings = null; var settings = null;
var tags = null; var tags = null;
var currentvault = "";
var currenttag = ""; var currenttag = "";
var stat = var stat =
@ -171,11 +171,6 @@ var commands = [
action: shownotelinks, action: shownotelinks,
shortcut: "ctrl+l" shortcut: "ctrl+l"
}, },
{
hint: "Switch local/remote vault",
action: switchvault,
shortcut: "ctrl+shift+V"
},
{ {
hint: "Add tag filter", hint: "Add tag filter",
action: addtagfilter, action: addtagfilter,
@ -220,17 +215,18 @@ var commands = [
action: downloadnotewithsubs action: downloadnotewithsubs
}, },
{ {
hint: "Download all notes in a zip file", hint: "Download all notes (zip file)",
action: downloadnotes, action: downloadnotes,
shortcut: "ctrl+shift+S" shortcut: "ctrl+shift+S"
}, },
{ {
hint: "Download current vault", hint: "Download all notes (json file)",
action: downloadvault action: downloadnotesjson
}, },
{ {
hint: "Download all vaults", hint: "Download all notes (encrypted json file)",
action: downloadallvaults action: downloadencrypted,
remoteonly: true
}, },
{ {
hint: "Insert text in todo", hint: "Insert text in todo",
@ -272,11 +268,6 @@ var commands = [
{ {
hint: "Sort todo.txt list", hint: "Sort todo.txt list",
action: sorttodotxt action: sorttodotxt
},
{
hint: "Download encrypted data",
remoteonly: true,
action: downloadencrypted
}]; }];
var snippets = [ var snippets = [
@ -500,7 +491,7 @@ function showinfo()
var tags = gettags(currentnote); var tags = gettags(currentnote);
showtemporaryinfo( showtemporaryinfo(
[ [
"vault: " + currentvault, "sync: " + (settings.sync ? "en" : "dis") + "abled",
"title: " + currentnote.title, "title: " + currentnote.title,
"saved: " + saved + " (" + lastsaved + ")", "saved: " + saved + " (" + lastsaved + ")",
"line count: " + md.value.split("\n").length, "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) function descendants(note)
{ {
var list = [note]; var list = [note];
@ -954,7 +930,7 @@ function editpgpkeys()
bindfile( bindfile(
{ {
title: "pgpkeys", title: "pgpkeys",
content: localStorage.getItem("pgpkeys") content: localStorage.getItem("pgpkeys") || ""
}); });
} }
@ -987,7 +963,7 @@ function togglesplit()
function isremote() function isremote()
{ {
return currentvault == "remote"; return settings.sync;
} }
function tagslist() function tagslist()
@ -1083,7 +1059,7 @@ function downloadnotes()
zip.generateAsync({type:"blob"}) zip.generateAsync({type:"blob"})
.then(function(content) .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 = download("notes-" + timestamp() + ".json", window.localStorage.getItem("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));
} }
function downloadvault()
{
download("notes " + timestamp() + " " + currentvault + ".json", window.localStorage.getItem(currentvault));
}
function downloadencrypted() function downloadencrypted()
{ {
encryptstring(JSON.stringify(localdata)) encryptstring(JSON.stringify(localdata))
.then(encrypted => .then(encrypted =>
{ {
download("encrypted notes " + timestamp() + " " + currentvault + ".acs", encrypted); download("notes-encrypted-" + timestamp() + ".acs", encrypted);
}); });
} }
@ -1193,7 +1157,7 @@ function gotoline(line)
function loadstorage() function loadstorage()
{ {
var item = window.localStorage.getItem(currentvault); var item = window.localStorage.getItem("data");
localdata = item ? JSON.parse(item) : []; localdata = item ? JSON.parse(item) : [];
var params = new URLSearchParams(window.location.search); var params = new URLSearchParams(window.location.search);
@ -1301,15 +1265,9 @@ function initsnippets()
}); });
} }
function initvault()
{
currentvault = window.localStorage.getItem("vault") || "local";
}
function init() function init()
{ {
loadsettings(); loadsettings();
initvault();
window.onbeforeunload = checksaved; window.onbeforeunload = checksaved;
window.onclick = focuseditor; window.onclick = focuseditor;
@ -1325,7 +1283,7 @@ function init()
queryremote({action: "fetch"}) queryremote({action: "fetch"})
.then(data => .then(data =>
{ {
window.localStorage.setItem("remote", JSON.stringify(data)); window.localStorage.setItem("data", JSON.stringify(data));
loadstorage(); loadstorage();
}) })
.catch(err => .catch(err =>
@ -1337,9 +1295,9 @@ function init()
} }
else else
{ {
showtemporaryinfo("Pgp key empty or invalid. Switching to local.");
currentvault = "local";
loadstorage(); loadstorage();
editpgpkeys();
showtemporaryinfo("Pgp key empty or invalid. Enter PGP keys and refresh.");
} }
} }
else else
@ -1878,7 +1836,7 @@ function save()
currentnote.content = content; currentnote.content = content;
putontop(); putontop();
window.localStorage.setItem(currentvault, JSON.stringify(localdata)); window.localStorage.setItem("data", JSON.stringify(localdata));
console.log("data serialized in local storage") console.log("data serialized in local storage")
if (isremote()) if (isremote())

View File

@ -11,18 +11,18 @@ Your notes are stored in your browser local storage.
* command palette: ctrl+shift+p * command palette: ctrl+shift+p
* notes list: ctrl+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 * put the source files on your php server
* browse index.html * browse index.html
* launch command "edit pgp keys" and paste your public and private keys as a single file (passphrase is not supported) * paste your public and private PGP keys as a single file (passphrase is not supported)
* switch to remote mode: ctrl+shift+V * 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 ## Cli tool