Fix
This commit is contained in:
parent
62160354bf
commit
3dc31548bf
|
@ -69,21 +69,27 @@
|
|||
throw new Error('Network response was not ok.');
|
||||
}
|
||||
|
||||
const newData = await response.json();
|
||||
localStorage.clear();
|
||||
|
||||
Object.entries(newData).forEach(([key, value]) => {
|
||||
localStorage.setItem(key, value);
|
||||
});
|
||||
console.log('Fetched savedata');
|
||||
window.reload();
|
||||
const lastModifiedServer = new Date(response.headers.get('Last-Modified'));
|
||||
const lastModifiedLocal = new Date(localStorage.getItem('lastModified'));
|
||||
|
||||
if (lastModifiedServer > lastModifiedLocal || !lastModifiedLocal) {
|
||||
const newData = await response.json();
|
||||
localStorage.clear();
|
||||
|
||||
Object.entries(newData).forEach(([key, value]) => {
|
||||
localStorage.setItem(key, value);
|
||||
});
|
||||
|
||||
localStorage.setItem('lastModified', lastModifiedServer.toISOString());
|
||||
console.log('Fetched savedata');
|
||||
} else {
|
||||
console.log('Local data is up-to-date or server data older.');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching localStorage:', error);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async function syncLocalStorage(){
|
||||
console.log("Syncing...")
|
||||
uploadLocalStorage();
|
||||
|
|
Loading…
Reference in New Issue