Skip to content

armgit / ente

Public Imported from GitHub
0

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

Reorder

Manav Rathic8f3df3969e3
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index f567efefc6..aeb3abe806 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -90,6 +90,64 @@ export const logoutML = async () => {
await clearFaceDB();
};
+/**
+ * Return true if we should show an option to the user to allow them to enable
+ * face search in the UI.
+ */
+export const canEnableFaceIndexing = async () =>
+ (await isInternalUser()) || (await isBetaUser());
+
+/**
+ * Return true if the user has enabled machine learning in their preferences.
+ *
+ * TODO-ML: The UI for this needs rework. We might retain the older remote (and
+ * local) storage key, but otherwise this setting now reflects the state of ML
+ * overall and not just face search.
+ */
+export const isMLEnabled = () => _isMLEnabled;
+
+/**
+ * Enable ML.
+ *
+ * Persist the user's preference and trigger a sync.
+ */
+export const enableML = () => {
+ setIsFaceIndexingEnabled(true);
+ _isMLEnabled = true;
+ triggerMLSync();
+};
+
+/**
+ * Disable ML
+ *
+ * Stop any in-progress ML tasks and persist the user's preference.
+ */
+export const disableML = () => {
+ terminateMLWorker();
+ setIsFaceIndexingEnabled(false);
+ _isMLEnabled = false;
+};
+
+/**
+ * Return true if the user has enabled face indexing in the app's settings.
+ *
+ * This setting is persisted locally (in local storage) and is not synced with
+ * remote. There is a separate setting, "faceSearchEnabled" that is synced with
+ * remote, but that tracks whether or not the user has enabled face search once
+ * on any client. This {@link isFaceIndexingEnabled} property, on the other
+ * hand, denotes whether or not indexing is enabled on the current client.
+ */
+export const isFaceIndexingEnabled = () =>
+ localStorage.getItem("faceIndexingEnabled") == "1";
+
+/**
+ * Update the (locally stored) value of {@link isFaceIndexingEnabled}.
+ */
+const setIsFaceIndexingEnabled = (enabled: boolean) =>
+ enabled
+ ? localStorage.setItem("faceIndexingEnabled", "1")
+ : localStorage.removeItem("faceIndexingEnabled");
+
/**
* Trigger a "sync", whatever that means for the ML subsystem.
*
@@ -161,64 +219,6 @@ export const unidentifiedFaceIDs = async (
return index?.faceEmbedding.faces.map((f) => f.faceID) ?? [];
};
-/**
- * Return true if we should show an option to the user to allow them to enable
- * face search in the UI.
- */
-export const canEnableFaceIndexing = async () =>
- (await isInternalUser()) || (await isBetaUser());
-
-/**
- * Return true if the user has enabled face indexing in the app's settings.
- *
- * This setting is persisted locally (in local storage) and is not synced with
- * remote. There is a separate setting, "faceSearchEnabled" that is synced with
- * remote, but that tracks whether or not the user has enabled face search once
- * on any client. This {@link isFaceIndexingEnabled} property, on the other
- * hand, denotes whether or not indexing is enabled on the current client.
- */
-export const isFaceIndexingEnabled = () =>
- localStorage.getItem("faceIndexingEnabled") == "1";
-
-/**
- * Update the (locally stored) value of {@link isFaceIndexingEnabled}.
- */
-const setIsFaceIndexingEnabled = (enabled: boolean) =>
- enabled
- ? localStorage.setItem("faceIndexingEnabled", "1")
- : localStorage.removeItem("faceIndexingEnabled");
-
-/**
- * Return true if the user has enabled machine learning in their preferences.
- *
- * TODO-ML: The UI for this needs rework. We might retain the older remote (and
- * local) storage key, but otherwise this setting now reflects the state of ML
- * overall and not just face search.
- */
-export const isMLEnabled = () => _isMLEnabled;
-
-/**
- * Enable ML.
- *
- * Persist the user's preference and trigger a sync.
- */
-export const enableML = () => {
- setIsFaceIndexingEnabled(true);
- _isMLEnabled = true;
- triggerMLSync();
-};
-
-/**
- * Disable ML
- *
- * Stop any in-progress ML tasks and persist the user's preference.
- */
-export const disableML = () => {
- terminateMLWorker();
- setIsFaceIndexingEnabled(false);
- _isMLEnabled = false;
-};
-
/**
* Sync face DB with the local (and potentially indexable) files that we know
* about. Then return the next {@link count} files that still need to be