Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use new

Manav Rathic5cd6cbbca52
diff --git a/web/apps/photos/src/components/ml/MLSearchSettings.tsx b/web/apps/photos/src/components/ml/MLSearchSettings.tsx
index 80b09d0e81..66eac5a578 100644
--- a/web/apps/photos/src/components/ml/MLSearchSettings.tsx
+++ b/web/apps/photos/src/components/ml/MLSearchSettings.tsx
@@ -2,7 +2,9 @@ import {
canEnableML,
disableML,
enableML,
+ getIsMLEnabledRemote,
isMLEnabled,
+ pauseML,
} from "@/new/photos/services/ml";
import { EnteDrawer } from "@/new/shared/components/EnteDrawer";
import { MenuItemGroup } from "@/new/shared/components/Menu";
@@ -24,10 +26,6 @@ import { t } from "i18next";
import { AppContext } from "pages/_app";
import { useContext, useEffect, useState } from "react";
import { Trans } from "react-i18next";
-import {
- getFaceSearchEnabledStatus,
- updateFaceSearchEnabledStatus,
-} from "services/userService";
export const MLSearchSettings = ({ open, onClose, onRootClose }) => {
const {
@@ -48,11 +46,11 @@ export const MLSearchSettings = ({ open, onClose, onRootClose }) => {
const enableMlSearch = async () => {
try {
- const hasEnabledFaceSearch = await getFaceSearchEnabledStatus();
- if (!hasEnabledFaceSearch) {
+ const isEnabledRemote = await getIsMLEnabledRemote();
+ if (!isEnabledRemote) {
openEnableFaceSearch();
} else {
- enableML();
+ await enableML();
}
} catch (e) {
log.error("Enable ML search failed", e);
@@ -63,9 +61,7 @@ export const MLSearchSettings = ({ open, onClose, onRootClose }) => {
const enableFaceSearch = async () => {
try {
startLoading();
- // Update the consent flag.
- await updateFaceSearchEnabledStatus(true);
- enableML();
+ await enableML();
closeEnableFaceSearch();
finishLoading();
} catch (e) {
@@ -76,7 +72,7 @@ export const MLSearchSettings = ({ open, onClose, onRootClose }) => {
const disableMlSearch = async () => {
try {
- disableML();
+ pauseML();
onClose();
} catch (e) {
log.error("Disable ML search failed", e);
@@ -87,7 +83,8 @@ export const MLSearchSettings = ({ open, onClose, onRootClose }) => {
const disableFaceSearch = async () => {
try {
startLoading();
- await disableMlSearch();
+ await disableML();
+ onClose();
finishLoading();
} catch (e) {
log.error("Disable face search failed", e);
diff --git a/web/apps/photos/src/services/userService.ts b/web/apps/photos/src/services/userService.ts
index 11da7b07c8..4c6e17e826 100644
--- a/web/apps/photos/src/services/userService.ts
+++ b/web/apps/photos/src/services/userService.ts
@@ -206,47 +206,6 @@ export const deleteAccount = async (
}
};
-export const getFaceSearchEnabledStatus = async () => {
- try {
- const token = getToken();
- const resp: AxiosResponse<GetRemoteStoreValueResponse> =
- await HTTPService.get(
- await apiURL("/remote-store"),
- {
- key: "faceSearchEnabled",
- defaultValue: false,
- },
- {
- "X-Auth-Token": token,
- },
- );
- return resp.data.value === "true";
- } catch (e) {
- log.error("failed to get face search enabled status", e);
- throw e;
- }
-};
-
-export const updateFaceSearchEnabledStatus = async (newStatus: boolean) => {
- try {
- const token = getToken();
- await HTTPService.post(
- await apiURL("/remote-store/update"),
- {
- key: "faceSearchEnabled",
- value: newStatus.toString(),
- },
- null,
- {
- "X-Auth-Token": token,
- },
- );
- } catch (e) {
- log.error("failed to update face search enabled status", e);
- throw e;
- }
-};
-
export const syncMapEnabled = async () => {
try {
const status = await getMapEnabledStatus();
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index a4d129459f..9e6c3fdda5 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -106,7 +106,7 @@ export const canEnableML = async () =>
*
* The user may enable ML. This enables in both locally by persisting a local
* storage flag, and sets a flag on remote so that the user's other devices can
- * also enable it.
+ * also enable it if they wish.
*
* The user may pause ML locally. This does not modify the remote flag, but it
* unsets the local flag. Subsequently resuming ML (locally) will set the local
@@ -124,8 +124,8 @@ export const isMLEnabled = () =>
*
* Persist the user's preference both locally and on remote, and trigger a sync.
*/
-export const enableML = () => {
- // TODO-ML: API call.
+export const enableML = async () => {
+ await updateIsMLEnabledRemote(true);
setIsMLEnabledLocally(true);
_isMLEnabled = true;
triggerMLSync();
@@ -137,8 +137,8 @@ export const enableML = () => {
* Stop any in-progress ML tasks, and persist the user's preference both locally
* and on remote.
*/
-export const disableML = () => {
- // TODO-ML: API call.
+export const disableML = async () => {
+ await updateIsMLEnabledRemote(false);
terminateMLWorker();
setIsMLEnabledLocally(false);
_isMLEnabled = false;
@@ -193,7 +193,7 @@ const setIsMLEnabledLocally = (enabled: boolean) =>
* Now it tracks the status of ML in general (which includes faces + consent).
*/
const mlRemoteKey = "faceSearchEnabled";
-const getIsMLEnabledRemote = () => getRemoteFlag(mlRemoteKey);
+export const getIsMLEnabledRemote = () => getRemoteFlag(mlRemoteKey);
const updateIsMLEnabledRemote = (enabled: boolean) =>
updateRemoteFlag(mlRemoteKey, enabled);