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 | 13 |
1 files changed, 8 insertions, 5 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 74084b8..77d050e 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/photo-sync.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/photo-sync.js @@ -229,8 +229,11 @@ async function send(transport, cfg, items, metered) { setState({ phase: 'up_to_date', done, total: items.length }); } -/** One photo, under a slot the node granted — the backup queues like anyone. */ -async function upload(transport, item) { +/** + * One photo, under a slot the node granted: the backup queues like anyone. + * `file` is how its bytes come from the phone; contacts and messages pass theirs. + */ +export async function upload(transport, item, file = platform.photoSync.file) { const lease = transport.openTransfer({ kind: 'upload', bytes: item.size }); try { let timeout; @@ -240,8 +243,8 @@ async function upload(transport, item) { timeout = setTimeout(() => reject(new Error('The node is busy')), LEASE_WAIT_MS); }), ]).finally(() => clearTimeout(timeout)); - const file = await platform.photoSync.file(item.token, item.name); - return await transport.uploadFile(file, { + const bytes = await file(item.token, item.name); + return await transport.uploadFile(bytes, { dir: item.dir, root: item.dir.split('/')[0], tr: lease.tr, }); } finally { @@ -250,7 +253,7 @@ async function upload(transport, item) { } /** `<folder>/YYYY/YYYY-MM`, one level at a time; a level that exists is fine. */ -async function makeDirs(transport, folder, dir, dirs) { +export async function makeDirs(transport, folder, dir, dirs) { let at = folder; for (const name of dir.slice(folder.length + 1).split('/').filter(Boolean)) { const next = `${at}/${name}`; |