Browse Source

fix-sync-empty-local-not-win

master
Serge Shutov 2 weeks ago
parent
commit
c612444581
  1. 3
      content/storage-bridge.js
  2. 2
      memory/state.json

3
content/storage-bridge.js

@ -10,7 +10,8 @@ function fetchRemote() {return authHeaders().then(function(h){return fetch(BU+"/ @@ -10,7 +10,8 @@ function fetchRemote() {return authHeaders().then(function(h){return fetch(BU+"/
function putRemote(s) {return authHeaders().then(function(h){return fetch(BU+"/"+"memory/state",{method:"PUT",headers:h,body:JSON.stringify(s)})}).then(function(r){if(!r.ok)throw new Error("PUT "+r.status);return r.json()}).then(function(j){return j&&j.ok})};
function newer(a,b) {return (a&&a.updatedAt?a.updatedAt:"") >= (b&&b.updatedAt?b.updatedAt:"")};
function sync() {return Promise.all([loadLocal(),fetchRemote().catch(function(){return null})]).then(function(arr){var loc=arr[0],rem=arr[1];if(!rem)return loc;if(newer(loc,rem)){putRemote(loc).catch(function(){});return loc};return saveLocal(rem).then(function(){return rem})})};
function isEmpty(s) {return !s || ((s.memories ? Object.keys(s.memories).length : 0) + (s.skills ? s.skills.length : 0) === 0)};
function sync() {return Promise.all([loadLocal(),fetchRemote().catch(function(){return null})]).then(function(arr){var loc=arr[0],rem=arr[1];if(!rem)return loc;var le=isEmpty(loc),re=isEmpty(rem);if(le!==re){if(le){return saveLocal(rem).then(function(){return rem})}putRemote(loc).catch(function(){});return loc};if(newer(loc,rem)){putRemote(loc).catch(function(){});return loc};return saveLocal(rem).then(function(){return rem})})};
function getState() {return sync()};
function putState(s) {var v={version:1,updatedAt:new Date().toISOString(),memories:s.memories||{},skills:s.skills||[]};return saveLocal(v).then(function(){return putRemote(v).catch(function(){return false})}).then(function(){return v})};

2
memory/state.json

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
{
"version": 1,
"updatedAt": "2026-10-31T02:11:46.453Z",
"updatedAt": "2026-10-31T03:11:08.923Z",
"memories": {},
"skills": []
}
Loading…
Cancel
Save