π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix embed app runtime errors and update branding
Manav Rathi780e7fc5ff37
diff --git a/web/apps/embed/eslint.config.mjs b/web/apps/embed/eslint.config.mjsindex 3fb4491a25..641d994d1e 100644--- a/web/apps/embed/eslint.config.mjs+++ b/web/apps/embed/eslint.config.mjs@@ -1 +1 @@-export { default } from "ente-build-config/eslint.config.base.mjs";+export { default } from "ente-build-config/eslintrc-next-app.mjs";diff --git a/web/apps/embed/src/components/EmbedFileList.tsx b/web/apps/embed/src/components/EmbedFileList.tsxindex 9c9f2d17ac..15143cfcfe 100644--- a/web/apps/embed/src/components/EmbedFileList.tsx+++ b/web/apps/embed/src/components/EmbedFileList.tsx@@ -116,7 +116,7 @@ const EmbedFileTile: React.FC<EmbedFileTileProps> = memo(style={{ width: size, height: size }}/>);- }, [isLoading, thumbnailSrc, size]);+ }, [isLoading, thumbnailSrc, size, file.metadata.fileType]);return (<TileContainerdiff --git a/web/apps/embed/src/components/EmbedFileListWithViewer.tsx b/web/apps/embed/src/components/EmbedFileListWithViewer.tsxindex edc3f7e83a..2d759e4c3f 100644--- a/web/apps/embed/src/components/EmbedFileListWithViewer.tsx+++ b/web/apps/embed/src/components/EmbedFileListWithViewer.tsx@@ -40,12 +40,15 @@ export const EmbedFileListWithViewer: React.FC<[files],);- const handleThumbnailClick = useCallback((index: number) => {- console.log("Thumbnail clicked, index:", index);- console.log("Files available:", files.length);- setCurrentIndex(index);- setOpenFileViewer(true);- }, [files.length]);+ const handleThumbnailClick = useCallback(+ (index: number) => {+ console.log("Thumbnail clicked, index:", index);+ console.log("Files available:", files.length);+ setCurrentIndex(index);+ setOpenFileViewer(true);+ },+ [files.length],+ );const handleCloseFileViewer = useCallback(() => {console.log("Closing file viewer");@@ -76,27 +79,23 @@ export const EmbedFileListWithViewer: React.FC<fontSize: "0.8em","&:hover .powered-text": {color: "text.base",- cursor: "pointer"+ cursor: "pointer",},"&:hover .ente-logo": {color: "#1db954",- cursor: "pointer"- }+ cursor: "pointer",+ },}}><spanclassName="powered-text"- style={{- transition: "color 0.2s ease"- }}+ style={{ transition: "color 0.2s ease" }}>powered by</span><spanclassName="ente-logo"- style={{- transition: "color 0.2s ease"- }}+ style={{ transition: "color 0.2s ease" }}><EnteLogo height={14} /></span>@@ -142,7 +141,6 @@ export const EmbedFileListWithViewer: React.FC<const Container = styled("div")({ flex: 1, width: "100%" });-const fileTimelineDateString = (file: EnteFile) => {const date = new Date(fileCreationTime(file) / 1000);return isSameDay(date, new Date())diff --git a/web/apps/embed/src/pages/_app.tsx b/web/apps/embed/src/pages/_app.tsxindex 97efd18d8c..dac5406386 100644--- a/web/apps/embed/src/pages/_app.tsx+++ b/web/apps/embed/src/pages/_app.tsx@@ -1,6 +1,4 @@import "@fontsource-variable/inter";-import "photoswipe/dist/photoswipe.css";-import "styles/photoswipe.css";import { CssBaseline } from "@mui/material";import { ThemeProvider } from "@mui/material/styles";import { CustomHeadPhotosOrAlbums } from "ente-base/components/Head";@@ -16,14 +14,16 @@ import { ThemedLoadingBar } from "ente-new/photos/components/ThemedLoadingBar";import { useLoadingBar } from "ente-new/photos/components/utils/use-loading-bar";import { PhotosAppContext } from "ente-new/photos/types/context";import type { AppProps } from "next/app";+import "photoswipe/dist/photoswipe.css";import { useCallback, useEffect, useMemo } from "react";+import "styles/photoswipe.css";export default function App({ Component, pageProps }: AppProps) {useSetupLogs();useSetupI18n();useEffect(() => {- void logStartupBanner();+ logStartupBanner();}, []);// Simplified - no complex dialogs needed for embed@@ -57,9 +57,13 @@ export default function App({ Component, pageProps }: AppProps) {() => ({showLoadingBar,hideLoadingBar,- showNotification: () => {}, // No notifications in embed+ showNotification: () => {+ // No notifications in embed+ },watchFolderView: false,- setWatchFolderView: () => {}, // No watch folder in embed+ setWatchFolderView: () => {+ // No watch folder in embed+ },}),[showLoadingBar, hideLoadingBar],);diff --git a/web/apps/embed/src/pages/index.tsx b/web/apps/embed/src/pages/index.tsxindex 751f55dd17..746cb29acc 100644--- a/web/apps/embed/src/pages/index.tsx+++ b/web/apps/embed/src/pages/index.tsx@@ -17,6 +17,11 @@ import { extractCollectionKeyFromShareURL } from "ente-gallery/services/share";import { sortFiles } from "ente-gallery/utils/file";import type { Collection } from "ente-media/collection";import { type EnteFile } from "ente-media/file";+import { usePhotosAppContext } from "ente-new/photos/types/context";+import { t } from "i18next";+import { useCallback, useEffect, useRef, useState } from "react";+import { EmbedFileListWithViewer } from "../components/EmbedFileListWithViewer";+import { EmbedPasswordForm } from "../components/EmbedPasswordForm";import {removePublicCollectionByKey,savedPublicCollectionAccessTokenJWT,@@ -30,11 +35,6 @@ import {removePublicCollectionFileData,verifyPublicAlbumPassword,} from "../services/public-collection";-import { usePhotosAppContext } from "ente-new/photos/types/context";-import { t } from "i18next";-import { useCallback, useEffect, useRef, useState } from "react";-import { EmbedFileListWithViewer } from "../components/EmbedFileListWithViewer";-import { EmbedPasswordForm } from "../components/EmbedPasswordForm";export default function EmbedGallery() {const { onGenericError } = useBaseContext();@@ -53,55 +53,6 @@ export default function EmbedGallery() {const credentials = useRef<PublicAlbumsCredentials | undefined>(undefined);const collectionKey = useRef<string | undefined>(undefined);- useEffect(() => {- const main = async () => {- let redirectingToWebsite = false;- try {- const currentURL = new URL(window.location.href);- const t = currentURL.searchParams.get("t");- const ck = await extractCollectionKeyFromShareURL(currentURL);- if (!t && !ck) {- window.location.href = "https://ente.io";- redirectingToWebsite = true;- }- if (!t || !ck) {- return;- }-- collectionKey.current = ck;- const collection = await savedPublicCollectionByKey(ck);- const accessToken = t;- let accessTokenJWT: string | undefined;-- if (collection) {- setPublicCollection(collection);- setIsPasswordProtected(- !!collection.publicURLs[0]?.passwordEnabled,- );- setPublicFiles(- sortFilesForCollection(- await savedPublicCollectionFiles(accessToken),- collection,- ),- );- accessTokenJWT =- await savedPublicCollectionAccessTokenJWT(accessToken);- }-- credentials.current = { accessToken, accessTokenJWT };- downloadManager.setPublicAlbumsCredentials(credentials.current);-- await publicAlbumsRemotePull();- } finally {- if (!redirectingToWebsite) {- setLoading(false);- }- }- };-- main();- }, []);-const publicAlbumsRemotePull = useCallback(async () => {const accessToken = credentials.current!.accessToken;showLoadingBar();@@ -124,7 +75,7 @@ export default function EmbedGallery() {}if (isPasswordProtected && !credentials.current?.accessTokenJWT) {- await removePublicCollectionFileData(accessToken);+ removePublicCollectionFileData(accessToken);} else {try {await pullPublicCollectionFiles(@@ -157,8 +108,8 @@ export default function EmbedGallery() {? t("link_request_limit_exceeded"): t("link_expired_message"),);- await removePublicCollectionFileData(accessToken);- await removePublicCollectionByKey(collectionKey.current!);+ removePublicCollectionFileData(accessToken);+ removePublicCollectionByKey(collectionKey.current!);setPublicCollection(undefined);setPublicFiles(undefined);} else {@@ -171,6 +122,55 @@ export default function EmbedGallery() {}}, [showLoadingBar, hideLoadingBar, onGenericError]);+ useEffect(() => {+ const main = async () => {+ let redirectingToWebsite = false;+ try {+ const currentURL = new URL(window.location.href);+ const t = currentURL.searchParams.get("t");+ const ck = await extractCollectionKeyFromShareURL(currentURL);+ if (!t && !ck) {+ window.location.href = "https://ente.io";+ redirectingToWebsite = true;+ }+ if (!t || !ck) {+ return;+ }++ collectionKey.current = ck;+ const collection = savedPublicCollectionByKey(ck);+ const accessToken = t;+ let accessTokenJWT: string | undefined;++ if (collection) {+ setPublicCollection(collection);+ setIsPasswordProtected(+ !!collection.publicURLs[0]?.passwordEnabled,+ );+ setPublicFiles(+ sortFilesForCollection(+ savedPublicCollectionFiles(accessToken),+ collection,+ ),+ );+ accessTokenJWT =+ savedPublicCollectionAccessTokenJWT(accessToken);+ }++ credentials.current = { accessToken, accessTokenJWT };+ downloadManager.setPublicAlbumsCredentials(credentials.current);++ await publicAlbumsRemotePull();+ } finally {+ if (!redirectingToWebsite) {+ setLoading(false);+ }+ }+ };++ void main();+ }, [publicAlbumsRemotePull]);+const handleSubmitPassword = async (password: string) => {try {const accessToken = credentials.current!.accessToken;@@ -181,10 +181,7 @@ export default function EmbedGallery() {);credentials.current!.accessTokenJWT = accessTokenJWT;downloadManager.setPublicAlbumsCredentials(credentials.current);- await savePublicCollectionAccessTokenJWT(- accessToken,- accessTokenJWT,- );+ savePublicCollectionAccessTokenJWT(accessToken, accessTokenJWT);} catch (e) {log.error("Failed to verify password", e);if (isHTTP401Error(e)) {diff --git a/web/apps/embed/src/services/in-memory-storage.ts b/web/apps/embed/src/services/in-memory-storage.tsindex 49556a5ef4..1479730d48 100644--- a/web/apps/embed/src/services/in-memory-storage.ts+++ b/web/apps/embed/src/services/in-memory-storage.ts@@ -13,47 +13,46 @@export class InMemoryStorage {private storage = new Map<string, unknown>();- async getItem<T>(key: string): Promise<T | null> {+ getItem(key: string): unknown {const value = this.storage.get(key);- return value !== undefined ? (value as T) : null;+ return value !== undefined ? value : null;}- async setItem<T>(key: string, value: T): Promise<T> {+ setItem<T>(key: string, value: T): T {this.storage.set(key, value);return value;}- async removeItem(key: string): Promise<void> {+ removeItem(key: string): void {this.storage.delete(key);}- async clear(): Promise<void> {+ clear(): void {this.storage.clear();}- async ready(): Promise<void> {+ ready(): void {// Always ready since it's in-memory- return Promise.resolve();}- async keys(): Promise<string[]> {+ keys(): string[] {return Array.from(this.storage.keys());}- async length(): Promise<number> {+ length(): number {return this.storage.size;}- async key(index: number): Promise<string | null> {- const keys = await this.keys();+ key(index: number): string | null {+ const keys = this.keys();return keys[index] || null;}// Config method to match localForage interface (no-op for in-memory)- config(_options: Record<string, unknown>): void {+ config(): void {// No configuration needed for in-memory storage}}// Create a singleton instance to be used as the storage backend-export const inMemoryStorage = new InMemoryStorage();\ No newline at end of file+export const inMemoryStorage = new InMemoryStorage();diff --git a/web/apps/embed/src/services/public-albums-storage.ts b/web/apps/embed/src/services/public-albums-storage.tsindex b3609b5faa..c2534d9cd1 100644--- a/web/apps/embed/src/services/public-albums-storage.ts+++ b/web/apps/embed/src/services/public-albums-storage.ts@@ -23,10 +23,8 @@ import { inMemoryStorage } from "./in-memory-storage";** Use {@link savePublicCollections} to update the storage.*/-const savedPublicCollections = async (): Promise<Collection[]> =>- LocalCollections.parse(- (await inMemoryStorage.getItem("public-collections")) ?? [],- );+const savedPublicCollections = (): Collection[] =>+ LocalCollections.parse(inMemoryStorage.getItem("public-collections") ?? []);/*** Replace the list of public collections stored in our local storage.@@ -45,12 +43,12 @@ const savePublicCollections = (collections: Collection[]) =>* @param key The collection key that can be used to identify the public album* we want from amongst all the locally saved public albums.*/-export const savedPublicCollectionByKey = async (+export const savedPublicCollectionByKey = (collectionKey: string,-): Promise<Collection | undefined> =>- savedPublicCollections().then((cs) =>- cs.find((c) => c.key == collectionKey),- );+): Collection | undefined => {+ const collections = savedPublicCollections();+ return collections.find((c) => c.key == collectionKey);+};/*** Save a public collection to our local storage.@@ -58,9 +56,9 @@ export const savedPublicCollectionByKey = async (* The collection can later be retrieved using {@link savedPublicCollection}.* The collection can be removed using {@link removePublicCollection}.*/-export const savePublicCollection = async (collection: Collection) => {- const collections = await savedPublicCollections();- await savePublicCollections([+export const savePublicCollection = (collection: Collection) => {+ const collections = savedPublicCollections();+ savePublicCollections([collection,...collections.filter((c) => c.id != collection.id),]);@@ -73,9 +71,9 @@ export const savePublicCollection = async (collection: Collection) => {* @param key The collection key that can be used to identify the public album* we want to remove.*/-export const removePublicCollectionByKey = async (collectionKey: string) => {- const collections = await savedPublicCollections();- await savePublicCollections([+export const removePublicCollectionByKey = (collectionKey: string) => {+ const collections = savedPublicCollections();+ savePublicCollections([...collections.filter((c) => c.key != collectionKey),]);};@@ -100,8 +98,8 @@ const LocalString = z.string().nullish().transform(nullToUndefined);* 3. It gets updated as part of {@link publicAlbumsRemotePull}, which writes* out a new value using {@link saveLastPublicCollectionReferralCode}.*/-export const savedLastPublicCollectionReferralCode = async () =>- LocalString.parse(await inMemoryStorage.getItem("public-referral-code"));+export const savedLastPublicCollectionReferralCode = () =>+ LocalString.parse(inMemoryStorage.getItem("public-referral-code"));/*** Update the referral code present in our local storage.@@ -109,10 +107,8 @@ export const savedLastPublicCollectionReferralCode = async () =>* This is the setter corresponding to* {@link savedLastPublicCollectionReferralCode}.*/-export const saveLastPublicCollectionReferralCode = async (- referralCode: string,-) => {- await inMemoryStorage.setItem("public-referral-code", referralCode);+export const saveLastPublicCollectionReferralCode = (referralCode: string) => {+ inMemoryStorage.setItem("public-referral-code", referralCode);};const LocalSavedPublicCollectionFilesEntry = z.object({@@ -138,25 +134,23 @@ type LocalSavedPublicCollectionFilesEntry = z.infer<* @param accessToken The access token that identifies the public album whose* files we want.*/-export const savedPublicCollectionFiles = async (- accessToken: string,-): Promise<EnteFile[]> => {- const entry = (await pcfEntries()).find(- (e) => e.collectionUID == accessToken,- );+export const savedPublicCollectionFiles = (accessToken: string): EnteFile[] => {+ const entry = pcfEntries().find((e) => e.collectionUID == accessToken);return transformFilesIfNeeded(entry ? entry.files : []);};/*** A convenience routine to read the storage entries for "public-collection-files".*/-const pcfEntries = async () => {+const pcfEntries = () => {// A local alias to avoid the code from looking scary.type ES = LocalSavedPublicCollectionFilesEntry[];// See: [Note: Avoiding Zod parsing for large DB arrays] for why we use an// (implied) cast here instead of parsing using the Zod schema.- const entries = await inMemoryStorage.getItem<ES>("public-collection-files");+ const entries = inMemoryStorage.getItem(+ "public-collection-files",+ ) as ES | null;return entries ?? [];};@@ -170,13 +164,13 @@ const pcfEntries = async () => {** @param files The files to save.*/-export const savePublicCollectionFiles = async (+export const savePublicCollectionFiles = (accessToken: string,files: EnteFile[],-): Promise<void> => {- await inMemoryStorage.setItem("public-collection-files", [+): void => {+ inMemoryStorage.setItem("public-collection-files", [{ collectionUID: accessToken, files },- ...(await pcfEntries()).filter((e) => e.collectionUID != accessToken),+ ...pcfEntries().filter((e) => e.collectionUID != accessToken),]);};@@ -184,11 +178,9 @@ export const savePublicCollectionFiles = async (* Remove the list of files, in any, in our local storage for the given* collection (identified by its {@link accessToken}).*/-export const removePublicCollectionFiles = async (- accessToken: string,-): Promise<void> => {- await inMemoryStorage.setItem("public-collection-files", [- ...(await pcfEntries()).filter((e) => e.collectionUID != accessToken),+export const removePublicCollectionFiles = (accessToken: string): void => {+ inMemoryStorage.setItem("public-collection-files", [+ ...pcfEntries().filter((e) => e.collectionUID != accessToken),]);};@@ -204,30 +196,26 @@ export const removePublicCollectionFiles = async (* @param accessToken The access token that identifies the public album whose* last sync time we want.*/-export const savedPublicCollectionLastSyncTime = async (accessToken: string) =>- LocalTimestamp.parse(- await inMemoryStorage.getItem(`public-${accessToken}-time`),- );+export const savedPublicCollectionLastSyncTime = (accessToken: string) =>+ LocalTimestamp.parse(inMemoryStorage.getItem(`public-${accessToken}-time`));/*** Update the locally persisted timestamp that will be returned by subsequent* calls to {@link savedPublicCollectionLastSyncTime}.*/-export const savePublicCollectionLastSyncTime = async (+export const savePublicCollectionLastSyncTime = (accessToken: string,time: number,) => {- await inMemoryStorage.setItem(`public-${accessToken}-time`, time);+ inMemoryStorage.setItem(`public-${accessToken}-time`, time);};/*** Remove the locally persisted timestamp, if any, previously saved for a* collection using {@link savedPublicCollectionLastSyncTime}.*/-export const removePublicCollectionLastSyncTime = async (- accessToken: string,-) => {- await inMemoryStorage.removeItem(`public-${accessToken}-time`);+export const removePublicCollectionLastSyncTime = (accessToken: string) => {+ inMemoryStorage.removeItem(`public-${accessToken}-time`);};/**@@ -237,12 +225,8 @@ export const removePublicCollectionLastSyncTime = async (* Use {@link savePublicCollectionAccessTokenJWT} to save the value, and* {@link removePublicCollectionAccessTokenJWT} to remove it.*/-export const savedPublicCollectionAccessTokenJWT = async (- accessToken: string,-) =>- LocalString.parse(- await inMemoryStorage.getItem(`public-${accessToken}-passkey`),- );+export const savedPublicCollectionAccessTokenJWT = (accessToken: string) =>+ LocalString.parse(inMemoryStorage.getItem(`public-${accessToken}-passkey`));/*** Update the access token JWT in our local storage for the given public@@ -251,21 +235,19 @@ export const savedPublicCollectionAccessTokenJWT = async (* This is the setter corresponding to* {@link savedPublicCollectionAccessTokenJWT}.*/-export const savePublicCollectionAccessTokenJWT = async (+export const savePublicCollectionAccessTokenJWT = (accessToken: string,passwordJWT: string,) => {- await inMemoryStorage.setItem(`public-${accessToken}-passkey`, passwordJWT);+ inMemoryStorage.setItem(`public-${accessToken}-passkey`, passwordJWT);};/*** Remove the access token JWT in our local storage for the given public* collection (as identified by its {@link accessToken}).*/-export const removePublicCollectionAccessTokenJWT = async (- accessToken: string,-) => {- await inMemoryStorage.removeItem(`public-${accessToken}-passkey`);+export const removePublicCollectionAccessTokenJWT = (accessToken: string) => {+ inMemoryStorage.removeItem(`public-${accessToken}-passkey`);};/**@@ -287,9 +269,9 @@ export const removePublicCollectionAccessTokenJWT = async (* @param accessToken The access token that identifies the public album whose* saved uploader name we want.*/-export const savedPublicCollectionUploaderName = async (accessToken: string) =>+export const savedPublicCollectionUploaderName = (accessToken: string) =>LocalString.parse(- await inMemoryStorage.getItem(`public-${accessToken}-uploaderName`),+ inMemoryStorage.getItem(`public-${accessToken}-uploaderName`),);/**@@ -299,12 +281,9 @@ export const savedPublicCollectionUploaderName = async (accessToken: string) =>* This is the setter corresponding to* {@link savedPublicCollectionUploaderName}.*/-export const savePublicCollectionUploaderName = async (+export const savePublicCollectionUploaderName = (accessToken: string,uploaderName: string,) => {- await inMemoryStorage.setItem(- `public-${accessToken}-uploaderName`,- uploaderName,- );-};\ No newline at end of file+ inMemoryStorage.setItem(`public-${accessToken}-uploaderName`, uploaderName);+};diff --git a/web/apps/embed/src/services/public-collection.ts b/web/apps/embed/src/services/public-collection.tsindex cb64db1791..6c0cf23c5a 100644--- a/web/apps/embed/src/services/public-collection.ts+++ b/web/apps/embed/src/services/public-collection.ts@@ -112,18 +112,21 @@ export const pullCollection = async (});ensureOk(res);- const data = await res.json();+ const data = (await res.json()) as {+ collection: unknown;+ referralCode?: string;+ };const remoteCollection = RemoteCollection.parse(data.collection);- const referralCode = data.referralCode || "";+ const referralCode = data.referralCode ?? "";const collection = await decryptRemoteCollection(remoteCollection,collectionKey,);- await savePublicCollection(collection);+ savePublicCollection(collection);- return { collection, referralCode };+ return { collection, referralCode } as const;};/**@@ -146,17 +149,13 @@ export const pullPublicCollectionFiles = async (collection: Collection,onUpdate: (files: EnteFile[]) => void,) => {- let time = await savedPublicCollectionLastSyncTime(- credentials.accessToken,- );+ let time = savedPublicCollectionLastSyncTime(credentials.accessToken);let hasMore = true;while (hasMore) {const res = await fetch(await apiURL("/public-collection/diff", { sinceTime: time ?? 0 }),- {- headers: authenticatedPublicAlbumsRequestHeaders(credentials),- },+ { headers: authenticatedPublicAlbumsRequestHeaders(credentials) },);ensureOk(res);@@ -168,7 +167,7 @@ export const pullPublicCollectionFiles = async (diff.map((f) => decryptRemoteFile(f, collection.key)),);- let existingFiles = await savedPublicCollectionFiles(+ const existingFiles = savedPublicCollectionFiles(credentials.accessToken,);@@ -176,14 +175,11 @@ export const pullPublicCollectionFiles = async (// order of their creation time.const newFiles = [...existingFiles, ...files];- await savePublicCollectionFiles(credentials.accessToken, newFiles);+ savePublicCollectionFiles(credentials.accessToken, newFiles);if (files.length > 0) {time = Math.max(...files.map((f) => f.updationTime));- await savePublicCollectionLastSyncTime(- credentials.accessToken,- time,- );+ savePublicCollectionLastSyncTime(credentials.accessToken, time);}hasMore = hasMoreRemote;@@ -195,8 +191,8 @@ export const pullPublicCollectionFiles = async (* Remove all data associated with the public collection (identified by the* given {@link accessToken}) from our local storage.*/-export const removePublicCollectionFileData = async (accessToken: string) => {- await removePublicCollectionFiles(accessToken);- await removePublicCollectionLastSyncTime(accessToken);- await removePublicCollectionAccessTokenJWT(accessToken);-};\ No newline at end of file+export const removePublicCollectionFileData = (accessToken: string) => {+ removePublicCollectionFiles(accessToken);+ removePublicCollectionLastSyncTime(accessToken);+ removePublicCollectionAccessTokenJWT(accessToken);+};