fix fetch modified notes from server

This commit is contained in:
quenousimporte 2024-02-15 16:39:31 +01:00
parent 5f049cf587
commit 4f33d65317
1 changed files with 40 additions and 15 deletions

55
main.js
View File

@ -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