Merge branch 'feat/onevault'

This commit is contained in:
quenousimporte 2023-11-05 18:32:15 +01:00
commit c7910ff704
4 changed files with 39 additions and 120 deletions

View File

@ -22,13 +22,6 @@
<div id="network"></div> <div id="network"></div>
</div> </div>
<div id="authentpage" hidden>
<div id="bigtitle">notes</div>
<div>
<input id="password" type="password" placeholder="pass phrase..." onkeydown="sendpassword()" onblur="sendpassword()" ></input>
</div>
</div>
<div id="searchdialog" oninput="applyfilter()" hidden> <div id="searchdialog" oninput="applyfilter()" hidden>
<div> <div>
<input id="filter" placeholder="search..." autocomplete="off"></input> <input id="filter" placeholder="search..." autocomplete="off"></input>

131
main.js
View File

@ -15,7 +15,9 @@ var defaultsettings =
titlebydefault: false, titlebydefault: false,
linksinnewtab: true, linksinnewtab: true,
colors: true, colors: true,
bulletrendering: "•" bulletrendering: "•",
password: "",
sync: false
}; };
//builtin //builtin
@ -33,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 =
@ -128,10 +129,6 @@ var commands = [
action: searchtags, action: searchtags,
shortcut: "ctrl+shift+T" shortcut: "ctrl+shift+T"
}, },
{
hint: "Log out",
action: logout,
},
{ {
hint: "Toggle split view", hint: "Toggle split view",
action: togglesplit action: togglesplit
@ -174,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,
@ -223,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",
@ -275,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 = [
@ -503,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,
@ -550,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];
@ -957,7 +930,7 @@ function editpgpkeys()
bindfile( bindfile(
{ {
title: "pgpkeys", title: "pgpkeys",
content: localStorage.getItem("pgpkeys") content: localStorage.getItem("pgpkeys") || ""
}); });
} }
@ -990,16 +963,7 @@ function togglesplit()
function isremote() function isremote()
{ {
return currentvault == "remote"; return settings.sync;
}
function logout()
{
if (isremote())
{
window.localStorage.removeItem("password");
togglepassword();
}
} }
function tagslist() function tagslist()
@ -1095,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");
}); });
} }
@ -1135,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);
}); });
} }
@ -1205,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);
@ -1313,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;
@ -1337,16 +1283,24 @@ function init()
queryremote({action: "fetch"}) queryremote({action: "fetch"})
.then(data => .then(data =>
{ {
window.localStorage.setItem("remote", JSON.stringify(data)); if (data.length)
{
window.localStorage.setItem("data", JSON.stringify(data));
loadstorage(); loadstorage();
}
}) })
.catch(remotecallfailed); .catch(err =>
{
settings.password = prompt("Password: ", settings.password);
savesettings();
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
@ -1367,15 +1321,6 @@ function init()
} }
} }
function togglepassword()
{
password.value = "";
authentpage.hidden = false;
notepage.style.display = "none";
document.title = "notes";
password.focus();
}
function cvdt(text) function cvdt(text)
{ {
var day = text.substr(0,8); var day = text.substr(0,8);
@ -1445,7 +1390,7 @@ function queryremote(params)
stat.cur.q++; stat.cur.q++;
stat.ses.q++; stat.ses.q++;
params.password = window.localStorage.getItem("password"); params.password = settings.password;
var paramlist = []; var paramlist = [];
for (var i in params) for (var i in params)
@ -1484,8 +1429,7 @@ function queryremote(params)
{ {
if (data.error == "authent") if (data.error == "authent")
{ {
failed(); failed("Authent failed");
togglepassword();
} }
else else
{ {
@ -1498,7 +1442,6 @@ function queryremote(params)
} }
else else
{ {
authentpage.hidden = true;
notepage.style.display = "table"; notepage.style.display = "table";
apply(data); apply(data);
} }
@ -1896,7 +1839,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())
@ -2846,16 +2789,6 @@ function loadnote(name)
} }
} }
function sendpassword()
{
if (!authentpage.hidden && (event.type == "blur" || event.key == "Enter"))
{
event.preventDefault();
window.localStorage.setItem("password", password.value);
init();
}
}
function focuseditor() function focuseditor()
{ {
if (document.documentElement == event.srcElement) if (document.documentElement == event.srcElement)

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

View File

@ -133,10 +133,3 @@ body::-webkit-scrollbar-thumb {
background-color: darkgray; background-color: darkgray;
margin: 2px 2px 2px 2px; margin: 2px 2px 2px 2px;
} }
/* authent */
#bigtitle {
font-size: 50px;
line-height: 100%;
}