fix fetch modified notes from server
This commit is contained in:
parent
5f049cf587
commit
4f33d65317
55
main.js
55
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
|
||||
|
|
Loading…
Reference in New Issue