diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/photo-sync.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/photo-sync.js | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/photo-sync.js b/packages/meshbay-hub/src/meshbay_hub/static/photo-sync.js index 1439c20..a9d4517 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/photo-sync.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/photo-sync.js @@ -172,8 +172,8 @@ export function createBackup({ if (refused === 'offline') { setState({ phase: 'offline' }); return; } if (refused) { await lasting(refused); return; } - const { items } = await sync.plan(); - if (!items.length) { + const { items, manifest } = await sync.plan(); + if (!items.length && !manifest) { await sync.completed(); setState({ phase: 'up_to_date', done: 0, total: 0 }); return; @@ -246,10 +246,29 @@ export function createBackup({ done += 1; await sync.keepAlive(true, report()); } + if (!await sendManifest(transport, dest, dirs)) return; await sync.completed(); setState({ phase: 'up_to_date', done, total: items.length }); } + // What the phone knew of what was sent (its path and album, its dates and + // hash), for a restore or a merge later: one file per run that sent + // anything, beside the files, kept by the phone until the node has it. + // False when a lasting refusal stopped it, which is then said. + async function sendManifest(transport, dest, dirs) { + const { item } = await sync.manifest(); + if (!item) return true; + try { + await makeDirs(transport, dest.folder, item.dir, dirs); + await upload(transport, item, sync.file); + } catch (e) { + if (e.code && failures[e.code]) { await lasting(e.code); return false; } + throw e; + } + await sync.manifestSent(item.token); + return true; + } + async function lasting(code) { setState({ phase: 'failed', reason: code }); await sync.failed(code, say(code)).catch(() => {}); |