fix fetch modified notes from server
This commit is contained in:
parent
5f049cf587
commit
4f33d65317
33
main.js
33
main.js
|
@ -1291,6 +1291,15 @@ function pushall()
|
||||||
return Promise.all(list);
|
return Promise.all(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fetchandserialize(guid)
|
||||||
|
{
|
||||||
|
return queryremote({action: "fetch", name: guid})
|
||||||
|
.then(content =>
|
||||||
|
{
|
||||||
|
localStorage.setItem(guid, content);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function fetch()
|
function fetch()
|
||||||
{
|
{
|
||||||
return new Promise(function(resolve)
|
return new Promise(function(resolve)
|
||||||
|
@ -1311,14 +1320,30 @@ function fetch()
|
||||||
{
|
{
|
||||||
if (!filecontent)
|
if (!filecontent)
|
||||||
{
|
{
|
||||||
return pushall();
|
pushall().then(resolve);
|
||||||
}
|
}
|
||||||
else
|
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")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue