From 4f33d65317f683b9837c5f3ad08e1ec6bcae58f5 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Thu, 15 Feb 2024 16:39:31 +0100 Subject: [PATCH] fix fetch modified notes from server --- main.js | 55 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/main.js b/main.js index d8462d6..d576e91 100644 --- a/main.js +++ b/main.js @@ -1291,6 +1291,15 @@ function pushall() return Promise.all(list); } +function fetchandserialize(guid) +{ + return queryremote({action: "fetch", name: guid}) + .then(content => + { + localStorage.setItem(guid, content); + }); +} + function fetch() { return new Promise(function(resolve) @@ -1311,26 +1320,42 @@ function fetch() { if (!filecontent) { - return pushall(); + pushall().then(resolve); } else { - // compare and fetch modified and serialize all that - } + var localindex = JSON.parse(localStorage.getItem("index")); + var remoteindex = JSON.parse(filecontent); - }).catch(err => + var list = []; + Object.keys(remoteindex).forEach(guid => + { + if (!localindex[guid] || localindex[guid].lastchanged < remoteindex[guid].lastchanged) + { + list.push(fetchandserialize(guid)); + } + }); + + Promise.all(list).then( () => + { + localStorage.setItem("index", JSON.stringify(remoteindex)); + resolve(); + }); + } + }) + .catch(err => + { + if (err == "error: authent") { - if (err == "error: authent") - { - settings.password = prompt("Password: ", settings.password); - savesettings(); - init(); - } - else - { - showtemporaryinfo(err); - } - }); + settings.password = prompt("Password: ", settings.password); + savesettings(); + init(); + } + else + { + showtemporaryinfo(err); + } + }); } } else