π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add memory host origin and fix public memory request headers
AmanRajSinghMourya6393ada3c3a3
diff --git a/web/packages/base/origins.ts b/web/packages/base/origins.tsindex b8efcafb21..f946dc923e 100644--- a/web/packages/base/origins.ts+++ b/web/packages/base/origins.ts@@ -130,3 +130,22 @@ export const shareAppOrigin = (): string =>*/export const photosAppOrigin = (): string =>process.env.NEXT_PUBLIC_ENTE_PHOTOS_ENDPOINT ?? "https://web.ente.io";++/**+ * Return the origin that serves public memory shares.+ *+ * Defaults to our production instance, "https://memories.ente.io", but can be+ * overridden by setting the `NEXT_PUBLIC_ENTE_MEMORIES_ENDPOINT` environment+ * variable. For self-hosted setups, this can be set to the custom API origin.+ */+export const memoryHost = async (): Promise<string> => {+ const custom = await customAPIOrigin();+ if (custom) {+ // For self-hosted, point to the custom API with the memories path+ return `${custom}/memories`;+ }+ return (+ process.env.NEXT_PUBLIC_ENTE_MEMORIES_ENDPOINT ??+ "https://memories.ente.io"+ );+};diff --git a/web/packages/new/albums/services/public-memory.ts b/web/packages/new/albums/services/public-memory.tsindex c425635337..9e81d829e2 100644--- a/web/packages/new/albums/services/public-memory.ts+++ b/web/packages/new/albums/services/public-memory.ts@@ -1,9 +1,5 @@import { decryptBoxBytes } from "ente-base/crypto";-import {- authenticatedPublicAlbumsRequestHeaders,- ensureOk,- type PublicAlbumsCredentials,-} from "ente-base/http";+import { ensureOk, publicRequestHeaders } from "ente-base/http";import { apiURL } from "ente-base/origins";import {decryptRemoteFile,@@ -13,21 +9,27 @@ import {import { z } from "zod";/**- * Credentials for accessing a public memory share.+ * Credentials needed to make public memory share related API requests.*/export interface PublicMemoryCredentials {+ /**+ * The access token for the public memory share.+ *+ * This is obtained from the "t" query parameter of the share URL.+ * It both identifies the share and authenticates the request.+ */accessToken: string;}/**- * Request headers for authenticated public memory share requests.+ * Return headers for public memory share API requests.*/-export const authenticatedPublicMemoryRequestHeaders = (- credentials: PublicMemoryCredentials,-): ReturnType<typeof authenticatedPublicAlbumsRequestHeaders> =>- authenticatedPublicAlbumsRequestHeaders(- credentials as PublicAlbumsCredentials,- );+export const authenticatedPublicMemoryRequestHeaders = ({+ accessToken,+}: PublicMemoryCredentials) => ({+ "X-Auth-Access-Token": accessToken,+ ...publicRequestHeaders(),+});/*** Information about a public memory share fetched from remote.@@ -61,7 +63,7 @@ export const getPublicMemoryInfo = async (accessToken: string,): Promise<PublicMemoryShareInfo> => {const res = await fetch(await apiURL("/public-memory/info"), {- headers: authenticatedPublicAlbumsRequestHeaders({ accessToken }),+ headers: authenticatedPublicMemoryRequestHeaders({ accessToken }),});ensureOk(res);const { memoryShare } = PublicMemoryShareInfoResponse.parse(@@ -95,7 +97,7 @@ export const getPublicMemoryFiles = async (shareKey: string,): Promise<EnteFile[]> => {const res = await fetch(await apiURL("/public-memory/files"), {- headers: authenticatedPublicAlbumsRequestHeaders({ accessToken }),+ headers: authenticatedPublicMemoryRequestHeaders({ accessToken }),});ensureOk(res);const { files } = PublicMemoryShareFilesResponse.parse(await res.json());