Skip to content

armgit / ente

Public Imported from GitHub
0

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

swap

Manav Rathi72aec4bc5ab5
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts
index db97ec547a..0b16e729e4 100644
--- a/web/apps/photos/src/services/collectionService.ts
+++ b/web/apps/photos/src/services/collectionService.ts
@@ -37,6 +37,7 @@ import {
groupFilesByCollectionID,
sortFiles,
} from "ente-new/photos/services/files";
+import { getPublicKey } from "ente-new/photos/services/user";
import HTTPService from "ente-shared/network/HTTPService";
import { getData } from "ente-shared/storage/localStorage";
import { getToken } from "ente-shared/storage/localStorage/helpers";
@@ -48,7 +49,6 @@ import {
isQuickLinkCollection,
isValidMoveTarget,
} from "utils/collection";
-import { getPublicKey } from "./userService";
const UNCATEGORIZED_COLLECTION_NAME = "Uncategorized";
export const HIDDEN_COLLECTION_NAME = ".hidden";
diff --git a/web/apps/photos/src/services/userService.ts b/web/apps/photos/src/services/userService.ts
index 4d7c790f4b..41fe2acce1 100644
--- a/web/apps/photos/src/services/userService.ts
+++ b/web/apps/photos/src/services/userService.ts
@@ -4,17 +4,6 @@ import type { UserDetails } from "ente-new/photos/services/user-details";
import HTTPService from "ente-shared/network/HTTPService";
import { getToken } from "ente-shared/storage/localStorage/helpers";
-export const getPublicKey = async (email: string) => {
- const token = getToken();
-
- const resp = await HTTPService.get(
- await apiURL("/users/public-key"),
- { email },
- { "X-Auth-Token": token },
- );
- return resp.data.publicKey;
-};
-
export const getUserDetailsV2 = async (): Promise<UserDetails> => {
try {
const token = getToken();
diff --git a/web/packages/new/photos/services/user.ts b/web/packages/new/photos/services/user.ts
index 0817446499..7b8b84dfea 100644
--- a/web/packages/new/photos/services/user.ts
+++ b/web/packages/new/photos/services/user.ts
@@ -3,6 +3,23 @@ import { apiURL } from "ente-base/origins";
import { nullToUndefined } from "ente-utils/transform";
import { z } from "zod";
+/**
+ * Fetch the public key from remote for the user (if any) who has registered
+ * with remote with the given {@link email}.
+ *
+ * @returns the base64 encoded public key of the user with {@link email}.
+ */
+export const getPublicKey = async (email: string) => {
+ const params = new URLSearchParams({ email });
+ const url = await apiURL("/users/public-key");
+ const res = await fetch(`${url}?${params.toString()}`, {
+ headers: await authenticatedRequestHeaders(),
+ });
+ ensureOk(res);
+ return z.object({ publicKey: z.string() }).parse(await res.json())
+ .publicKey;
+};
+
/**
* Fetch the two-factor status (whether or not it is enabled) from remote.
*/