Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

transform 1

Manav Rathi1d276c795c00
diff --git a/desktop/src/main/services/ffmpeg-worker.ts b/desktop/src/main/services/ffmpeg-worker.ts
index f14f3fc53f..5e16772372 100644
--- a/desktop/src/main/services/ffmpeg-worker.ts
+++ b/desktop/src/main/services/ffmpeg-worker.ts
@@ -840,11 +840,8 @@ const uploadVideoSegments = async (
// because when we use the node native fetch then we need to
// provide it explicitly.
headers: { "Content-Length": `${videoSize}` },
- // The duplex option is required since we're passing a stream.
- //
- // @ts-expect-error TypeScript's libdom.d.ts does not include
- // the "duplex" parameter, e.g. see
- // https://github.com/node-fetch/node-fetch/issues/1769.
+ // See: [Note: duplex param required for stream body]
+ // @ts-expect-error ^see note above
duplex: "half",
body: webStream,
});
diff --git a/web/packages/gallery/services/upload/remote.ts b/web/packages/gallery/services/upload/remote.ts
index 063511d224..94a5df3bad 100644
--- a/web/packages/gallery/services/upload/remote.ts
+++ b/web/packages/gallery/services/upload/remote.ts
@@ -271,7 +271,21 @@ export const putFilePart = async (
fetch(partUploadURL, {
method: "PUT",
headers: publicRequestHeaders(),
- body: partData,
+ // @ts-expect-error See: [Note: duplex param required for stream body]
+ duplex: "half",
+ // Pipe the part data via a transform stream so that we can report progress.
+ body: new Response(partData).body!.pipeThrough(
+ new TransformStream({
+ start() {
+ console.log("start");
+ },
+ transform(chunk, controller) {
+ console.log("chunk", chunk);
+ onProgress(chunk.length /* dummy value for now */);
+ controller.enqueue(chunk);
+ },
+ }),
+ ),
}),
);
return nullToUndefined(res.headers.get("etag"));
diff --git a/web/packages/gallery/utils/native-stream.ts b/web/packages/gallery/utils/native-stream.ts
index 7abbcfec56..4a3afb7ff9 100644
--- a/web/packages/gallery/utils/native-stream.ts
+++ b/web/packages/gallery/utils/native-stream.ts
@@ -105,11 +105,16 @@ export const writeStream = async (
const req = new Request(url, {
// GET can't have a body
method: "POST",
- body: stream,
- // @ts-expect-error TypeScript's libdom.d.ts does not include the
- // "duplex" parameter, e.g. see
+ // [Note: duplex param required for stream body]
+ //
+ // The duplex parameter needs to be set to 'half' when streaming
+ // requests. However, TypeScript's libdom.d.ts does not include the
+ // "duplex" parameter, so we need to silence the tsc error. e.g. see
// https://github.com/node-fetch/node-fetch/issues/1769.
+ //
+ // @ts-expect-error See: [Note: duplex param required for stream body]
duplex: "half",
+ body: stream,
});
const res = await fetch(req);
@@ -227,11 +232,7 @@ export const initiateGenerateHLS = async (
const url = `stream://video?${params.toString()}`;
const res = await fetch(url, {
method: "POST",
- // The duplex option is required when body is a stream.
- //
- // @ts-expect-error TypeScript's libdom.d.ts does not include the
- // "duplex" parameter, e.g. see
- // https://github.com/node-fetch/node-fetch/issues/1769.
+ // @ts-expect-error See: [Note: duplex param required for stream body]
duplex: "half",
body,
});