π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fixes
AmanRajSinghMouryaa00e257d1526
diff --git a/web/apps/share/src/components/file-share/CollectionShareView.tsx b/web/apps/share/src/components/file-share/CollectionShareView.tsxindex dccd6fa82f..699c6f3e48 100644--- a/web/apps/share/src/components/file-share/CollectionShareView.tsx+++ b/web/apps/share/src/components/file-share/CollectionShareView.tsx@@ -58,21 +58,11 @@ const passwordCardSx = {px: { xs: 3, sm: 4 },py: { xs: 3.5, sm: 4 },borderRadius: "20px",- backgroundColor: "rgba(19, 21, 24, 0.96)",- border: "1px solid rgba(255, 255, 255, 0.08)",- boxShadow:- "0 24px 60px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.03)",- color: "#FFFFFF",- "& .MuiTypography-root": { color: "inherit" },- "& .MuiFormLabel-root": { color: "rgba(255, 255, 255, 0.64)" },+ backgroundColor: "background.paper",+ border: "1px solid",+ borderColor: "divider",+ color: "text.base","& .MuiFormLabel-root.Mui-focused": { color: "accent.light" },- "& .MuiInputBase-root": {- backgroundColor: "rgba(255, 255, 255, 0.08)",- color: "#FFFFFF",- },- "& .MuiInputBase-input": { color: "#FFFFFF" },- "& .MuiInputAdornment-root": { color: "rgba(255, 255, 255, 0.52)" },- "& .MuiFormHelperText-root": { color: "rgba(255, 255, 255, 0.6)" },"& .MuiButton-root": {backgroundColor: "accent.main",color: "accent.contrastText",@@ -169,13 +159,13 @@ export const CollectionShareView: React.FC = () => {<Paper elevation={0} sx={passwordCardSx}><Typographyvariant="h4"- sx={{ fontWeight: 700, color: "#FFFFFF", mb: 1.5 }}+ sx={{ fontWeight: 700, color: "text.base", mb: 1.5 }}>{passwordTitle}</Typography><Typographyvariant="body"- sx={{ color: "rgba(255, 255, 255, 0.72)", mb: 2 }}+ sx={{ color: "text.muted", mb: 2 }}>{passwordDescription}</Typography>@@ -217,9 +207,12 @@ export const CollectionShareView: React.FC = () => {sx={{width: "100%",flex: 1,+ display: "flex",+ flexDirection: "column",+ overflow: "hidden",+ minHeight: 0,px: { xs: 2, sm: 3 },- pb: "calc(env(safe-area-inset-bottom) + 120px)",- pt: { xs: 3, md: 5 },+ pt: { xs: 2, md: 2 },}}><Stack@@ -230,8 +223,10 @@ export const CollectionShareView: React.FC = () => {gap: 2,maxWidth: contentMaxWidth,mx: "auto",+ width: "100%",mt: 1,mb: 2.25,+ flexShrink: 0,}}><Box sx={{ minWidth: 0 }}>@@ -257,8 +252,14 @@ export const CollectionShareView: React.FC = () => {sx={{maxWidth: contentMaxWidth,mx: "auto",+ width: "100%",gap: 1.1,mt: 1.25,+ flex: 1,+ minHeight: 0,+ overflowY: "auto",+ pr: 0.5,+ pb: "calc(env(safe-area-inset-bottom) + 24px)",}}>{collectionInfo.items.map((item) => {@@ -270,11 +271,12 @@ export const CollectionShareView: React.FC = () => {return (<ButtonBasekey={`${item.collectionID}-${item.id}`}- component="div"onClick={() => handleItemClick(item)}+ aria-label={`Open ${item.fileName}`}sx={(theme) => ({display: "flex",width: "100%",+ flexShrink: 0,textAlign: "left",borderRadius: "18px",overflow: "hidden",@@ -292,9 +294,13 @@ export const CollectionShareView: React.FC = () => {.faintHover,},...theme.applyStyles("light", {- backgroundColor: "#FFFFFF",+ backgroundColor:+ theme.vars.palette+ .background.paper,"&:hover": {- backgroundColor: "#FFFFFF",+ backgroundColor:+ theme.vars.palette.fill+ .faintHover,},}),})}diff --git a/web/apps/share/src/components/file-share/FileShareView.tsx b/web/apps/share/src/components/file-share/FileShareView.tsxindex 3f0dd527c8..13a52b7cb1 100644--- a/web/apps/share/src/components/file-share/FileShareView.tsx+++ b/web/apps/share/src/components/file-share/FileShareView.tsx@@ -1,7 +1,5 @@import { Box, Button, CircularProgress, Typography } from "@mui/material";-import { useColorScheme } from "@mui/material/styles";import { Notification } from "ente-new/photos/components/Notification";-import Head from "next/head";import React from "react";import { useFileShare } from "../../hooks/useFileShare";import { formatFileSize } from "../../services/file-share";@@ -9,9 +7,6 @@ import { getLockerFileIcon } from "../../utils/file-type";import { LockerTypeDisplay } from "./LockerTypeDisplay";export const FileShareView: React.FC = () => {- const { systemMode } = useColorScheme();- const isDarkMode = systemMode === "dark";-const {loading,downloading,@@ -29,33 +24,33 @@ export const FileShareView: React.FC = () => {: null;return (- <>- <Head>- <meta name="robots" content="noindex, nofollow" />- </Head>- <Box- sx={{- minHeight: "100dvh",- bgcolor: "accent.main",- display: "flex",- flexDirection: "column",- alignItems: "center",- padding: { xs: 1, md: 3 },- boxSizing: "border-box",- }}- >+ <Box+ sx={{+ minHeight: "100dvh",+ width: "100%",+ maxWidth: "100%",+ bgcolor: "accent.main",+ display: "flex",+ flexDirection: "column",+ alignItems: "center",+ p: { xs: 1.25, md: 2 },+ boxSizing: "border-box",+ overflowX: "hidden",+ }}+ ><Boxsx={{- minHeight: {- xs: "calc(100dvh - 16px)",- md: "calc(100dvh - 48px)",+ height: {+ xs: "calc(100dvh - 20px)",+ md: "calc(100dvh - 32px)",},width: "100%",bgcolor: "background.default",- borderRadius: { xs: "20px", md: "40px" },+ borderRadius: { xs: "24px", md: "34px" },display: "flex",flexDirection: "column",alignItems: "center",+ overflow: "hidden","& ::selection": {backgroundColor: "accent.main",color: "fixed.white",@@ -69,10 +64,13 @@ export const FileShareView: React.FC = () => {{/* Ente Locker Logo */}<Boxsx={{- mt: { xs: 5, md: 6 },+ width: "100%",+ display: "flex",+ alignItems: "center",+ justifyContent: { xs: "center", md: "flex-end" },+ minHeight: { xs: 88, md: 104 },+ px: { xs: 3, md: 4.5 },mb: fileInfo?.lockerType ? { xs: 16, md: 0 } : 0,- alignSelf: { xs: "center", md: "flex-end" },- mr: { xs: 0, md: 6 },}}><a@@ -81,16 +79,18 @@ export const FileShareView: React.FC = () => {rel="noopener noreferrer"style={{ display: "block", lineHeight: 0 }}>- <Box- component="img"- src={- isDarkMode- ? "/images/ente-locker-white.svg"- : "/images/ente-locker.svg"- }- alt="Ente Locker"- sx={{ height: "56px", cursor: "pointer" }}- />+ <picture>+ <source+ srcSet="/images/ente-locker-white.svg"+ media="(prefers-color-scheme: dark)"+ />+ <Box+ component="img"+ src="/images/ente-locker.svg"+ alt="Ente Locker"+ sx={{ height: "56px", cursor: "pointer" }}+ />+ </picture></a></Box>@@ -277,7 +277,6 @@ export const FileShareView: React.FC = () => {attributes={notificationAttributes}/></Box>- </Box>- </>+ </Box>);};diff --git a/web/apps/share/src/components/file-share/PublicShareScaffold.tsx b/web/apps/share/src/components/file-share/PublicShareScaffold.tsxindex 72d4fb27fa..32c10b3faf 100644--- a/web/apps/share/src/components/file-share/PublicShareScaffold.tsx+++ b/web/apps/share/src/components/file-share/PublicShareScaffold.tsx@@ -1,5 +1,4 @@import { Box } from "@mui/material";-import Head from "next/head";import React, { type ReactNode } from "react";interface PublicShareScaffoldProps {@@ -10,39 +9,51 @@ export const PublicShareScaffold: React.FC<PublicShareScaffoldProps> = ({children,}) => {return (- <>- <Head>- <meta name="robots" content="noindex, nofollow" />- </Head>+ <Box+ sx={{+ minHeight: "100dvh",+ width: "100%",+ maxWidth: "100%",+ bgcolor: "accent.main",+ display: "flex",+ flexDirection: "column",+ alignItems: "center",+ p: { xs: 1.25, md: 2 },+ boxSizing: "border-box",+ overflowX: "hidden",+ "& ::selection": {+ backgroundColor: "accent.main",+ color: "fixed.white",+ },+ "& ::-moz-selection": {+ backgroundColor: "accent.main",+ color: "fixed.white",+ },+ }}+ ><Boxsx={{- minHeight: "100dvh",- bgcolor: "#08090A",+ height: {+ xs: "calc(100dvh - 20px)",+ md: "calc(100dvh - 32px)",+ },+ width: "100%",+ bgcolor: "background.default",+ borderRadius: { xs: "24px", md: "34px" },display: "flex",flexDirection: "column",alignItems: "center",- boxSizing: "border-box",- "& ::selection": {- backgroundColor: "#1071FF",- color: "#FFFFFF",- },- "& ::-moz-selection": {- backgroundColor: "#1071FF",- color: "#FFFFFF",- },+ overflow: "hidden",}}><Boxsx={{width: "100%",- background:- "linear-gradient(135deg, #1071FF 0%, #0056CC 100%)",display: "flex",alignItems: "center",- justifyContent: "center",- px: { xs: 2, sm: 3 },- pt: 2,- pb: 2.5,+ justifyContent: { xs: "center", md: "flex-end" },+ minHeight: { xs: 88, md: 104 },+ px: { xs: 3, md: 4.5 },}}><a@@ -51,12 +62,18 @@ export const PublicShareScaffold: React.FC<PublicShareScaffoldProps> = ({rel="noopener noreferrer"style={{ display: "block", lineHeight: 0 }}>- <Box- component="img"- src="/images/ente-locker-white.svg"- alt="Ente Locker"- sx={{ height: { xs: "30px", md: "34px" } }}- />+ <picture>+ <source+ srcSet="/images/ente-locker-white.svg"+ media="(prefers-color-scheme: dark)"+ />+ <Box+ component="img"+ src="/images/ente-locker.svg"+ alt="Ente Locker"+ sx={{ height: "56px", cursor: "pointer" }}+ />+ </picture></a></Box><Box@@ -65,12 +82,12 @@ export const PublicShareScaffold: React.FC<PublicShareScaffoldProps> = ({flex: 1,display: "flex",flexDirection: "column",- bgcolor: "#08090A",+ minHeight: 0,}}>{children}</Box></Box>- </>+ </Box>);};diff --git a/web/apps/share/src/components/file-share/SharedItemDetails.tsx b/web/apps/share/src/components/file-share/SharedItemDetails.tsxindex 59e4dbcab5..f49bb89936 100644--- a/web/apps/share/src/components/file-share/SharedItemDetails.tsx+++ b/web/apps/share/src/components/file-share/SharedItemDetails.tsx@@ -58,6 +58,7 @@ export const SharedItemDetails: React.FC<SharedItemDetailsProps> = ({<Box sx={{ width: "100%", mb: 4 }}><IconButtononClick={onBack}+ aria-label="Back"sx={{color: "text.base",ml: -1,diff --git a/web/apps/share/src/hooks/useCollectionShare.ts b/web/apps/share/src/hooks/useCollectionShare.tsindex 83f19188f2..4a0ace2795 100644--- a/web/apps/share/src/hooks/useCollectionShare.ts+++ b/web/apps/share/src/hooks/useCollectionShare.ts@@ -33,7 +33,6 @@ interface UseCollectionShareResult {downloadProgress: number | null;errorTitle: string | null;error: string | null;- errorIsExpired: boolean;collectionInfo: PublicCollectionShareInfo | null;selectedItem: SharedCollectionItemInfo | null;notificationAttributes: NotificationAttributes | undefined;@@ -50,7 +49,6 @@ interface UseCollectionShareResult {interface CollectionShareLoadError {title: string;message: string;- isExpired: boolean;}const readLocalStorageItem = (key: string): string | null => {@@ -106,7 +104,6 @@ const collectionShareLoadError = async (title: "Link expired",message:"This link has either expired or has been disabled.",- isExpired: true,};}} catch {@@ -116,7 +113,14 @@ const collectionShareLoadError = async (return {title: "Link expired",message: "This link has either expired or has been disabled.",- isExpired: true,+ };+ }++ if (isHTTPErrorWithStatus(err, 429)) {+ return {+ title: "Too many viewers",+ message:+ "This link has reached its device limit. Ask the owner to increase the limit or try again later.",};}@@ -129,7 +133,6 @@ const collectionShareLoadError = async (title: "Unable to open this collection",message:"This collection link is no longer available. It may have been removed or expired.",- isExpired: false,};}@@ -137,13 +140,44 @@ const collectionShareLoadError = async (title: "Unable to open this collection",message:"Unable to load this collection right now. Please try again later.",- isExpired: false,};};+const ITEM_BACK_STATE_KEY = "__enteCollectionShareItemBack";+const RESUME_REVALIDATE_AFTER_MS = 30_000;++const addItemBackStateMarker = (state: unknown, marker: string) =>+ state && typeof state == "object"+ ? {+ ...(state as Record<string, unknown>),+ [ITEM_BACK_STATE_KEY]: marker,+ }+ : { [ITEM_BACK_STATE_KEY]: marker };++const hasItemBackStateMarker = (state: unknown, marker: string) =>+ !!state &&+ typeof state == "object" &&+ (state as Record<string, unknown>)[ITEM_BACK_STATE_KEY] == marker;++const getItemBackStateMarker = (state: unknown) =>+ state && typeof state == "object"+ ? (state as Record<string, unknown>)[ITEM_BACK_STATE_KEY]+ : undefined;++const shouldPreserveLoadedStateOnSilentRefreshError = (err: unknown) => {+ if (!(err instanceof HTTPError)) {+ return true;+ }++ return err.res.status >= 500;+};+export const useCollectionShare = (): UseCollectionShareResult => {const router = useRouter();+ const initialLoadStartedRef = useRef(false);const isRevalidatingRef = useRef(false);+ const lastResumeRevalidateAtRef = useRef(0);+ const browserBackStateRef = useRef<string | undefined>(undefined);const [loading, setLoading] = useState(true);const [downloadingItemID, setDownloadingItemID] = useState<number | null>(null,@@ -153,7 +187,6 @@ export const useCollectionShare = (): UseCollectionShareResult => {);const [errorTitle, setErrorTitle] = useState<string | null>(null);const [error, setError] = useState<string | null>(null);- const [errorIsExpired, setErrorIsExpired] = useState(false);const [collectionInfo, setCollectionInfo] =useState<PublicCollectionShareInfo | null>(null);const [selectedItem, setSelectedItem] =@@ -183,13 +216,15 @@ export const useCollectionShare = (): UseCollectionShareResult => {accessToken: string;collectionKey: string;accessTokenJWT: string;+ silent: boolean;}>,) => {try {- setLoading(true);+ if (!opts?.silent) {+ setLoading(true);+ }setError(null);setErrorTitle(null);- setErrorIsExpired(false);setPasswordProtectedPublicURL(null);const url = new URL(window.location.href);@@ -200,9 +235,15 @@ export const useCollectionShare = (): UseCollectionShareResult => {return;}- const resolvedCollectionKey =- opts?.collectionKey ??- (await extractCollectionKeyFromShareURL(url));+ let resolvedCollectionKey: string | undefined;+ try {+ resolvedCollectionKey =+ opts?.collectionKey ??+ (await extractCollectionKeyFromShareURL(url));+ } catch {+ setInvalidLinkState();+ return;+ }if (!resolvedCollectionKey) {setInvalidLinkState();return;@@ -243,7 +284,7 @@ export const useCollectionShare = (): UseCollectionShareResult => {accessToken: token,accessTokenJWT: activeAccessTokenJWT,},- resolvedCollectionKey,+ metadata,);} catch (err) {if (activeAccessTokenJWT && isHTTP401Error(err)) {@@ -262,20 +303,29 @@ export const useCollectionShare = (): UseCollectionShareResult => {setPasswordProtectedPublicURL(null);setCollectionInfo(info);} catch (err) {+ if (+ opts?.silent &&+ shouldPreserveLoadedStateOnSilentRefreshError(err)+ ) {+ return;+ }+clearLoadedState();const loadError = await collectionShareLoadError(err);setErrorTitle(loadError.title);setError(loadError.message);- setErrorIsExpired(loadError.isExpired);} finally {- setLoading(false);+ if (!opts?.silent) {+ setLoading(false);+ }}},[clearLoadedState, setInvalidLinkState],);useEffect(() => {- if (router.isReady) {+ if (router.isReady && !initialLoadStartedRef.current) {+ initialLoadStartedRef.current = true;void loadCollection();}}, [router.isReady, loadCollection]);@@ -293,8 +343,17 @@ export const useCollectionShare = (): UseCollectionShareResult => {return;}+ const now = Date.now();+ if (+ now - lastResumeRevalidateAtRef.current <+ RESUME_REVALIDATE_AFTER_MS+ ) {+ return;+ }++ lastResumeRevalidateAtRef.current = now;isRevalidatingRef.current = true;- void loadCollection().finally(() => {+ void loadCollection({ silent: true }).finally(() => {isRevalidatingRef.current = false;});};@@ -319,6 +378,56 @@ export const useCollectionShare = (): UseCollectionShareResult => {};}, [router.isReady, loadCollection]);+ useEffect(() => {+ if (!selectedItem) {+ return;+ }++ const currentState: unknown = window.history.state;+ const existingMarker = getItemBackStateMarker(currentState);+ const stateMarker =+ typeof existingMarker == "string" && existingMarker+ ? existingMarker+ : `${selectedItem.id}-${Date.now()}-${Math.random()+ .toString(36)+ .slice(2)}`;+ browserBackStateRef.current = stateMarker;++ if (!existingMarker) {+ const itemState = addItemBackStateMarker(currentState, stateMarker);+ try {+ window.history.pushState(itemState, "", window.location.href);+ } catch {+ browserBackStateRef.current = undefined;+ return;+ }+ }++ const onPopState = () => {+ if (browserBackStateRef.current != stateMarker) {+ return;+ }++ browserBackStateRef.current = undefined;+ setSelectedItem(null);+ };++ window.addEventListener("popstate", onPopState);+ return () => {+ window.removeEventListener("popstate", onPopState);+ if (browserBackStateRef.current != stateMarker) {+ return;+ }++ browserBackStateRef.current = undefined;++ const latestHistoryState: unknown = window.history.state;+ if (hasItemBackStateMarker(latestHistoryState, stateMarker)) {+ window.history.back();+ }+ };+ }, [selectedItem]);+const handleCloseItem = () => {setSelectedItem(null);};@@ -436,7 +545,6 @@ export const useCollectionShare = (): UseCollectionShareResult => {downloadProgress,errorTitle,error,- errorIsExpired,collectionInfo,selectedItem,notificationAttributes,diff --git a/web/apps/share/src/pages/_app.tsx b/web/apps/share/src/pages/_app.tsxindex fe853cc9d6..331780aa7b 100644--- a/web/apps/share/src/pages/_app.tsx+++ b/web/apps/share/src/pages/_app.tsx@@ -3,13 +3,17 @@ import { CssBaseline } from "@mui/material";import { ThemeProvider } from "@mui/material/styles";import { staticAppTitle } from "ente-base/app";import { CustomHead } from "ente-base/components/Head";-import { useSetupLogs } from "ente-base/components/utils/hooks-app";+import {+ useSetupI18n,+ useSetupLogs,+} from "ente-base/components/utils/hooks-app";import { shareTheme } from "ente-base/components/utils/theme";import type { AppProps } from "next/app";import React from "react";const App: React.FC<AppProps> = ({ Component, pageProps }) => {useSetupLogs({ disableDiskLogs: true });+ useSetupI18n();return (<ThemeProviderdiff --git a/web/apps/share/src/services/collection-share.ts b/web/apps/share/src/services/collection-share.tsindex fbf0324963..51c1175629 100644--- a/web/apps/share/src/services/collection-share.ts+++ b/web/apps/share/src/services/collection-share.ts@@ -234,6 +234,7 @@ const fetchPublicCollectionDiff = async (let hasMore = true;while (hasMore) {+ const prevSinceTime = sinceTime;const res = await fetch(await apiURL("/public-collection/diff", { sinceTime }),{@@ -253,6 +254,9 @@ const fetchPublicCollectionDiff = async (}}hasMore = parsed.hasMore;+ // Defensive guard: if the server claims more pages but sinceTime did+ // not advance, stop to avoid spinning on a broken server contract.+ if (hasMore && sinceTime === prevSinceTime) break;}return [...filesByID.values()];@@ -313,12 +317,8 @@ export const fetchPublicCollectionShareMetadata = async (export const fetchPublicCollectionShare = async (credentials: PublicAlbumsCredentials,- collectionKey: string,+ metadata: PublicCollectionShareMetadata,): Promise<PublicCollectionShareInfo> => {- const metadata = await fetchPublicCollectionShareMetadata(- credentials.accessToken,- collectionKey,- );const remoteFiles = await fetchPublicCollectionDiff(credentials);const items = await Promise.all(remoteFiles.map((file) =>