Skip to content

armgit / ente

Public Imported from GitHub
0

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

flags

Manav Rathicfad9f841ef8
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index 6def77972c..a4d129459f 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -14,6 +14,7 @@ import { ensureElectron } from "@/next/electron";
import log from "@/next/log";
import { ComlinkWorker } from "@/next/worker/comlink-worker";
import { proxy } from "comlink";
+import { getRemoteFlag, updateRemoteFlag } from "../remote-store";
import type { UploadItem } from "../upload/types";
import { regenerateFaceCrops } from "./crop";
import { clearMLDB, faceIndex, indexableAndIndexedCounts } from "./db";
@@ -185,6 +186,17 @@ const setIsMLEnabledLocally = (enabled: boolean) =>
? localStorage.setItem("faceIndexingEnabled", "1")
: localStorage.removeItem("faceIndexingEnabled");
+/**
+ * For historical reasons, this is called "faceSearchEnabled" (it started off as
+ * a flag to ensure we have taken the face recognition consent from the user).
+ *
+ * Now it tracks the status of ML in general (which includes faces + consent).
+ */
+const mlRemoteKey = "faceSearchEnabled";
+const getIsMLEnabledRemote = () => getRemoteFlag(mlRemoteKey);
+const updateIsMLEnabledRemote = (enabled: boolean) =>
+ updateRemoteFlag(mlRemoteKey, enabled);
+
/**
* Trigger a "sync", whatever that means for the ML subsystem.
*
diff --git a/web/packages/new/photos/services/remote-store.ts b/web/packages/new/photos/services/remote-store.ts
index d9e26dd680..1501c0d220 100644
--- a/web/packages/new/photos/services/remote-store.ts
+++ b/web/packages/new/photos/services/remote-store.ts
@@ -3,7 +3,9 @@ import { apiURL } from "@/next/origins";
import { z } from "zod";
/**
- * Fetch the value of a remote value for the given {@link key}.
+ * Fetch the value for the given {@link key} from remote store.
+ *
+ * If the key is not present in the remote store, return `undefined`.
*/
export const getRemoteValue = async (key: string) => {
const url = await apiURL("/remote-store");
@@ -12,8 +14,30 @@ export const getRemoteValue = async (key: string) => {
headers: await authenticatedRequestHeaders(),
});
ensureOk(res);
- const data = GetRemoteStoreResponse.parse(await res.json());
- return data?.value;
+ return GetRemoteStoreResponse.parse(await res.json())?.value;
};
const GetRemoteStoreResponse = z.object({ value: z.string() }).nullable();
+
+/**
+ * Convenience wrapper over {@link getRemoteValue} that returns booleans.
+ */
+export const getRemoteFlag = async (key: string) =>
+ (await getRemoteValue(key)) == "true";
+
+/**
+ * Update or insert {@link value} for the given {@link key} into remote store.
+ */
+export const updateRemoteValue = async (key: string, value: string) =>
+ ensureOk(
+ await fetch(await apiURL("/remote-store/update"), {
+ headers: await authenticatedRequestHeaders(),
+ body: JSON.stringify({ key, value }),
+ }),
+ );
+
+/**
+ * Convenience wrapper over {@link updateRemoteValue} that sets booleans.
+ */
+export const updateRemoteFlag = (key: string, value: boolean) =>
+ updateRemoteValue(key, JSON.stringify(value));