[desktop] Split x-client-package and x-client-version to match mobile (#6008)

This commit is contained in:
Manav Rathi
2025-05-22 17:49:20 +05:30
committed by GitHub
4 changed files with 29 additions and 9 deletions

View File

@@ -62,8 +62,7 @@ export const staticAppTitle = {
/**
* Client "package names" for our app.
*
* The package name is used as the (a) "X-Client-Package" header in API
* requests, and (b) as the identifier in inline user agent strings in payloads.
* The package name is used as the "X-Client-Package" header in API requests.
*
* In cases where this code works for both a web and a desktop app for the same
* app (currently only photos), this will be the platform specific package name.
@@ -72,9 +71,7 @@ export const clientPackageName = (() => {
if (isDesktop) {
if (appName != "photos")
throw new Error(`Unsupported desktop appName ${appName}`);
if (!desktopAppVersion)
throw new Error(`desktopAppVersion is not defined`);
return `io.ente.photos.desktop/${desktopAppVersion}`;
return "io.ente.photos.desktop";
}
return {
accounts: "io.ente.accounts.web",
@@ -83,3 +80,23 @@ export const clientPackageName = (() => {
photos: "io.ente.photos.web",
}[appName];
})();
/**
* The client package name, augmented with the client version where applicable.
*
* This string is used as the "client identifier" in payloads (e.g. ML data
* generated by a client).
*
* For the desktop app, it will be client package name and version. Otherwise,
* it'll just be the same as {@link clientPackageName}.
*/
export const clientIdentifier = (() => {
if (isDesktop) {
if (appName != "photos")
throw new Error(`Unsupported desktop appName ${appName}`);
if (!desktopAppVersion)
throw new Error(`desktopAppVersion is not defined`);
return `io.ente.photos.desktop/${desktopAppVersion}`;
}
return clientPackageName;
})();

View File

@@ -1,3 +1,4 @@
import { desktopAppVersion, isDesktop } from "ente-base/app";
import { wait } from "ente-utils/promise";
import { z } from "zod";
import { clientPackageName } from "./app";
@@ -14,6 +15,7 @@ import log from "./log";
export const authenticatedRequestHeaders = async () => ({
"X-Auth-Token": await ensureAuthToken(),
"X-Client-Package": clientPackageName,
...(isDesktop ? { "X-Client-Version": desktopAppVersion } : {}),
});
/**
@@ -25,6 +27,7 @@ export const authenticatedRequestHeaders = async () => ({
*/
export const publicRequestHeaders = () => ({
"X-Client-Package": clientPackageName,
...(isDesktop ? { "X-Client-Version": desktopAppVersion } : {}),
});
/**

View File

@@ -64,7 +64,7 @@ const isDesktop = process.env._ENTE_IS_DESKTOP ? "1" : "";
/**
* When we're running within the desktop app, also extract the version of the
* desktop app for use in our "X-Client-Package" string.
* desktop app for use in our "X-Client-Version" string.
*
* > The web app has continuous deployments, and doesn't have versions.
*/

View File

@@ -1,5 +1,5 @@
import { expose, wrap } from "comlink";
import { clientPackageName } from "ente-base/app";
import { clientIdentifier } from "ente-base/app";
import { assertionFailed } from "ente-base/assert";
import { isHTTP4xxError, isHTTPErrorWithStatus } from "ente-base/http";
import log from "ente-base/log";
@@ -590,13 +590,13 @@ const index = async (
const remoteFaceIndex = existingRemoteFaceIndex ?? {
version: faceIndexingVersion,
client: clientPackageName,
client: clientIdentifier,
...faceIndex,
};
const remoteCLIPIndex = existingRemoteCLIPIndex ?? {
version: clipIndexingVersion,
client: clientPackageName,
client: clientIdentifier,
...clipIndex,
};