Merge branch 'feat/onevault'
This commit is contained in:
commit
c7910ff704
|
@ -22,13 +22,6 @@
|
|||
<div id="network"></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>
|
||||
<input id="filter" placeholder="search..." autocomplete="off"></input>
|
||||
|
|
131
main.js
131
main.js
|
@ -15,7 +15,9 @@ var defaultsettings =
|
|||
titlebydefault: false,
|
||||
linksinnewtab: true,
|
||||
colors: true,
|
||||
bulletrendering: "•"
|
||||
bulletrendering: "•",
|
||||
password: "",
|
||||
sync: false
|
||||
};
|
||||
|
||||
//builtin
|
||||
|
@ -33,7 +35,6 @@ var lastsaved = "";
|
|||
var pending = false;
|
||||
var settings = null;
|
||||
var tags = null;
|
||||
var currentvault = "";
|
||||
var currenttag = "";
|
||||
|
||||
var stat =
|
||||
|
@ -128,10 +129,6 @@ var commands = [
|
|||
action: searchtags,
|
||||
shortcut: "ctrl+shift+T"
|
||||
},
|
||||
{
|
||||
hint: "Log out",
|
||||
action: logout,
|
||||
},
|
||||
{
|
||||
hint: "Toggle split view",
|
||||
action: togglesplit
|
||||
|
@ -174,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,
|
||||
|
@ -223,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",
|
||||
|
@ -275,11 +268,6 @@ var commands = [
|
|||
{
|
||||
hint: "Sort todo.txt list",
|
||||
action: sorttodotxt
|
||||
},
|
||||
{
|
||||
hint: "Download encrypted data",
|
||||
remoteonly: true,
|
||||
action: downloadencrypted
|
||||
}];
|
||||
|
||||
var snippets = [
|
||||
|
@ -503,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,
|
||||
|
@ -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)
|
||||
{
|
||||
var list = [note];
|
||||
|
@ -957,7 +930,7 @@ function editpgpkeys()
|
|||
bindfile(
|
||||
{
|
||||
title: "pgpkeys",
|
||||
content: localStorage.getItem("pgpkeys")
|
||||
content: localStorage.getItem("pgpkeys") || ""
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -990,16 +963,7 @@ function togglesplit()
|
|||
|
||||
function isremote()
|
||||
{
|
||||
return currentvault == "remote";
|
||||
}
|
||||
|
||||
function logout()
|
||||
{
|
||||
if (isremote())
|
||||
{
|
||||
window.localStorage.removeItem("password");
|
||||
togglepassword();
|
||||
}
|
||||
return settings.sync;
|
||||
}
|
||||
|
||||
function tagslist()
|
||||
|
@ -1095,7 +1059,7 @@ function downloadnotes()
|
|||
zip.generateAsync({type:"blob"})
|
||||
.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 =
|
||||
{
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1205,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);
|
||||
|
@ -1313,15 +1265,9 @@ function initsnippets()
|
|||
});
|
||||
}
|
||||
|
||||
function initvault()
|
||||
{
|
||||
currentvault = window.localStorage.getItem("vault") || "local";
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
loadsettings();
|
||||
initvault();
|
||||
|
||||
window.onbeforeunload = checksaved;
|
||||
window.onclick = focuseditor;
|
||||
|
@ -1337,16 +1283,24 @@ function init()
|
|||
queryremote({action: "fetch"})
|
||||
.then(data =>
|
||||
{
|
||||
window.localStorage.setItem("remote", JSON.stringify(data));
|
||||
if (data.length)
|
||||
{
|
||||
window.localStorage.setItem("data", JSON.stringify(data));
|
||||
loadstorage();
|
||||
}
|
||||
})
|
||||
.catch(remotecallfailed);
|
||||
.catch(err =>
|
||||
{
|
||||
settings.password = prompt("Password: ", settings.password);
|
||||
savesettings();
|
||||
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
|
||||
|
@ -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)
|
||||
{
|
||||
var day = text.substr(0,8);
|
||||
|
@ -1445,7 +1390,7 @@ function queryremote(params)
|
|||
stat.cur.q++;
|
||||
stat.ses.q++;
|
||||
|
||||
params.password = window.localStorage.getItem("password");
|
||||
params.password = settings.password;
|
||||
|
||||
var paramlist = [];
|
||||
for (var i in params)
|
||||
|
@ -1484,8 +1429,7 @@ function queryremote(params)
|
|||
{
|
||||
if (data.error == "authent")
|
||||
{
|
||||
failed();
|
||||
togglepassword();
|
||||
failed("Authent failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1498,7 +1442,6 @@ function queryremote(params)
|
|||
}
|
||||
else
|
||||
{
|
||||
authentpage.hidden = true;
|
||||
notepage.style.display = "table";
|
||||
apply(data);
|
||||
}
|
||||
|
@ -1896,7 +1839,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())
|
||||
|
@ -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()
|
||||
{
|
||||
if (document.documentElement == event.srcElement)
|
||||
|
|
12
readme.md
12
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue