fixed: ics file not found

refactor: removed commented code
changed: server data file name
changed: pgp is required in remote mode
refactor: added function to get or create note
This commit is contained in:
quenousimporte 2023-07-17 09:16:10 +02:00
parent 5ecf1b721b
commit 9df5301f5d
4 changed files with 46 additions and 39 deletions

View File

@ -41,7 +41,7 @@ else if (isset($_POST['action']))
break; break;
case 'cal': case 'cal':
if (file_exists($icsfile)) if ($icsfile)
{ {
$result = array(); $result = array();
$result["ics"] = file_get_contents($icsfile); $result["ics"] = file_get_contents($icsfile);

77
main.js
View File

@ -1242,14 +1242,23 @@ function init()
if (isremote()) if (isremote())
{ {
queryremote({action: "fetch"}) if (localStorage.getItem("pgpkeys") && localStorage.getItem("pgpkeys").startsWith("-----BEGIN PGP PUBLIC KEY BLOCK-----"))
.then(data =>
{ {
window.localStorage.setItem("remote", JSON.stringify(data)); queryremote({action: "fetch"})
.then(data =>
{
window.localStorage.setItem("remote", JSON.stringify(data));
loadstorage();
checkevents();
})
.catch(remotecallfailed);
}
else
{
showtemporaryinfo("Pgp key empty or invalid. Switching to local.");
currentvault = "local";
loadstorage(); loadstorage();
checkevents(); }
})
.catch(remotecallfailed);
} }
else else
{ {
@ -1323,6 +1332,23 @@ function ics2json(ics)
return events.sort( (a,b) => a.DTSTART - b.DTSTART); return events.sort( (a,b) => a.DTSTART - b.DTSTART);
} }
function getorcreate(title, content, putontop)
{
var note = getnote(title);
if (!note)
{
note = {title: title, content: content};
localdata.push(note)
}
if (putontop)
{
localdata.splice(localdata.indexOf(note), 1);
localdata.unshift(note);
}
return note;
}
function checkevents() function checkevents()
{ {
queryremote({action: "cal"}) queryremote({action: "cal"})
@ -1340,16 +1366,7 @@ function checkevents()
return; return;
} }
var note = getnote("events.json"); var note = getorcreate("events.json", "[]", false);
if (!note)
{
note = {
title: "events.json",
content: "[]"
};
localdata.push(note);
}
var events = ics2json(data.ics); var events = ics2json(data.ics);
var existing = JSON.parse(note.content).map(e => var existing = JSON.parse(note.content).map(e =>
{ {
@ -1387,21 +1404,21 @@ function checkevents()
if (newcontent.length) if (newcontent.length)
{ {
showtemporaryinfo("Calendar changes to check"); showtemporaryinfo("Calendar changes to check");
var todo = getnote("todo"); var eventsnotes = getorcreate("events to check", "", true);
var idx = 0; var idx = 0;
if (todo.content.startsWith("---")) if (eventsnotes.content.startsWith("---"))
{ {
idx = todo.content.indexOf("---", 3) + 4; idx = eventsnotes.content.indexOf("---", 3) + 4;
} }
todo.content = todo.content.substring(0, idx) eventsnotes.content = eventsnotes.content.substring(0, idx)
+ newcontent.join("\n") + newcontent.join("\n")
+ "\n---\n" + "\n---\n"
+ todo.content.substring(idx); + eventsnotes.content.substring(idx);
// reload todo if open // reload eventsnotes if open
if (currentnote == todo) if (currentnote == eventsnotes)
{ {
bindfile(todo); bindfile(eventsnotes);
} }
note.content = JSON.stringify(events); note.content = JSON.stringify(events);
@ -2123,7 +2140,7 @@ function toggleheader()
{ {
if (preview.hidden) if (preview.hidden)
{ {
if (md.value.startsWith("---")) if (md.value.startsWith("---\n"))
{ {
var idx = md.value.indexOf("---", 3); var idx = md.value.indexOf("---", 3);
var header = md.value.substring(0, idx + 4); var header = md.value.substring(0, idx + 4);
@ -2467,7 +2484,7 @@ function bindfile(note)
} }
currentheader = ""; currentheader = "";
if (settings.hideheaderbydefault && md.value.startsWith("---")) if (settings.hideheaderbydefault && md.value.startsWith("---\n"))
{ {
toggleheader(); toggleheader();
} }
@ -2477,13 +2494,7 @@ function bindfile(note)
function loadnote(name) function loadnote(name)
{ {
var note = localdata.find(n => n.title == name); var note = getorcreate(name, "", true);
if (!note)
{
note = {title: name, content: ""};
localdata.unshift(note);
}
bindfile(note); bindfile(note);
stat.cur.q = 0; stat.cur.q = 0;

View File

@ -1,5 +1,5 @@
<?php <?php
$datafile = '../data/data.json'; $datafile = '../data/data.acs';
$icsfile = ''; $icsfile = '';
$password = ''; $password = '';
$smsurl = ''; $smsurl = '';

View File

@ -89,10 +89,6 @@ body::-webkit-scrollbar-thumb {
#filter { #filter {
width: 100%; width: 100%;
/* wm style
background-color: #f0f0f0;
*/
} }
#searchdialog { #searchdialog {