aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/platform.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/platform.js')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/platform.js28
1 files changed, 21 insertions, 7 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/platform.js b/packages/meshbay-hub/src/meshbay_hub/static/platform.js
index 2cfa673..8effc21 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/platform.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/platform.js
@@ -238,8 +238,8 @@ export const push = {
export const photoSync = {
available: Boolean(bridge && bridge.photoSync),
status() { return bridge.photoSync.status(); },
- permit() { return bridge.photoSync.permit(); },
- albums() { return bridge.photoSync.albums(); },
+ permit(withVideos) { return bridge.photoSync.permit(withVideos); },
+ albums(withVideos) { return bridge.photoSync.albums(withVideos); },
configure(settings) { return bridge.photoSync.configure(settings); },
estimate(settings) { return bridge.photoSync.estimate(settings); },
plan() { return bridge.photoSync.plan(); },
@@ -247,11 +247,25 @@ export const photoSync = {
completed() { return bridge.photoSync.completed(); },
failed(code, text) { return bridge.photoSync.failed(code, text); },
keepAlive(on, text) { return bridge.photoSync.keepAlive(on, text); },
- /** The bytes of a photo the last plan issued, as a File named for the node. */
- async file(token, name) {
- const r = await fetch(`/photosync/${encodeURIComponent(token)}`, { cache: 'no-store' });
- if (!r.ok) throw new Error('This photo is no longer on the phone');
- return new File([await r.blob()], name);
+ /**
+ * A photo or video the last plan issued, as what an upload reads (`name`,
+ * `size`, `slice(a, b).arrayBuffer()`): each slice is fetched from the phone
+ * when it is read, so a video of gigabytes is never whole in this page.
+ */
+ file(token, name, size) {
+ const url = `/photosync/${encodeURIComponent(token)}`;
+ const part = (start, end) => ({
+ async arrayBuffer() {
+ if (end <= start) return new ArrayBuffer(0);
+ const r = await fetch(url, { cache: 'no-store', headers: { Range: `bytes=${start}-${end - 1}` } });
+ if (r.status !== 206) throw new Error('This photo is no longer on the phone');
+ return r.arrayBuffer();
+ },
+ });
+ return {
+ name, size,
+ slice: (a = 0, b = size) => part(Math.max(0, a), Math.min(b, size)),
+ };
},
};