π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
ver
Manav Rathi6d13ff5151b2
diff --git a/desktop/src/main/services/ffmpeg-worker.ts b/desktop/src/main/services/ffmpeg-worker.tsindex e9131568c8..f3b3cefa04 100644--- a/desktop/src/main/services/ffmpeg-worker.ts+++ b/desktop/src/main/services/ffmpeg-worker.ts@@ -12,6 +12,7 @@ import fs_ from "node:fs";import fs from "node:fs/promises";import path from "node:path";import { Readable } from "node:stream";+import { z } from "zod";import type { FFmpegCommand } from "../../types/ipc";import log from "../log-worker";import { messagePortMainEndpoint } from "../utils/comlink";@@ -56,6 +57,8 @@ log.debugString("Started ffmpeg utility process");process.on("uncaughtException", (e, origin) => log.error(origin, e));process.parentPort.once("message", (e) => {+ // Initialize ourselves with the data we got from our parent.+ parseInitData(e.data);// Expose an instance of `FFmpegUtilityProcess` on the port we got from our// parent.expose(@@ -67,9 +70,26 @@ process.parentPort.once("message", (e) => {} satisfies FFmpegUtilityProcess,messagePortMainEndpoint(e.ports[0]!),);+ // Let the main process know we're ready.mainProcess("ack", undefined);});+/**+ * We cannot access Electron's {@link app} object within a utility process, so+ * we pass the value of `app.getVersion()` during initialization, and it can be+ * subsequently retrieved from here.+ */+let _desktopAppVersion: string | undefined;++/** Equivalent to `app.getVersion()` */+const desktopAppVersion = () => _desktopAppVersion!;++const FFmpegWorkerInitData = z.object({ appVersion: z.string() });++const parseInitData = (data: unknown) => {+ _desktopAppVersion = FFmpegWorkerInitData.parse(data).appVersion;+};+/*** Send a message to the main process using a barebones RPC protocol.*/@@ -846,7 +866,7 @@ const uploadVideoSegmentsSingle = (// net.fetch deduces and inserts a content-length for us, when we// use the node native fetch then we need to provide it explicitly.headers: {- ...publicRequestHeaders(),+ ...publicRequestHeaders(desktopAppVersion()),"Content-Length": `${videoSize}`,},// See: [Note: duplex param required for stream body]@@ -921,7 +941,7 @@ const uploadVideoSegmentsMultipart = async (fetch(partUploadURL, {method: "PUT",headers: {- ...publicRequestHeaders(),+ ...publicRequestHeaders(desktopAppVersion()),"Content-Length": `${size}`,},// See: [Note: duplex param required for stream body]@@ -946,7 +966,10 @@ const uploadVideoSegmentsMultipart = async (return await retryEnsuringHTTPOk(() =>fetch(completionURL, {method: "POST",- headers: { ...publicRequestHeaders(), "Content-Type": "text/xml" },+ headers: {+ ...publicRequestHeaders(desktopAppVersion()),+ "Content-Type": "text/xml",+ },body: completionBody,}),);diff --git a/desktop/src/main/services/workers.ts b/desktop/src/main/services/workers.tsindex 1dd5e5ae67..ee6c5961ea 100644--- a/desktop/src/main/services/workers.ts+++ b/desktop/src/main/services/workers.ts@@ -182,8 +182,10 @@ const createFFmpegUtilityProcessEndpoint = () => {const child = utilityProcess.fork(path.join(__dirname, "ffmpeg-worker.js"));// Send a handle to the port (one end of the message channel) to the utility- // process. The utility process will reply with an "ack" when it get it.- child.postMessage({}, [port1]);+ // process (alongwith any other init data). The utility process will reply+ // with an "ack" when it get it.+ const appVersion = app.getVersion();+ child.postMessage(/* FFmpegWorkerInitData */ { appVersion }, [port1]);child.on("message", (m: unknown) => {if (m && typeof m == "object" && "method" in m) {diff --git a/desktop/src/main/utils/http.ts b/desktop/src/main/utils/http.tsindex ca5b71a1bd..6496b99cc6 100644--- a/desktop/src/main/utils/http.ts+++ b/desktop/src/main/utils/http.ts@@ -1,11 +1,16 @@export const clientPackageName = "io.ente.photos.desktop";/**- * Partial implementation of {@link publicRequestHeaders} from the web source.- * It does not contain the "X-Client-Version" because app.getVersion() is not- * accessible to Electron utility processes.+ * Reimplementation of {@link publicRequestHeaders} from the web source.+ *+ * @param desktopAppVersion The desktop app's version. This will get passed on+ * as the "X-Client-Version" header.+ *+ * We cannot directly use `app.getVersion()` to obtain this value since the+ * {@link app} module is not accessible to Electron utility processes which also+ * calls this function.*/-export const publicRequestHeaders = () => ({+export const publicRequestHeaders = (desktopAppVersion: string) => ({"X-Client-Package": clientPackageName,- // "X-Client-Version": desktopAppVersion+ "X-Client-Version": desktopAppVersion});