π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Prune remaining web comments
Manav Rathi009807b859c0
diff --git a/web/apps/albums/src/public-album/components/TripLayout/index.tsx b/web/apps/albums/src/public-album/components/TripLayout/index.tsxindex e6c7d3c130..2dd3c774e9 100644--- a/web/apps/albums/src/public-album/components/TripLayout/index.tsx+++ b/web/apps/albums/src/public-album/components/TripLayout/index.tsx@@ -15,7 +15,6 @@ import type { Collection } from "ente-media/collection";import type { EnteFile } from "ente-media/file";import { useCallback, useEffect, useRef, useState } from "react";-// Import extracted componentsimport { MobileCover } from "./MobileCover";import { MobileNavBar } from "./MobileNavBar";import { MobileTimelineLocation } from "./MobileTimelineLocation";@@ -26,14 +25,12 @@ import { TimelineProgressLine } from "./TimelineProgressLine";import { TopNavButtons } from "./TopNavButtons";import { TripCover } from "./TripCover";-// Import hooksimport { useDataProcessing } from "./hooks/useDataProcessing";import { useFileViewer } from "./hooks/useFileViewer";import { useLocationFetching } from "./hooks/useLocationFetching";import { useScrollHandling } from "./hooks/useScrollHandling";import { useThumbnailGeneration } from "./hooks/useThumbnailGeneration";-// Import types and utilsimport type { JourneyPoint } from "./types";import type { PositionInfo } from "./utils/scrollUtils";@@ -43,20 +40,11 @@ export interface TripLayoutProps {albumTitle?: string;enableDownload?: boolean;onSetOpenFileViewer?: (open: boolean) => void;- onAddPhotos?: () => void; // Callback for add photos button- // Join album props+ onAddPhotos?: () => void;accessToken?: string;collectionKey?: string;credentials?: React.RefObject<PublicAlbumsCredentials | undefined>;- /**- * `true` if comments/reactions are enabled on the public link.- * When `false`, the feed button will be hidden.- */enableComment?: boolean;- /**- * `true` if the "Join album" option is enabled for this public link.- * When `false`, the "Join album and like/comment" buttons will be hidden.- */enableJoin?: boolean;}@@ -73,14 +61,11 @@ export const TripLayout: React.FC<TripLayoutProps> = ({enableComment = true,enableJoin = false,}) => {- // Extract collection info if availableconst collectionTitle = collection?.name || albumTitle || "Trip";- // Use media query for mobile/tablet detection (up to 960px)const theme = useTheme();- const isMobileOrTablet = useMediaQuery(theme.breakpoints.down("md")); // 960px breakpoint for mobile and tablet+ const isMobileOrTablet = useMediaQuery(theme.breakpoints.down("md"));- // Save groups hook for download progress trackingconst { onAddSaveGroup } = useSaveGroupsActions();const { show: showPublicFeed, props: publicFeedVisibilityProps } =useModalVisibility();@@ -88,7 +73,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({useState(false);const publicFeedSidebarOpenRef = useRef(publicFeedVisibilityProps.open);- // Navigation state for feed item clicksconst [initialSidebar, setInitialSidebar] = useState<FileViewerInitialSidebar | undefined>(undefined);@@ -99,7 +83,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({Map<string, string> | undefined>(undefined);- // File viewer hookconst {openFileViewer,currentFileIndex,@@ -108,7 +91,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({handleCloseFileViewer,} = useFileViewer({ files, onSetOpenFileViewer });- // Join album hook for file viewer's public like modalconst { handleJoinAlbum } = useJoinAlbum({publicCollection: collection,accessToken,@@ -129,32 +111,24 @@ export const TripLayout: React.FC<TripLayoutProps> = ({}}, []);- /**- * Handle clicks on feed items to navigate to the file and open sidebar.- */const handleFeedItemClick = (info: PublicFeedItemClickInfo) => {- // Find the file in the journey data to get its clusterconst journeyPoint = journeyData.find((point) => point.fileId === info.fileID,);if (!journeyPoint) return;- // Find the cluster that contains this fileconst cluster = photoClusters.find((c) =>c.some((p) => p.fileId === info.fileID),);if (!cluster) return;- // Close the feed sidebarpublicFeedVisibilityProps.onClose();- // Determine which sidebar to openconst sidebar: FileViewerInitialSidebar =info.type === "liked_photo" || info.type === "liked_video"? "likes": "comments";- // Set navigation state and open file viewersetInitialSidebar(sidebar);setHighlightCommentID(info.commentID);setInitialAnonUserNames(@@ -163,9 +137,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({handleOpenFileViewer(cluster, info.fileID);};- /**- * Handle file viewer close to clear navigation state.- */const handleCloseFileViewerWithCleanup = () => {setInitialSidebar(undefined);setHighlightCommentID(undefined);@@ -173,7 +144,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({handleCloseFileViewer();};- // Download all files functionalityconst downloadAllFiles = () => {if (!collection) return;void import("@/public-album/download/services/save").then(@@ -193,26 +163,26 @@ export const TripLayout: React.FC<TripLayoutProps> = ({const [isClient, setIsClient] = useState(false);const [isLoadingLocations, setIsLoadingLocations] = useState(false);const [isInitialLoad, setIsInitialLoad] = useState(true);- const [currentZoom, setCurrentZoom] = useState(7); // Default zoom, will be updated by MapEvents and optimalZoom+ const [currentZoom, setCurrentZoom] = useState(7);const [mapRef, setMapRef] = useState<import("leaflet").Map | null>(null);- const [, setTargetZoom] = useState<number | null>(null); // Only setter is used by child components- const [scrollProgress, setScrollProgress] = useState(0); // 0 to 1 representing scroll progress- const [hasUserScrolled, setHasUserScrolled] = useState(false); // Track if user has actually scrolled- const [showMobileCover, setShowMobileCover] = useState(true); // Track mobile cover state+ const [, setTargetZoom] = useState<number | null>(null);+ const [scrollProgress, setScrollProgress] = useState(0);+ const [hasUserScrolled, setHasUserScrolled] = useState(false);+ const [showMobileCover, setShowMobileCover] = useState(true);const [locationPositions, setLocationPositions] = useState<PositionInfo[]>([],);const timelineRef = useRef<HTMLDivElement>(null);const locationRefs = useRef<(HTMLDivElement | null)[]>([]);const tripStartedRef = useRef<HTMLDivElement | null>(null);- const isClusterClickScrollingRef = useRef(false); // Use ref for immediate updates- const clusterClickTimeoutRef = useRef<NodeJS.Timeout | null>(null); // Timeout for cluster clicks- const thumbnailsGeneratedRef = useRef(false); // Track if thumbnails have been generated+ const isClusterClickScrollingRef = useRef(false);+ const clusterClickTimeoutRef = useRef<NodeJS.Timeout | null>(null);+ const thumbnailsGeneratedRef = useRef(false);const locationDataRef = useRef<Map<number, { name: string; country: string }>- >(new Map()); // Track location data to prevent resets- const filesCountRef = useRef<number>(0); // Track files count to detect real changes- const previousActiveLocationRef = useRef<number>(-1); // Track previous active location for discrete panning+ >(new Map());+ const filesCountRef = useRef<number>(0);+ const previousActiveLocationRef = useRef<number>(-1);const [photoClusters, setPhotoClusters] = useState<JourneyPoint[][]>([]);const [optimalZoom, setOptimalZoom] = useState(7);@@ -233,21 +203,18 @@ export const TripLayout: React.FC<TripLayoutProps> = ({) => void;}> | null>(null);- // Load client-side components and calculations+ // Leaflet and its helpers must load only in the browser.useEffect(() => {if (isClient) {- // Load TripMap componentvoid import("./TripMap").then(({ TripMap }) => {setTripMapComponent(() => TripMap);});- // Load mapHelpers and calculate clusters if we have dataif (journeyData.length > 0) {void import("./mapHelpers").then(({ clusterPhotosByProximity, calculateOptimalZoom }) => {const clusters = clusterPhotosByProximity(journeyData);- // Sort clusters by their earliest timestamp to maintain chronological orderconst sortedClusters = clusters.sort((a, b) => {const earliestA = Math.min(...a.map((p) => p.timestamp),@@ -268,14 +235,12 @@ export const TripLayout: React.FC<TripLayoutProps> = ({}}, [isClient, journeyData, isMobileOrTablet]);- // Update currentZoom when optimalZoom changes and there's no mapRef yetuseEffect(() => {if (!mapRef && optimalZoom !== currentZoom) {setCurrentZoom(optimalZoom);}}, [optimalZoom, mapRef, currentZoom]);- // Set client-side rendering flaguseEffect(() => {setIsClient(true);}, []);@@ -285,7 +250,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({return scheduleFileViewerPreload();}, [files.length]);- // Use extracted data processing hooksuseDataProcessing({files,collection,@@ -315,7 +279,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({setJourneyData,});- // Use extracted scroll handling hooksconst { markerClickHandler } = useScrollHandling({timelineRef,photoClusters,@@ -340,7 +303,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({tripStartedElement.getBoundingClientRect();const timelineRect = timelineContainer.getBoundingClientRect();- // Show/hide cover based on trip started positionconst threshold = timelineRect.top + timelineRect.height * 0.3;if (tripStartedRect.bottom < threshold) {setShowMobileCover(false);@@ -353,13 +315,10 @@ export const TripLayout: React.FC<TripLayoutProps> = ({setTargetZoom,});- // Only wait for client-side rendering (needed for maps), but show layout immediately- // Let individual components handle their own loading statesif (!isClient) {- return null; // SSR compatibility+ return null;}- // Show black background if no photo data yetconst hasPhotoData = journeyData.length > 0;return (@@ -385,10 +344,8 @@ export const TripLayout: React.FC<TripLayoutProps> = ({onJoinAlbum={handleJoinAlbum}/>))}- {/* Mobile Layout */}{isMobileOrTablet ? (<MobileContainer>- {/* Map takes 60% of height */}<MobileMapContainer>{TripMapComponent && (<TripMapComponent@@ -403,7 +360,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({onMarkerClick={markerClickHandler}/>)}- {/* Cover overlay */}{!isInitialLoad && journeyData.length > 0 && (<MobileCoverOverlay show={showMobileCover}><MobileCover@@ -415,7 +371,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({)}</MobileMapContainer>- {/* Timeline takes 40% of height */}<MobileTimelineContainer ref={timelineRef}><MobileTimelineContent>{isInitialLoad ? (@@ -478,7 +433,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({</MobileContainer>) : (<>- {/* Desktop Layout - Left Sidebar - Floating Timeline */}<TimelineSidebar ref={timelineRef}><TimelineContent>{isInitialLoad ? (@@ -580,7 +534,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({</TimelineContent></TimelineSidebar>- {/* Desktop Map Container */}{TripMapComponent && (<TripMapComponentjourneyData={journeyData}@@ -597,7 +550,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({</>)}- {/* FileViewer for photo gallery */}{openFileViewer && (<LazyFileVieweropen={openFileViewer}@@ -616,10 +568,8 @@ export const TripLayout: React.FC<TripLayoutProps> = ({/>)}- {/* Download progress notifications */}<ActiveDownloadStatusNotifications fullWidthOnMobile />- {/* Public feed sidebar */}{(publicFeedVisibilityProps.open || keepPublicFeedSidebarMounted) &&collection &&credentials?.current &&@@ -637,7 +587,6 @@ export const TripLayout: React.FC<TripLayoutProps> = ({);};-// Styled componentsconst TripLayoutContainer = styled(Box)({position: "relative",width: "100%",@@ -760,7 +709,6 @@ const NoPhotosContainer = styled(Box)(({ theme }) => ({fontSize: "16px",}));-// Mobile specific styled componentsconst MobileContainer = styled(Box)({display: "flex",flexDirection: "column",diff --git a/web/apps/albums/src/public-album/components/TripLayout/mapHelpers.ts b/web/apps/albums/src/public-album/components/TripLayout/mapHelpers.tsindex 9ef10b15be..c27242cfea 100644--- a/web/apps/albums/src/public-album/components/TripLayout/mapHelpers.ts+++ b/web/apps/albums/src/public-album/components/TripLayout/mapHelpers.ts@@ -2,14 +2,13 @@ import { haveWindow } from "ente-base/env";import type { JourneyPoint } from "./types";import { iconCache } from "./utils/geocoding";-// Mobile/tablet detection using media query breakpointconst isMobileDevice = () => {if (typeof window === "undefined") return false;- // Use 960px breakpoint to match Material-UI's "md" breakpoint for mobile and tablet+ // Keep this aligned with MUI's md breakpoint.return window.innerWidth < 960;};-// Conditionally import leaflet only in browser environment+// Leaflet reads window during import.const getLeaflet = () => {if (haveWindow()) {// eslint-disable-next-line @typescript-eslint/no-require-imports@@ -18,14 +17,14 @@ const getLeaflet = () => {return null;};-// Calculate distance between two points using Haversine formula (returns distance in km)+// Haversine distance in kilometers.export const calculateDistance = (lat1: number,lng1: number,lat2: number,lng2: number,): number => {- const R = 6371; // Radius of Earth in kilometers+ const R = 6371;const dLat = (lat2 - lat1) * (Math.PI / 180);const dLng = (lng2 - lng1) * (Math.PI / 180);const a =@@ -38,14 +37,13 @@ export const calculateDistance = (return R * c;};-// Geographic clustering with responsive distance thresholds and day separationexport const clusterPhotosByProximity = (photos: JourneyPoint[]) => {if (photos.length === 0) return [];- // 5km clustering distance (roughly 0.05 degrees)- const distanceThreshold = 0.05; // About 5km in degrees+ // Approximate five kilometers in coordinate degrees.+ const distanceThreshold = 0.05;- // First, group photos by day+ // Never cluster photos across local calendar days.const photosByDay = new Map<string, JourneyPoint[]>();photos.forEach((photo) => {const date = new Date(photo.timestamp);@@ -57,7 +55,6 @@ export const clusterPhotosByProximity = (photos: JourneyPoint[]) => {photosByDay.get(dayKey)!.push(photo);});- // Then cluster within each dayconst allClusters: JourneyPoint[][] = [];photosByDay.forEach((dayPhotos) => {@@ -90,13 +87,10 @@ export const clusterPhotosByProximity = (photos: JourneyPoint[]) => {return allClusters;};-// Return fixed zoom level of 10 for consistent positioningexport const calculateOptimalZoom = (): number => {- // Return fixed zoom of 10 as per new requirementsreturn 10;};-// Function to create icon with specific image and progress stylingexport const createIcon = (imageSrc: string,size = 40,@@ -106,20 +100,17 @@ export const createIcon = (): import("leaflet").DivIcon | null => {const leaflet = getLeaflet();if (typeof window === "undefined" || !leaflet) {- // Fallback icon for SSRreturn null;}- const pinSize = size + 16; // Make it square and bigger- const triangleHeight = size <= 30 ? 7 : 10; // Smaller triangle for mobile- const pinHeight = pinSize + triangleHeight + 2; // Add space for triangle+ const pinSize = size + 16;+ const triangleHeight = size <= 30 ? 7 : 10;+ const pinHeight = pinSize + triangleHeight + 2;const hasImage = imageSrc && imageSrc.trim() !== "";- // Adjust border radius for smaller mobile markersconst outerBorderRadius = size <= 30 ? 14 : 16;const innerBorderRadius = size <= 30 ? 10 : 12;- // Create cache key based on all parameters including border radius and triangle sizeconst cacheKey = `icon_${imageSrc}_${size}_${borderColor}_${isReached}_${outerBorderRadius}_${innerBorderRadius}_${triangleHeight}`;const cachedIcon = iconCache.get(cacheKey);@@ -136,7 +127,6 @@ export const createIcon = (cursor: pointer;transition: all 0.3s ease;">- <!-- Main rounded rectangle container --><div style="width: ${pinSize}px;height: ${pinSize}px;@@ -154,7 +144,6 @@ export const createIcon = (${hasImage? `- <!-- Image inside the rounded rectangle --><imgsrc="${imageSrc}"style="@@ -167,7 +156,6 @@ export const createIcon = (/>`: `- <!-- Loading skeleton when no image --><div style="width: 100%;height: 100%;@@ -184,8 +172,6 @@ export const createIcon = (`}</div>-- <!-- Triangle at the bottom --><div style="position: absolute;bottom: 2px;@@ -206,49 +192,39 @@ export const createIcon = (popupAnchor: [0, -pinHeight],});- // Cache the iconiconCache.set(cacheKey, icon);return icon;};-// Calculate map center with first location positioned at 20% from right edge+// Offset markers right to leave room for the desktop timeline.+// The constants below are tuned around zoom level 10.export const getMapCenter = (photoClusters: JourneyPoint[][],journeyData: JourneyPoint[],): [number, number] => {- // If no clusters yet, check journey dataif (photoClusters.length === 0) {const firstPoint = journeyData[0];- if (!firstPoint) return [0, 0]; // Fallback, but map won't render anyway+ if (!firstPoint) return [0, 0];return [firstPoint.lat, firstPoint.lng];}- // Start at first cluster centerconst firstCluster = photoClusters[0];- if (!firstCluster || firstCluster.length === 0) return [0, 0]; // Fallback, but map won't render anyway+ if (!firstCluster || firstCluster.length === 0) return [0, 0];const firstLat =firstCluster.reduce((sum, p) => sum + p.lat, 0) / firstCluster.length;const firstLng =firstCluster.reduce((sum, p) => sum + p.lng, 0) / firstCluster.length;- // Position first location at 20% from right edge (80% from left)- // At zoom level 10, each pixel represents approximately 152.87 meters- // On mobile, timeline is at bottom so full width is available; on desktop, timeline takes up 50% of screen width- // We want the first location to be at 20% from right of the visible map area- // This means shifting map center left so marker appears more to the right-const isMobile = isMobileDevice();- const timelineWidthRatio = isMobile ? 0.0 : 0.5; // Mobile: full width, Desktop: timeline takes up 50% of screen+ const timelineWidthRatio = isMobile ? 0.0 : 0.5;- // At zoom 10, approximately 0.35 degrees per 1000px at equator- // For positioning, we need to shift the longitude to place marker at desired position- const degreesPerPixelAtZoom10 = 0.35 / 1000; // rough approximation+ const degreesPerPixelAtZoom10 = 0.35 / 1000;const basePixelsToShift =(window.innerWidth || 1400) * (1 - timelineWidthRatio);const pixelsToShiftFor20Percent = isMobile- ? basePixelsToShift * 0.6 // Mobile: less aggressive positioning (60% instead of 300%)- : basePixelsToShift * 3.0; // Desktop: 300% of visible map width to shift map left+ ? basePixelsToShift * 0.6+ : basePixelsToShift * 3.0;const lngShift = pixelsToShiftFor20Percent * degreesPerPixelAtZoom10;const adjustedLng = firstLng - lngShift;@@ -256,55 +232,42 @@ export const getMapCenter = (return [firstLat, adjustedLng];};-// Calculate position for a location to be at 20% from right edge of visible mapexport const getLocationPosition = (lat: number,lng: number,): [number, number] => {- // Position location at 20% from right edge (80% from left) of visible map area- // On mobile, the timeline is at the bottom, not the side, so full width is available for mapconst isMobile = isMobileDevice();- const timelineWidthRatio = isMobile ? 0.0 : 0.5; // Mobile: full width, Desktop: timeline takes up 50% of screen- const degreesPerPixelAtZoom10 = 0.35 / 1000; // rough approximation at zoom 10+ const timelineWidthRatio = isMobile ? 0.0 : 0.5;+ const degreesPerPixelAtZoom10 = 0.35 / 1000;- // Calculate shift to position marker at 20% from right edge of visible map- // Need to shift map center left so the marker appears more to the right- // On mobile, use less aggressive positioning since we have full widthconst basePixelsToShift =(window.innerWidth || 1400) * (1 - timelineWidthRatio);const pixelsToShiftFor20Percent = isMobile- ? basePixelsToShift * 0.6 // Mobile: less aggressive positioning (60% instead of 300%)- : basePixelsToShift * 3.0; // Desktop: 300% of visible map width to shift map left+ ? basePixelsToShift * 0.6+ : basePixelsToShift * 3.0;const lngShift = pixelsToShiftFor20Percent * degreesPerPixelAtZoom10;return [lat, lng - lngShift];};-// Calculate position for a location to be at 20% from right edge at a specific zoom levelexport const getLocationPositionAtZoom = (lat: number,lng: number,zoom: number,): [number, number] => {- // Position location at 20% from right edge (80% from left) of visible map area- // On mobile, the timeline is at the bottom, not the side, so full width is available for mapconst isMobile = isMobileDevice();- const timelineWidthRatio = isMobile ? 0.0 : 0.5; // Mobile: full width, Desktop: timeline takes up 50% of screen+ const timelineWidthRatio = isMobile ? 0.0 : 0.5;- // Scale the positioning offset based on zoom level- // At higher zoom levels, we need less offset since we're more zoomed inconst baseDegreesPerPixelAtZoom10 = 0.35 / 1000;- const zoomScaleFactor = Math.pow(2, 10 - zoom); // Scale relative to zoom 10+ const zoomScaleFactor = Math.pow(2, 10 - zoom);const degreesPerPixelAtCurrentZoom =baseDegreesPerPixelAtZoom10 * zoomScaleFactor;- // Calculate shift to position marker at 20% from right edge of visible map- // On mobile, use less aggressive positioning since we have full widthconst basePixelsToShift =(window.innerWidth || 1400) * (1 - timelineWidthRatio);const pixelsToShiftFor20Percent = isMobile- ? basePixelsToShift * 0.6 // Mobile: less aggressive positioning (60% instead of 300%)- : basePixelsToShift * 3.0; // Desktop: 300% of visible map width to shift map left+ ? basePixelsToShift * 0.6+ : basePixelsToShift * 3.0;const lngShift = pixelsToShiftFor20Percent * degreesPerPixelAtCurrentZoom;return [lat, lng - lngShift];diff --git a/web/apps/albums/src/public-album/components/TripLayout/utils/scrollUtils.ts b/web/apps/albums/src/public-album/components/TripLayout/utils/scrollUtils.tsindex e840713cec..faf5dec7e9 100644--- a/web/apps/albums/src/public-album/components/TripLayout/utils/scrollUtils.ts+++ b/web/apps/albums/src/public-album/components/TripLayout/utils/scrollUtils.ts@@ -69,7 +69,6 @@ export const handleTimelineScroll = ({const clientHeight = timelineContainer.clientHeight;const scrollTop = timelineContainer.scrollTop;- // Calculate scroll progress (0 to 1)const isAtBottom = scrollTop + clientHeight >= scrollHeight - 10;const maxScrollableDistance = scrollHeight - clientHeight;const progress = isAtBottom@@ -88,16 +87,14 @@ export const handleTimelineScroll = ({setScrollProgress(clampedProgress);});- // Calculate current active location index based on scroll progress- let currentActiveLocationIndex = -1; // Start with no location selected+ let currentActiveLocationIndex = -1;if (photoClusters.length > 0) {if (isMobileOrTablet) {- // Mobile: Slower progression - stay on each location longer+ // Mobile keeps each location active for longer.currentActiveLocationIndex = Math.floor(clampedProgress * (photoClusters.length - 0.5),);} else {- // Desktop: Use original logiccurrentActiveLocationIndex = Math.round(clampedProgress * Math.max(0, photoClusters.length - 1),);@@ -105,14 +102,12 @@ export const handleTimelineScroll = ({}const previousActiveLocationIndex = previousActiveLocationRef.current;- // Only pan map when active location changes (discrete panning)if (mapRef?.getContainer() &¤tActiveLocationIndex !== previousActiveLocationIndex) {previousActiveLocationRef.current = currentActiveLocationIndex;- // Skip panning if no location is selected (mobile default view)if (currentActiveLocationIndex === -1) return;const clusterCenters = photoClusters.map((cluster) => {@@ -126,13 +121,11 @@ export const handleTimelineScroll = ({const targetCluster = clusterCenters[currentActiveLocationIndex];if (!targetCluster) return;- // Position active location at 20% from right edgeconst [positionedLat, positionedLng] = getLocationPosition(targetCluster.lat,targetCluster.lng,);- // Check if this is a distant location (>500km from previous)let isDistantLocation = false;if (previousActiveLocationIndex !== -1 &&@@ -146,22 +139,19 @@ export const handleTimelineScroll = ({targetCluster.lat,targetCluster.lng,);- isDistantLocation = distance > 500; // 500km threshold+ isDistantLocation = distance > 500;}}- const targetZoom = isMobileOrTablet ? 8 : 10; // Touch device-aware zoom level+ const targetZoom = isMobileOrTablet ? 8 : 10;try {- // Super cluster logic disabled - simple zoom transitionsif (isDistantLocation) {- // For distant locations not in super cluster: zoom out β pan β zoom in+ // Distant jumps zoom out before panning back in.const intermediateZoom = isMobileOrTablet ? 2 : 4;- // Use event listener for smoother animation chaining with pauseconst onZoomEnd = () => {mapRef.off("zoomend", onZoomEnd);- // Small pause to let user see the zoomed out viewsetTimeout(() => {setTargetZoom(targetZoom);mapRef.flyTo(@@ -184,7 +174,6 @@ export const handleTimelineScroll = ({easeLinearity: 0.2,});} else {- // For nearby locations not in super cluster: simple pan to target locationconst currentMapZoom = mapRef.getZoom();if (Math.abs(currentMapZoom - targetZoom) > 0.5) {mapRef.flyTo([positionedLat, positionedLng], targetZoom, {@@ -234,20 +223,15 @@ export const scrollTimelineToLocation = ({const clientHeight = timelineContainer.clientHeight;const maxScrollableDistance = scrollHeight - clientHeight;- // Calculate target progress using the same formula as scroll progress calculationlet targetProgress;if (isMobileOrTablet) {- // Mobile: Use inverse of the slower progression formula- // If active index = Math.floor(progress * (length - 0.5))- // Then progress = (index + 0.5) / (length - 0.5) for accurate inverse+ // Invert the mobile index formula in handleTimelineScroll.targetProgress =(locationIndex + 0.5) / Math.max(1, photoClusters.length - 0.5);} else {- // Desktop: Use original formulatargetProgress = locationIndex / Math.max(1, photoClusters.length - 1);}- // Clamp progress to valid rangetargetProgress = Math.min(1, Math.max(0, targetProgress));const targetScrollTop = targetProgress * maxScrollableDistance;@@ -298,21 +282,17 @@ export const handleMarkerClick = ({setScrollProgress(targetProgress);setHasUserScrolled(true);- // Update the previous active location to the target clusterpreviousActiveLocationRef.current = clusterIndex;if (mapRef?.getContainer()) {try {- // Super cluster logic disabled - simple fly to target with standard zoomconst [positionedLat, positionedLng] = getLocationPosition(clusterLat,clusterLng,);const targetZoomLevel = isMobileOrTablet ? 8 : 10;- // Set target zoom before animationsetTargetZoom(targetZoomLevel);- // Clear target zoom after animation completesconst onMoveEnd = () => {mapRef.off("moveend", onMoveEnd);setTargetZoom(null);diff --git a/web/apps/photos/src/components/CollectionSelector.tsx b/web/apps/photos/src/components/CollectionSelector.tsxindex 3d1ea9ca28..d12b688a67 100644--- a/web/apps/photos/src/components/CollectionSelector.tsx+++ b/web/apps/photos/src/components/CollectionSelector.tsx@@ -41,92 +41,25 @@ export type CollectionSelectorAction =| "unhide";export interface CollectionSelectorAttributes {- /**- * The {@link action} modifies the title of the dialog, and also removes- * some system collections that don't might not make sense for that- * particular action.- */action: CollectionSelectorAction;- /**- * Some actions, like "add" and "move", happen in the context of an existing- * collection summary.- *- * In such cases, the ID of the collection summary can be set as the- * {@link sourceCollectionID} to omit showing it in the list again.- */sourceCollectionSummaryID?: number;- /**- * If set, this collection will be shown first in the list.- *- * This is useful for the "upload" action, where the user is viewing a- * specific collection and might want to upload to it.- */activeCollectionID?: number;- /**- * If true, only show hidden albums in the collection selector.- *- * This is used when uploading from the hidden albums section.- */showHiddenCollections?: boolean;- /**- * Callback invoked when the user selects the option to create a new- * collection.- */onCreateCollection: () => void;- /**- * Callback invoked when the user selects one the existing collections- * listed in the dialog.- */onSelectCollection: (collection: Collection) => void;- /**- * Callback invoked when the user cancels the collection selection dialog.- */onCancel?: () => void;}export type CollectionSelectorProps = ModalVisibilityProps & {- /** Callback fired after the selector has finished closing. */onExited?: () => void;- /**- * The same {@link CollectionSelector} can be used for different- * purposes by customizing the {@link attributes} prop before opening it.- */attributes: CollectionSelectorAttributes | undefined;- /**- * The collections to list.- *- * The picker does not list all of the collection summaries, it filters- * these provided list down to values which make sense for the- * {@link attribute}'s {@link action}.- *- * See: [Note: Picking from selectable collection summaries].- */collectionSummaries: CollectionSummaries;- /**- * A function to map from a collection summary ID to a {@link Collection}.- *- * This is invoked when the user makes a selection, to convert the ID of the- * selected collection summary into a collection object that can be passed- * as the {@link callback} property of {@link CollectionSelectorAttributes}.- *- * [Note: Picking from selectable collection summaries]- *- * In general, not all pseudo collections can be converted into a- * collection. For example, there is no underlying collection corresponding- * to the "All" pseudo collection. However, the implementation of- * {@link CollectionSelector} is such that it filters the provided- * {@link collectionSummaries} to only show those which, when selected, can- * be mapped to an (existing or on-demand created) collection.- */+ // Every listed summary must map to a real or on-demand collection.collectionForCollectionSummaryID: (collectionID: number,) => Promise<Collection>;};-/**- * A dialog allowing the user to select one of their existing collections or- * create a new one, styled to match the upload design system.- */export const CollectionSelector: React.FC<CollectionSelectorProps> = (props,) => {@@ -139,7 +72,6 @@ export const CollectionSelector: React.FC<CollectionSelectorProps> = (collectionForCollectionSummaryID,} = props;- // Make the dialog fullscreen if the screen is <= the dialog's max width.const isFullScreen = useMediaQuery("(max-width: 490px)");const [searchTerm, setSearchTerm] = useState("");diff --git a/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx b/web/apps/photos/src/components/Collections/AlbumCastDialog.tsxindex 37164bf3a2..a1302b9c73 100644--- a/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx+++ b/web/apps/photos/src/components/Collections/AlbumCastDialog.tsx@@ -22,14 +22,8 @@ import React, { useCallback, useEffect, useState } from "react";import { Trans } from "react-i18next";import { z } from "zod";-type AlbumCastDialogProps = ModalVisibilityProps & {- /** The collection that we want to cast. */- collection: Collection;-};+type AlbumCastDialogProps = ModalVisibilityProps & { collection: Collection };-/**- * A dialog that shows various options that the user has for casting an album.- */export const AlbumCastDialog: React.FC<AlbumCastDialogProps> = ({open,onClose,@@ -40,32 +34,8 @@ export const AlbumCastDialog: React.FC<AlbumCastDialogProps> = ({</TitledMiniDialog>);-/**- * [Note: MUI dialog state]- *- * In some cases we keep the dialog contents in a separate component so that (a)- * they get rendered only when the dialog is shown, and (b) they get rendered- * afresh when the dialog is unmounted and then shown again.- *- * Keeping it separate both resets the state of the component, and also ensures- * that the effects run again when the dialog is shown.- *- * Details:- *- * Any state we keep inside the React component that a MUI Dialog as a child- * gets retained across visibility changes. For example, if the- * {@link AlbumCastDialogContents} were inlined into {@link AlbumCastDialog},- * then if we were to open the dialog, switch over to the "pin" view, then close- * the dialog by clicking on the backdrop, and then reopen it again, then we'd- * still remain on the "pin" view.- *- * This behaviour might be desirable or undesirable, depending on the- * circumstance. If it is undesirable, there are multiple approaches:- * https://github.com/mui/material-ui/issues/16325- *- * One of those approaches is to keep the dialog contents in a separate- * component.- */+// MUI preserves a dialog child's state while hidden.+// Keep contents separate so each open starts fresh and reruns effects.export const AlbumCastDialogContents: React.FC<AlbumCastDialogProps> = ({open,onClose,@@ -79,15 +49,9 @@ export const AlbumCastDialogContents: React.FC<AlbumCastDialogProps> = ({const [browserCanCast, setBrowserCanCast] = useState(false);- // The link to the cast app is to the full URL, but in the link text only- // show the host (e.g. for "https://cast.ente.com", show "cast.ente.com").const castHost = new URL(castURL).host;useEffect(() => {- // Determine if Chromecast is supported by the current browser- // (effectively, only Chrome).- //- // Override, otherwise tsc complains about unknown property `chrome`.// @ts-expect-error TODO: why is this needed// eslint-disable-next-line @typescript-eslint/dot-notationsetBrowserCanCast(typeof window["chrome"] != "undefined");@@ -155,11 +119,8 @@ export const AlbumCastDialogContents: React.FC<AlbumCastDialogProps> = ({}, [onClose, view, collection]);useEffect(() => {- // Make API call to clear all previous sessions (if any) whenever the- // dialog is opened so that the user can start a new session.- //- // This is not going to have an effect on the current client, so we- // don't need to wait for it to finish (and can ignore errors).+ // Start every open with new server-side sessions.+ // Revocation cannot affect this client, so do not block on it.if (open) void revokeAllCastTokens();}, [open]);@@ -249,7 +210,4 @@ export const AlbumCastDialogContents: React.FC<AlbumCastDialogProps> = ({);};-/**- * Zod schema for the "x-cast:pair-request" payload sent by the cast app.- */const CastPairRequest = z.object({ code: z.string() });diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsxindex 68303d6f12..fe9e60f65e 100644--- a/web/apps/photos/src/components/Collections/CollectionShare.tsx+++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx@@ -90,29 +90,13 @@ import { Trans } from "react-i18next";import { z } from "zod";export type CollectionShareProps = ModalVisibilityProps & {- /**- * The currently logged in user.- */user: LocalUser;collection: Collection;collectionSummary: CollectionSummary;- /**- * A map from known Ente user IDs to their emails- */emailByUserID: Map<number, string>;- /**- * A list of emails that can be served up as suggestions when the user is- * trying to share an album with another Ente user.- */shareSuggestionEmails: string[];setBlockingLoad: (value: boolean) => void;- /**- * Called when an operation in the share menu requires a full remote pull.- */onRemotePull: (opts?: RemotePullOpts) => Promise<void>;- /**- * When set, opens a specific nested share view directly.- */intent?: CollectionShareIntent;};@@ -133,32 +117,20 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({const { onGenericError } = useBaseContext();const { showLoadingBar, hideLoadingBar } = usePhotosAppContext();- // Use local state for collection to handle updates from fetchconst [collection, setCollection] = useState(collectionProp);- // Track if we've fetched a collection with public URLsconst hasFetchedPublicURLs = useRef(false);- // Update local collection when prop changes, but don't overwrite if we've fetched newer data+ // Do not replace fetched public URLs with an older prop snapshot.useEffect(() => {- // Only update from prop if:- // 1. We haven't fetched public URLs yet, OR- // 2. The prop has public URLs (meaning it's been updated with the latest data)if (!hasFetchedPublicURLs.current ||collectionProp?.publicURLs?.length > 0) {setCollection(collectionProp);}- // Skip the update if we've fetched public URLs but the prop doesn't have them- // This preserves the fetched data when parent component updates with outdated info}, [collectionProp]);// TODO: Duplicated from CollectionHeader.tsx- /**- * Return a new function by wrapping an async function in an error handler,- * showing the global loading bar when the function runs, and syncing with- * remote on completion.- */const wrap = useCallback((f: () => Promise<void>) => {const wrapped = async () => {@@ -190,10 +162,8 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({collection?.type != "uncategorized" &&(isOwner || (isSharedIncoming && hasPublicLink));- // Use a ref to track if we've already fetched for this dialog sessionconst hasFetchedForSession = useRef(false);- // Reset the fetch flags when dialog closesuseEffect(() => {if (!open) {hasFetchedForSession.current = false;@@ -201,8 +171,7 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({}}, [open]);- // Fetch collection for non-owners when the share pane opens- // to ensure we have the latest public link information+ // Fetch once per open; the remote pull can retrigger this effect.useEffect(() => {const refreshCollection = async () => {const shouldFetch =@@ -215,17 +184,14 @@ export const CollectionShare: React.FC<CollectionShareProps> = ({!hasFetchedForSession.current;if (shouldFetch) {- // Mark that we've fetched to prevent infinite loopshasFetchedForSession.current = true;try {const latestCollection = await getCollectionByID(collection.id,);- // If the fetched collection has public URLs, update local stateif (latestCollection.publicURLs.length > 0) {hasFetchedPublicURLs.current = true;setCollection(latestCollection);- // Also trigger remote pull to sync with parentawait onRemotePull({ silent: true });}} catch (e) {@@ -530,8 +496,6 @@ const EmailShare: React.FC<EmailShareProps> = ({useModalVisibility();const [participantRole, setParticipantRole] =- // Initial value is arbitrary, it always gets reset before- // `showAddParticipant` is called.useState<CollectionNewParticipantRole>("VIEWER");const showAddViewer = useCallback(() => {@@ -758,8 +722,6 @@ const AddParticipant: React.FC<AddParticipantProps> = ({) => {let emails: string[];if (typeof emailOrEmails == "string") {- // If email is a string, it means the user entered a custom email- // string, so validate it to skip self sharing and duplicate share.const email = emailOrEmails;if (email == user.email) {setEmailFieldError(t("sharing_with_self"));@@ -829,23 +791,8 @@ const AddParticipant: React.FC<AddParticipantProps> = ({};type AddParticipantFormProps = {- /**- * Title for the submit button.- */submitButtonTitle: string;- /**- * A list of emails the user can user to pick from.- */existingEmails: string[];- /**- * Submission handler. A callback invoked when the submit button is pressed.- *- * @param emailOrEmail Either the new email that the user entered, or the- * subset of {@link existingEmails} selected by the user.- *- * @param setEmailFieldError A function that can be called to set the error- * message shown below the email input field.- */onSubmit: (emailOrEmails: string | string[],setEmailFieldError: (message: string) => void,@@ -1265,12 +1212,7 @@ const ManageEmailShare: React.FC<ManageEmailShareProps> = ({type ManageParticipantProps = ModalVisibilityProps & {onRootClose: () => void;wrap: (f: () => Promise<void>) => () => void;- /**- * The participant in the collection who we're trying to manage.- *- * The caller semantically guarantees that participant will always be set- * when {@link open} is `true`, but the types don't reflect this.- */+ // open implies participant is set.participant: CollectionUser | undefined;} & Pick<CollectionShareProps, "collection" | "onRemotePull">;@@ -1291,8 +1233,6 @@ const ManageParticipant: React.FC<ManageParticipantProps> = ({};const unshare = wrap(() =>- // We should have a participant (with a valid email) if this ends up- // being called.unshareCollection(collection.id, participant!.email!),);@@ -1775,10 +1715,6 @@ type ManagePublicShareOptionsProps = ModalVisibilityProps & {onRootClose: () => void;publicURL: PublicURL;setPublicURL: (publicURL: PublicURL | undefined) => void;- /**- * The "resolved" publicURL, with both the full origin and the secret- * fragment appended to it.- */resolvedURL: string;} & Pick<CollectionShareProps,@@ -1801,7 +1737,6 @@ const ManagePublicShareOptions: React.FC<ManagePublicShareOptionsProps> = ({const [copied, handleCopyLink] = useClipboardCopy(resolvedURL);- // For embeddable HTML copyconst embedURL = resolvedURL? resolvedURL.replace(new URL(resolvedURL).origin,@@ -1955,19 +1890,11 @@ const ManagePublicShareOptions: React.FC<ManagePublicShareOptionsProps> = ({);};-/**- * The Prop type used by components that allow the use to modify some setting- * related to a public link.- */interface ManagePublicLinkSettingProps {publicURL: PublicURL;onUpdate: (req: UpdatePublicURLAttributes) => Promise<void>;}-/**- * An extension of {@link ManagePublicLinkSettingProps} for use when the- * component shows update options in a (nested) drawer.- */type ManagePublicLinkSettingDrawerProps = ManagePublicLinkSettingProps & {onRootClose: () => void;};@@ -2261,13 +2188,8 @@ const SetPublicLinkPassword: React.FC<SetPublicLinkPasswordProps> = ({await enablePublicUrlPassword(password);publicURL.passwordEnabled = true;onClose();- // The onClose above will close the dialog, but if we return immediately- // from this function, then the dialog will be temporarily rendered- // without the activity indicator on the button (before the entire- // dialog disappears). This gives a ungainly visual flash, so add a wait- // long enough so that the form's activity indicator persists longer- // than it'll take for the dialog to get closed.- return wait(1000 /* 1 second */);+ // Keep the submitting state through the close animation.+ return wait(1000);};const enablePublicUrlPassword = async (password: string) => {@@ -2280,17 +2202,13 @@ const SetPublicLinkPassword: React.FC<SetPublicLinkPasswordProps> = ({});};+ // This dialog is nested inside the sidebar.return (<Dialog{...{ open, onClose }}disablePortalslotProps={{- // We're being shown within the sidebar drawer, so limit the- // backdrop to only cover the drawer.backdrop: { sx: { position: "absolute" } },- // We're being shown within the sidebar drawer, and also the- // content of this dialog is lesser than what a normal dialog- // contains. Use a bespoke padding.paper: { sx: { "&&": { padding: "4px" } } },}}sx={{ position: "absolute" }}diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsxindex 45f21cb0cc..b5aea5183a 100644--- a/web/apps/photos/src/components/FileListWithViewer.tsx+++ b/web/apps/photos/src/components/FileListWithViewer.tsx@@ -33,14 +33,7 @@ import {} from "./FileList";export type FileListWithViewerProps = {- /**- * The list of files to show.- */files: EnteFile[];- /**- * Additional source data for deriving Map View files. Defaults to using- * {@link files} directly.- */mapFileSource?: {collectionFiles: EnteFile[];favoriteFileIDs: Set<number>;@@ -51,59 +44,22 @@ export type FileListWithViewerProps = {};enableDownload?: boolean;enableImageEditing?: boolean;- /**- * Called when the component wants to mark the given files as deleted in the- * the in-memory, unsynced, state maintained by the top level gallery.- *- * For more details, see {@link unsyncedFavoriteUpdates} in the gallery- * reducer's documentation.- */onMarkTempDeleted?: (files: EnteFile[]) => void;- /**- * Called when the visibility of the file viewer dialog changes.- */onSetOpenFileViewer?: (open: boolean) => void;- /**- * Called when an action in the file viewer requires us to perform a full- * pull from remote.- */onRemotePull: (opts?: RemotePullOpts) => Promise<void>;activeCollectionSummary?: CollectionSummary;activeCollection?: Collection;- /**- * If set, the file viewer will open to this file index on mount/update.- * Set to undefined after the navigation is complete.- */pendingFileIndex?: number;- /**- * The sidebar to open when navigating to a file from feed.- */pendingFileSidebar?: FileViewerInitialSidebar;- /**- * The comment ID to highlight when navigating from feed.- */pendingHighlightCommentID?: string;- /**- * Called after the pending navigation is consumed.- */onPendingNavigationConsumed?: () => void;- /**- * A function that can be used to create a UI notification to track the- * progress of user-initiated download, and to cancel it if needed.- */onAddSaveGroup: AddSaveGroup;onAddFileToCollection?: (file: EnteFile,sourceCollectionSummaryID?: number,) => void;- /**- * Called when the list scrolls, providing the current scroll offset.- */onScroll?: (scrollOffset: number) => void;- /**- * Called when the visible date at the top of the viewport changes.- */onVisibleDateChange?: (date: string | undefined) => void;} & Pick<FileListProps,@@ -147,11 +103,6 @@ export type FileListWithViewerProps = {| "onSelectPerson">;-/**- * A list of files (represented by their thumbnails), along with a file viewer- * that opens on activating the thumbnail (and also allows the user to navigate- * through this list of files).- */export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({mode,modePlus,@@ -227,7 +178,6 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({: (colorSchemeMode ?? theme.palette.mode);const isDarkMode = resolvedMode === "dark";- // Handle pending navigation from feed item clicksuseEffect(() => {if (pendingFileIndex !== undefined) {setCurrentIndex(pendingFileIndex);@@ -245,7 +195,6 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({onPendingNavigationConsumed,]);- // Clear initial sidebar state when file viewer closesconst handleCloseFileViewerInternal = useCallback(() => {setInitialSidebar(undefined);setHighlightCommentID(undefined);@@ -486,9 +435,6 @@ const MapIcon = styled("img")<{ $isDarkMode: boolean }>(}),);-/**- * See: [Note: Timeline date string]- */const fileTimelineDateString = (file: EnteFile) => {const date = fileCreationPhotoDate(file);return isSameDay(date, new Date())diff --git a/web/apps/photos/src/components/PlanSelector.tsx b/web/apps/photos/src/components/PlanSelector.tsxindex db787b5206..bf26872b20 100644--- a/web/apps/photos/src/components/PlanSelector.tsx+++ b/web/apps/photos/src/components/PlanSelector.tsx@@ -85,17 +85,6 @@ export const PlanSelector: React.FC<PlanSelectorProps> = ({[theme.breakpoints.down(360)]: { p: 0 },}),},- // [Note: Backdrop variant blur]- //- // What we wish for is creating a variant of Backdrop that- // instead of specifying the backdrop filter each time. But as- // of MUI v6.4, the TypeScript definition for Backdrop does not- // contain a variant, causing tsc to show an error when we try- // to specify a variant.- //- // Since the styling is trivial and used only infrequently, for- // now we copy paste it. If it gets needed more often, we can- // also make it into a palette var.backdrop: { sx: { backdropFilter: "blur(30px) opacity(95%)" } },}}>@@ -266,40 +255,24 @@ const PlanSelectorCard: React.FC<PlanSelectorCardProps> = ({);};-/**- * Return the outcome that should happen when the user selects a paid plan on- * the plan selection screen.- *- * @param subscription Their current subscription details.- */const planSelectionOutcome = (subscription: Subscription | undefined) => {- // This shouldn't happen, but we need this case to handle missing types.if (!subscription) return "buyPlan";- // The user is a on a free plan and can buy the plan they selected.if (subscription.productID == "free") return "buyPlan";- // Their existing subscription has expired. They can buy a new plan.if (subscription.expiryTime < Date.now() * 1000) return "buyPlan";- // -- The user already has an active subscription to a paid plan.-- // Using Stripe.if (subscription.paymentProvider == "stripe") {- // Update their existing subscription to the new plan.return "updateSubscriptionToPlan";}- // Using one of the mobile app stores.if (subscription.paymentProvider == "appstore" ||subscription.paymentProvider == "playstore") {- // They need to cancel first on the mobile app stores.return "cancelOnMobile";}- // Some other bespoke case. They should contact support.return "contactSupport";};@@ -720,11 +693,7 @@ const StripeSubscriptionOptions: React.FC<StripeSubscriptionOptionsProps> = ({action: async () => {await activateStripeSubscription();onClose();- // [Note: Chained MiniDialogs]- //- // The MiniDialog will automatically close when we the- // action promise resolves, so if we want to show another- // dialog, schedule it on the next run loop.+ // Wait for this action's dialog to close before showing another.setTimeout(() => {showMiniDialog({title: t("success"),@@ -751,7 +720,7 @@ const StripeSubscriptionOptions: React.FC<StripeSubscriptionOptionsProps> = ({action: async () => {await cancelStripeSubscription();onClose();- // See: [Note: Chained MiniDialogs]+ // Wait for this action's dialog to close before showing another.setTimeout(() => {showMiniDialog({message: t("subscription_cancel_success"),diff --git a/web/apps/photos/src/components/SelectedFileOptions.tsx b/web/apps/photos/src/components/SelectedFileOptions.tsxindex ca219a9819..2208bbc50d 100644--- a/web/apps/photos/src/components/SelectedFileOptions.tsx+++ b/web/apps/photos/src/components/SelectedFileOptions.tsx@@ -34,9 +34,6 @@ import type { Collection } from "ente-media/collection";import type { CollectionSummary } from "ente-new/photos/services/collection-summary";import { t } from "i18next";-/**- * Operations on selected files.- */export type FileOp =| "sendLink"| "download"@@ -49,137 +46,33 @@ export type FileOp =| "trash"| "deletePermanently";-/**- * Operations on selected files that also have an associated collection.- */export type CollectionOp = "add" | "move" | "restore" | "unhide";interface SelectedFileOptionsProps {barMode?: GalleryBarMode;isInSearchMode: boolean;selectedCollection?: Collection;- /**- * If {@link collectionSummary} is set and is not a pseudo-collection, then- * this will be set to the corresponding {@link Collection}.- */collection: Collection | undefined;- /**- * The collection summary in whose context the selection happened.- *- * This will not be set if we are in the people section, or if we are- * showing search results.- */collectionSummary: CollectionSummary | undefined;- /**- * The total number of files selected by the user.- */selectedFileCount: number;- /**- * The subset of {@link selectedFileCount} that are also owned by the user.- */selectedOwnFileCount: number;- /**- * The number of selected files that are currently favorited.- */selectedFavoriteCount: number;- /**- * Called when the user clears the selection by pressing the cancel button- * on the selection bar.- */onClearSelection: () => void;- /**- * Called when the user wants to remove the selected files from the given- * {@link collection}.- */onRemoveFilesFromCollection: (collection: Collection) => void;- /**- * Callback to open a dialog where the user can choose a collection.- *- * The reason for opening the dialog and other properties are passed as the- * {@link attributes} argument.- */onOpenCollectionSelector: (attributes: CollectionSelectorAttributes,) => void;- /**- * A function called to obtain a new album creation handler for the provided- * {@link op}.- *- * This function will be passed the operation to be be performed. It will- * return a new function G can be used as the {@link onCreateCollection}- * attribute for {@link onOpenCollectionSelector}.- *- * Once the user enters the name and a new album with that name gets- * created, the newly created collection will be passed to G.- *- * @param op The operation that should be performed on the selected files- * using the newly created collection.- *- * @returns A function that can be called with to create a new collection- * and then perform {@link op} on successful creation of the new collection.- */createOnCreateForCollectionOp: (op: CollectionOp) => () => void;- /**- * A function called to obtain an existing album selection handler for the- * provided {@link op}.- *- * This function will be passed the operation to be be performed. It will- * return a new function G can be used as the {@link onSelectCollection}- * attribute for {@link onOpenCollectionSelector}.- *- * Once the user selects a collection, then the selected collection will be- * passed to G.- *- * @param op The operation that should be performed on the selected files,- * using the selected collection.- *- * @returns A function that can be called with a selected collection.- */createOnSelectForCollectionOp: (op: CollectionOp,) => (selectedCollection: Collection) => void;- /**- * A function called to obtain a handler for the provided {@link op}.- *- * This function will be passed the file operation to be performed. It will- * return a new function G that can be used as a {@link onClick} handler for- * the button. Calling G will trigger the operation on the selected files.- *- * @param op The operation that should be performed on the selected files.- * @returns- */createFileOpHandler: (op: FileOp) => () => void;- /**- * Callback to show the assign person dialog.- *- * Similar to {@link onOpenCollectionSelector}, this opens a shared dialog- * defined in the parent component where the user can select a person to- * associate with the selected files.- *- * If not set, the "Add Person" option will not be shown.- */onShowAssignPersonDialog?: () => void;-- /**- * Called when the user wants to edit the location of the selected files.- *- * Only shown when at least one owned file is selected.- */onEditLocation?: () => void;- /**- * Called when the user wants to select all files.- */onSelectAll: () => void;- /**- * If true, all files in the current view are selected.- */isAllSelected: boolean;}-/**- * The selection bar shown at the top of the viewport when the user has selected- * one or more files in the photos app gallery.- */export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({barMode,isInSearchMode,@@ -203,14 +96,10 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({const handleFavorite = createFileOpHandler("favorite");const handleUnfavorite = createFileOpHandler("unfavorite");-const handleFixTime = createFileOpHandler("fixTime");-const handleDownload = createFileOpHandler("download");const handleSendLink = createFileOpHandler("sendLink");-const handleArchive = createFileOpHandler("archive");-const handleUnarchive = createFileOpHandler("unarchive");const handleDelete = () =>diff --git a/web/apps/photos/src/components/Sidebar.tsx b/web/apps/photos/src/components/Sidebar.tsxindex ee34a64d19..9987ce3b16 100644--- a/web/apps/photos/src/components/Sidebar.tsx+++ b/web/apps/photos/src/components/Sidebar.tsx@@ -139,63 +139,17 @@ import { Trans } from "react-i18next";import { SubscriptionCard } from "./SubscriptionCard";type SidebarProps = ModalVisibilityProps & {- /**- * Information about non-hidden collections and pseudo-collections.- *- * These are used to obtain data about the archive, hidden and trash- * "section" entries shown within the shortcut section of the sidebar.- */normalCollectionSummaries: CollectionSummaries;- /**- * The ID of the collection summary that should be shown when the user- * activates the "Uncategorized" section shortcut.- */uncategorizedCollectionSummaryID: number;-- /**- * Option search-triggered sidebar action to perform- */pendingAction?: SidebarActionID;-- /**- * Called after a pending sidebar action has been handled- */onActionHandled?: (actionID: SidebarActionID) => void;- /**- * Called when the plan selection modal should be shown.- */onShowPlanSelector: () => void;- /**- * Called when the collection summary with the given {@link collectionID}- * should be shown.- *- * @param collectionSummaryID The ID of the {@link CollectionSummary} to- * switch to.- *- * @param isHiddenCollectionSummary If `true`, then any reauthentication as- * appropriate before switching to the hidden section of the app is- * performed first before showing the collection summary.- *- * @return A promise that fullfills after any needed reauthentication has- * been peformed (The view transition might still be in progress).- */onShowCollectionSummary: (collectionSummaryID: number,isHiddenCollectionSummary?: boolean,) => Promise<void>;- /**- * Called when the export dialog should be shown.- */onShowExport: () => void;- /**- * Called when the user should be authenticated again.- *- * This will be invoked before sensitive actions, and the action will only- * proceed if the promise returned by this function is fulfilled.- *- * On errors or if the user cancels the reauthentication, the promise will- * not settle.- */+ // Cancellation or failure deliberately leaves this promise unsettled.onAuthenticateUser: () => Promise<void>;};@@ -368,12 +322,8 @@ export const Sidebar: React.FC<SidebarProps> = ({],);- // Use refs for callbacks to prevent the effect from re-running when- // callback identities change. This is critical because closing the auth- // modal causes handleSidebarClose to get a new identity (it depends on- // authenticateUserVisibilityProps.open), which cascades to- // performSidebarAction, causing this effect to re-run while pendingAction- // is still set - reopening the modal.+ // Closing auth changes these callback identities.+ // Letting that restart the pending action effect would reopen auth.const performSidebarActionRef = useRef(performSidebarAction);const onActionHandledRef = useRef(onActionHandled);useEffect(() => {@@ -747,7 +697,7 @@ const ShortcutSection: React.FC<ShortcutSectionProps> = ({const handleOpenHiddenSection = () =>void onShowCollectionSummary(PseudoCollectionID.hiddenItems, true)- // See: [Note: Workarounds for unactionable ARIA warnings]+ // Let focus settle before closing to avoid aria-hidden warnings..then(() => wait(10)).then(onCloseSidebar);@@ -1389,17 +1339,8 @@ const LanguageSelector = () => {if (newLocale === locale) return;void setLocaleInUse(newLocale).then(() => {- // [Note: Changing locale causes a full reload]- //- // A full reload is needed because we use the global `t` instance- // instead of the useTranslation hook.- //- // We also rely on this behaviour by caching various formatters in- // module static variables that not get updated if the i18n.language- // changes unless there is a full reload.- //- // Mark this as a trusted app-initiated reload so desktop app-lock- // setup does not force an immediate lock screen.+ // Global translations and cached formatters need a full reload.+ // Trust it so desktop app lock does not immediately lock again.if (globalThis.electron) {suppressAppLockRefreshFromSessionForTrustedReload();}@@ -1426,9 +1367,6 @@ const LanguageSelector = () => {);};-/**- * Human readable name for each supported locale.- */const localeName = (locale: SupportedLocale) => {switch (locale) {case "en-US":@@ -1481,7 +1419,7 @@ const localeName = (locale: SupportedLocale) => {const ThemeSelector = () => {const { mode, setMode } = useColorScheme();- // During SSR, mode is always undefined.+ // MUI color mode is undefined during SSR.if (!mode) return null;return (@@ -1524,7 +1462,7 @@ const DomainSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({);};-// Separate component to reset state on going back.+// This component boundary resets form state on back navigation.const DomainSettingsContents: React.FC = () => {const { customDomain, customDomainCNAME } = useSettingsSnapshot();diff --git a/web/apps/photos/src/components/gallery/BarImpl.tsx b/web/apps/photos/src/components/gallery/BarImpl.tsxindex a11c0ac640..718fc73808 100644--- a/web/apps/photos/src/components/gallery/BarImpl.tsx+++ b/web/apps/photos/src/components/gallery/BarImpl.tsx@@ -48,67 +48,19 @@ import {import type { GalleryBarMode } from "./reducer";export interface GalleryBarImplProps {- /**- * What are we displaying currently.- */mode: GalleryBarMode;- /**- * Called when the user selects to a different mode than the current one.- */onChangeMode: (mode: GalleryBarMode) => void;- /**- * Massaged data about the collections that should be shown in the bar.- */collectionSummaries: CollectionSummary[];- /**- * The ID of the currently active collection (if any).- *- * Required if mode is not "people".- */activeCollectionID: number | undefined;- /**- * Called when the user selects a new collection in the bar.- *- * This callback is passed the id of the selected collection.- */onSelectCollectionID: (collectionID: number) => void;- /**- * Called when the user selects the option to show a modal with all the- * albums.- */onShowAllAlbums: () => void;- /**- * Called when the user selects the option to show a modal with all the- * people.- */onShowAllPeople: () => void;- /**- * The scheme that should be used for sorting the collections in the bar.- */collectionsSortBy: CollectionsSortBy;- /**- * Called when the user changes the sorting scheme.- */onChangeCollectionsSortBy: (by: CollectionsSortBy) => void;- /**- * The scheme that should be used for sorting the people.- */peopleSortBy: PeopleSortBy;- /**- * Called when the user changes the people sorting scheme.- */onChangePeopleSortBy: (by: PeopleSortBy) => void;- /**- * The list of people that should be shown in the bar.- */people: Person[];- /**- * The currently selected person, if any.- */activePerson: Person | undefined;- /**- * Called when the selection should be moved to a new person in the bar.- */onSelectPerson: (personID: string) => void;}@@ -146,19 +98,8 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({setCanScrollRight(scrollLeft + clientWidth < scrollWidth);}, []);- // Maintain a ref to the list container with a combo of a callback and a- // regular ref.- //- // Using just a regular ref doesn't work - it is initially null, so- // updateScrollState is a no-op. Subsequently, react-window sets it to the- // correct element, but updateScrollState doesn't run, unless we add- // listContainerRef.current as a dependency. But that is just hacky.- //- // So instead we use a "callback ref", where we both act on the latest- // value, and also save it in a regular ref so that we can subsequently use- // it if the scroll position changes because of other, non-DOM, reasons- // (e.g. if the list of collections changes).-+ // react-window supplies the DOM node after the first render.+ // The callback ref initializes listeners; the regular ref handles later changes.const listContainerCallbackRef = useCallback<(ref: HTMLDivElement | null) => void>(@@ -166,16 +107,12 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({listContainerRef.current = ref;if (!ref) return undefined;- // Listen for scrolls and resize.ref.addEventListener("scroll", updateScrollState);const observer = new ResizeObserver(updateScrollState);observer.observe(ref);- // Call handler right away so that state gets updated for the- // initial size.updateScrollState();- // Remove listeners on cleanup.return () => {ref.removeEventListener("scroll", updateScrollState);observer.unobserve(ref);@@ -193,7 +130,6 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({useEffect(() => {if (!listRef.current) return;- // Scroll the active item into view.let i = -1;switch (mode) {case "albums":@@ -290,7 +226,6 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({return (<BarWrapper- // Hide the bottom border when showing the empty state for people.style={{"--et-bar-bottom-border-color":@@ -360,7 +295,6 @@ export const Row2 = styled("div")`const ModeIndicator: React.FC<Pick<GalleryBarImplProps, "mode" | "onChangeMode">> = ({ mode, onChangeMode }) => {- // Mode switcher is not shown in section-specific album views.if (mode == "hidden-albums") {return <Typography>{t("hidden_albums")}</Typography>;}@@ -368,9 +302,6 @@ const ModeIndicator: React.FC<return <Typography>{t("section_archive")}</Typography>;}- // Show the static mode indicator with only the "Albums" title if ML is not- // supported on this client (web), since there are no other sections to- // switch to in such a case.if (!isMLSupported) {return <Typography>{t("albums")}</Typography>;}@@ -573,13 +504,10 @@ interface CollectionBarCardIconProps {const CollectionBarCardIcon: React.FC<CollectionBarCardIconProps> = ({attributes,}) => (- // In the rarest of cases up to 4 of these can be true at once: a pinned- // album that is shared both with people and via a public link, and is also- // archived. The container is sized so that all 4 still fit on the tile.+ // A collection can show all four status icons at once.<CollectionBarCardIcon_>{attributes.has("userFavorites") && <StarIcon fontSize="small" />}{(attributes.has("pinned") || attributes.has("shareePinned")) && (- // Need && to override the 20px set in the container.<HugeiconsIcon icon={PinIcon} size={18} />)}{attributes.has("shared") && !attributes.has("sharedOnlyViaLink") && (diff --git a/web/apps/photos/src/components/gallery/PeopleHeader.tsx b/web/apps/photos/src/components/gallery/PeopleHeader.tsxindex 7e66a88f45..1438526508 100644--- a/web/apps/photos/src/components/gallery/PeopleHeader.tsx+++ b/web/apps/photos/src/components/gallery/PeopleHeader.tsx@@ -137,9 +137,7 @@ const CGroupPersonHeader: React.FC<CGroupPersonHeaderProps> = ({ person }) => {},});- // While technically it is possible for the cgroup not to have a name, logic- // wise we shouldn't be ending up here without a name (this state is- // expected to be reached only for unignored named persons).+ // This view only receives unignored, named people.const name = cgroup.data.name ?? "";return (@@ -302,17 +300,9 @@ const ClusterPersonHeader: React.FC<ClusterPersonHeaderProps> = ({type AddPersonDialogProps = ModalVisibilityProps &Pick<PeopleHeaderProps, "people" | "onSelectPerson"> & {- /**- * The cluster to add to the selected person (existing or new).- */cluster: FaceCluster;};-/**- * A dialog allowing the user to select one of the existing named persons they- * have, or create a new one, and then associate the provided cluster to it,- * creating or updating a remote "person".- */const AddPersonDialog: React.FC<AddPersonDialogProps> = ({open,onClose,@@ -344,19 +334,8 @@ const AddPersonDialog: React.FC<AddPersonDialogProps> = ({onSelectPerson(personID);};- // [Note: Calling setState during rendering]- //- // Calling setState during rendering should be avoided when there are- // cleaner alternatives, but it is not completely verboten, and it has- // documented semantics:- //- // > React will discard the currently rendering component's output and- // > immediately attempt to render it again with the new state.- // >- // > https://react.dev/reference/react/useState-- // If we're opened without any existing people that can be selected, jump- // directly to the add person dialog.+ // This render-time update intentionally redirects an empty list to naming.+ // React discards this render and starts another with the new state.if (open && !openNameInput && !cgroupPeople.length) {onClose();setOpenNameInput(true);@@ -435,29 +414,12 @@ type SuggestionsDialogProps = ModalVisibilityProps & { person: CGroupPerson };interface SuggestionsDialogState {activity: "fetching" | "saving" | undefined;- /**- * This is a workaround for the lack of stable identity of the person prop- * passed to the dialog (on which we trigger the suggestion computation.)- */+ // Track the ID because the person object has no stable identity.personID: string | undefined;- /**- * True if "fetching" failed.- */fetchFailed: boolean;- /**- * True if we should show the previously saved choice view instead of the- * new suggestions.- */showChoices: boolean;- /** Fetched choices. */choices: SCItem[];- /** Fetched suggestions. */suggestions: SCItem[];- /**- * An entry corresponding to each- * - saved choice for which the user has changed their mind.- * - suggestion that the user has either explicitly assigned or rejected.- */updates: PersonSuggestionUpdates;}@@ -515,27 +477,19 @@ const suggestionsDialogReducer: React.Reducer<const updates = new Map(state.updates);const { item, value } = action;if (item.assigned === undefined && value === undefined) {- // If this was a suggestion, prune previous updates since the- // use has toggled the item back to its original unset state.updates.delete(item.id);} else if (item.assigned !== undefined && value === item.assigned) {- // If this is a choice, prune updates which match the choice's- // original assigned state.updates.delete(item.id);} else {const update = (() => {switch (value) {case true:- // true corresponds to update "assign".return "assign";case false:- // false maps to different updates for suggestions- // vs choices.return item.assigned === undefined? "rejectSuggestion": "rejectSavedChoice";case undefined:- // undefined means reset.return "reset";}})();@@ -548,12 +502,8 @@ const suggestionsDialogReducer: React.Reducer<case "save":return { ...state, activity: "saving" };case "close":- // Reset the person ID when closing the dialog so that the- // suggestions are recomputed the next time the dialog is reopened- // (even for the same person).- //- // We cannot reset the suggestions themselves since they would cause- // the dialog to lose its visual state during the closing animation.+ // Reset the ID so reopening the same person recomputes suggestions.+ // Keep the lists visible during the closing animation.return { ...state, personID: undefined };}};@@ -582,9 +532,6 @@ const SuggestionsDialog: React.FC<SuggestionsDialogProps> = ({useEffect(() => {if (!open) return;- // Avoid recomputing when the person object changes without its identity- // changing. This is a workaround, a better fix would be to fix upstream- // to guarantee a stable identity of the person object itself.const personID = person.id;if (person.id == state.personID) return;@@ -682,7 +629,6 @@ const SuggestionsDialog: React.FC<SuggestionsDialogProps> = ({)}</SpacedRow><DialogContent- /* Reset scroll position on switching view */key={`${state.showChoices}`}sx={{ display: "flex", "&&&": { pt: 0 } }}>@@ -743,10 +689,6 @@ const SuggestionsDialog: React.FC<SuggestionsDialogProps> = ({interface SuggestionOrChoiceListProps {items: SCItem[];updates: PersonSuggestionUpdates;- /**- * Callback invoked when the user changes the value associated with the- * given suggestion or choice.- */onUpdateItem: (item: SCItem, value: boolean | undefined) => void;}@@ -763,7 +705,7 @@ const SuggestionOrChoiceList: React.FC<SuggestionOrChoiceListProps> = ({><Stack sx={{ gap: "10px" }}><Typography variant="small" sx={{ color: "text.muted" }}>- {/* Use the face count as as stand-in for the photo count */}+ {/* Face count stands in for photo count here. */}{t("photos_count", { count: item.faces.length })}</Typography><SuggestionFaceList faces={item.previewFaces} />@@ -791,8 +733,6 @@ const itemValueFromUpdate = (item: SCItem,updates: PersonSuggestionUpdates,) => {- // Use the in-memory state if available. For choices, fallback to their- // original state.const resolveUpdate = () => {switch (updates.get(item.id)) {case "assign":@@ -810,5 +750,4 @@ const itemValueFromUpdate = (};const toItemValue = (v: unknown) =>- // This dance is needed for TypeScript to recognize the type.v == "yes" ? true : v == "no" ? false : undefined;diff --git a/web/apps/photos/src/components/gallery/helpers.ts b/web/apps/photos/src/components/gallery/helpers.tsindex a14bde9e2b..dad4b112c6 100644--- a/web/apps/photos/src/components/gallery/helpers.ts+++ b/web/apps/photos/src/components/gallery/helpers.ts@@ -1,9 +1,5 @@-/**- * @file [Note: Gallery page logic] Logic and components for the gallery page, split out of pages/gallery.tsx.- *- * Separate from index.tsx so that it can export non-(React-)components, which- * is needed for fast refresh to work.- */+// TODO: Move this code back into gallery.tsx.+// Kept outside index.tsx so Fast Refresh allows non-component exports.import type { CollectionOp } from "@/components/SelectedFileOptions";import { getUserRecoveryKey } from "ente-accounts/services/recovery-key";@@ -19,80 +15,28 @@ import {} from "ente-new/photos/services/collection";import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";-/**- * Ensure that the keys in local storage are not malformed by verifying that the- * recoveryKey can be decrypted with the masterKey.- *- * This is not meant to be bullet proof, but more like an extra sanity check.- *- * @returns `true` if the sanity check passed, otherwise `false`. Since failure- * is not expected, the caller should {@link logout} on `false` to avoid- * continuing with an unexpected local state.- */+// A false result means the caller should log out instead of using local keys.export const validateKey = async () => {try {await getUserRecoveryKey();return true;} catch (e) {- log.warn("Failed to validate key" /*, caller will logout */, e);+ log.warn("Failed to validate key", e);return false;}};-/**- * Return the {@link Collection} (from amongst {@link collections}) with the- * given {@link collectionSummaryID}.- *- * As a special case, if the given {@link collectionSummaryID} is the ID of the- * placeholder uncategorized collection, create a new uncategorized collection- * and then return it.- *- * This is used in the context of the collection summary, so one of the two- * cases must be true.- */export const findCollectionCreatingUncategorizedIfNeeded = async (collections: Collection[],collectionSummaryID: number,): Promise<Collection> =>collectionSummaryID == PseudoCollectionID.uncategorizedPlaceholder? createUncategorizedCollection()- : // Null assert since the collection selector should only- // show "selectable" normalCollectionSummaries.- //- // See: [Note: Picking from selectable collection summaries].+ : // The selector only exposes summaries backed by collections.collections.find(({ id }) => id == collectionSummaryID)!;-/**- * Perform a "collection operation" on the selected file(s).- *- * @param op The {@link CollectionOp} to perform, e.g. "add", "restore".- *- * @param selectedCollection The existing or new collection selected by the- * user. This serves as the target of the operation.- *- * @param selectedFiles The files selected by the user, on which the operation- * should be performed.- *- * @param sourceCollectionID In the case of a "move", the operation is always- * expected to happen in the context of an existing collection, which serves as- * the source collection for the move. In such a case, the caller should provide- * this argument, using the collection ID of the collection in which the- * selection occurred.- *- * [Note: Add and move of non-user files]- *- * Adds can now operate on both owned and non-owned files using the same parity- * semantics as mobile:- *- * - current-user-owned files are added directly,- * - other-owned files reuse a same-hash owned file when available,- * - otherwise they are copied directly or via uncategorized depending on the- * destination ownership.- *- * Move semantics remain owner-only. Remote does not support cross-ownership- * moves, and mobile also models shared-album contributor flows as adds, not- * moves.- */+// Adds may copy non-owned files or reuse an owned file with the same hash.+// Moves remain owner-only; shared contributor flows are adds.export const performCollectionOp = async (op: CollectionOp,selectedCollection: Collection,diff --git a/web/apps/photos/src/components/gallery/index.tsx b/web/apps/photos/src/components/gallery/index.tsxindex fa7ef1ff83..631bcaff47 100644--- a/web/apps/photos/src/components/gallery/index.tsx+++ b/web/apps/photos/src/components/gallery/index.tsx@@ -1,6 +1,4 @@-/**- * @file [Note: Gallery page logic] Logic and components for the gallery page, split out of pages/gallery.tsx.- */+// TODO: Move this code back into gallery.tsx.import { EnableML, FaceConsent } from "@/components/sidebar/MLSettings";import { useWrapAsyncOperation } from "@/components/utils/use-wrap-async";@@ -29,28 +27,10 @@ import React, { useRef, useState } from "react";export { GalleryEmptyState } from "./GalleryEmptyState";-/**- * Options to customize the behaviour of the remote pull that gets triggered on- * various actions within the gallery and its descendants.- */export interface RemotePullOpts {- /**- * Perform the pull without showing a global loading bar- *- * Default: `false`.- */silent?: boolean;- /**- * The action that triggered this pull. Used to annotate downstream logs.- */source?: string;}-/**- * The context in which a selection was made.- *- * This allows us to reset the selection if user moves to a different context- * and starts a new selection.- * */export type SelectionContext =| {mode: "albums" | "hidden-albums" | "archive-albums";@@ -61,17 +41,8 @@ export type SelectionContext =interface SearchResultsHeaderProps {searchSuggestion: SearchSuggestion;fileCount: number;- /**- * Current sort order.- * - `undefined`: No sort selected (keeps original order, e.g. CLIP relevance)- * - `true`: Ascending (oldest first)- * - `false`: Descending (newest first)- */+ // undefined preserves source order; true is oldest-first; false is newest-first.sortAsc: boolean | undefined;- /**- * Called when the user changes the sort order.- * Pass `undefined` to reset to the original order (e.g., CLIP relevance).- */onSortOrderChange: (asc: boolean | undefined) => void;}@@ -141,9 +112,7 @@ interface SearchSortOrderMenuProps {onClose: () => void;sortButtonRef: React.RefObject<HTMLButtonElement | null>;sortAsc: boolean | undefined;- /** Whether the current search is a CLIP (magic) search. */isClipSearch: boolean;- /** Called when the user selects "Most Relevant" (only shown for CLIP searches). */onRelevanceClick: () => void;onAscClick: () => void;onDescClick: () => void;@@ -242,9 +211,7 @@ export const PeopleEmptyStateMessage: React.FC<React.PropsWithChildren> = ({sx={{color: "text.muted",mx: 1,- // Approximately compensate for the hidden section bar (86px),- // and then add a bit extra padding so that the message appears- // visually off the center, towards the top.+ // Offset the hidden 86px bar and bias the message upward.paddingBlockEnd: "126px",}}>@@ -263,8 +230,13 @@ export const PeopleEmptyStateDisabled: React.FC = () => {return (<Stack sx={{ alignItems: "center", flex: 1, overflow: "auto" }}><Paper- // Top margin is to prevent clipping of the shadow.- sx={{ maxWidth: "390px", padding: "4px", mt: 1, mb: "2rem" }}+ sx={{+ maxWidth: "390px",+ padding: "4px",+ // Prevent the card shadow from clipping.+ mt: 1,+ mb: "2rem",+ }}>{!showConsent ? (<EnableML onEnable={() => setShowConsent(true)} />diff --git a/web/apps/photos/src/components/sidebar/AppLockSettings.tsx b/web/apps/photos/src/components/sidebar/AppLockSettings.tsxindex 959bb46f3b..f08567a153 100644--- a/web/apps/photos/src/components/sidebar/AppLockSettings.tsx+++ b/web/apps/photos/src/components/sidebar/AppLockSettings.tsx@@ -43,17 +43,11 @@ export const AppLockSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({typeof navigator != "undefined" &&navigator.userAgent.toUpperCase().includes("MAC");- // For the 4-digit PIN setup and confirmation dialog.const [pinDialogOpen, setPinDialogOpen] = useState(false);- // For the password setup and confirmation dialog.const [passwordDialogOpen, setPasswordDialogOpen] = useState(false);- // Loading/disable flag while async device-lock setup is running.const [isSettingDeviceLock, setIsSettingDeviceLock] = useState(false);- // Controls whether the Device lock option should be shown after a compatibility check.const [showDeviceLockOption, setShowDeviceLockOption] = useState(false);- // For the auto-lock duration selection nested drawer.const [autoLockOptionsOpen, setAutoLockOptionsOpen] = useState(false);- // Cancel flag used to avoid state updates after unmount.const isDeviceLockOptionRequestCancelled = useRef(false);const { showMiniDialog } = useBaseContext();@@ -93,9 +87,6 @@ export const AppLockSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({}}, [open]);- /**- * Close both levels of the nested drawer.- */const handleRootClose = () => {setAutoLockOptionsOpen(false);onClose();@@ -104,14 +95,10 @@ export const AppLockSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({const handleSelectDeviceLock =useCallback(async (): Promise<DeviceLockEnableOutcome> => {- // Ignore repeated clicks while setup is already running.if (isSettingDeviceLock) return "failed";- // Show loading state while native device-lock setup runs.setIsSettingDeviceLock(true);try {- // setupDeviceLock performs capability checks and returns typed- // failure reasons when setup is unavailable or not completed.const result = await setupDeviceLock();if (result.status === "success") {return "success";@@ -161,7 +148,6 @@ export const AppLockSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({if (outcome !== "failed") return;}- // Fallback when macOS device lock setup is unavailable/failed.setPinDialogOpen(true);})();}, [@@ -180,12 +166,10 @@ export const AppLockSettings: React.FC<NestedSidebarDrawerVisibilityProps> = ({setPasswordDialogOpen(true);}, []);- // Close the PIN setup dialog after a successful setup.const handlePinSetupComplete = useCallback(() => {setPinDialogOpen(false);}, []);- // Close the password setup dialog after a successful setup.const handlePasswordSetupComplete = useCallback(() => {setPasswordDialogOpen(false);}, []);@@ -337,8 +321,6 @@ const deviceLockSetupErrorText = (result: SetupDeviceLockResult): string => {return t("device_lock_setup_failed");};-// -- Auto-lock duration helpers ---const autoLockOptions: { labelKey: string; ms: number }[] = [{ labelKey: "auto_lock_immediately", ms: 0 },{ labelKey: "auto_lock_5_seconds", ms: 5_000 },@@ -353,8 +335,6 @@ const autoLockLabel = (ms: number): string => {return t(option?.labelKey ?? "auto_lock_immediately");};-// -- PIN Setup Dialog ---interface SetupDialogProps {open: boolean;onClose: () => void;@@ -366,32 +346,16 @@ const PinSetupDialog: React.FC<SetupDialogProps> = ({onClose,onComplete,}) => {- // For PIN setup, there are two modals: one for initial input and one for confirmation.const [step, setStep] = useState<"enter" | "confirm">("enter");- // Stores the 4 PIN digits entered by the userconst [pin, setPin] = useState(["", "", "", ""]);- // Stores the 4 PIN digits entered for confirmationconst [confirmPin, setConfirmPin] = useState(["", "", "", ""]);- // Stores error message if PIN confirmation failsconst [error, setError] = useState("");- // DOM refs for the 4 PIN inputs in the "enter PIN" step.- // We keep these refs so the component can imperatively move focus between- // single-character fields (auto-advance on digit entry, move back on- // Backspace, and return focus to the first field when switching steps).const inputRefs = useRef<(HTMLInputElement | null)[]>([]);- // DOM refs for the 4 PIN inputs in the "confirm PIN" step.const confirmInputRefs = useRef<(HTMLInputElement | null)[]>([]);- // Tracks pending delayed focus so we can cancel stale timers safely.const focusTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);- /**- * queueFocus clears any existing timer and schedules a new focus callback- * with setTimeout(fn, delay).- *- * When steps change, inputs are remounted, so an immediate .focus() can- * run too early. This helper waits briefly, then focuses the correct field.- */+ // Step changes remount the inputs, so focus must wait for the next render.const queueFocus = useCallback((fn: () => void, delay: number) => {if (focusTimerRef.current) {clearTimeout(focusTimerRef.current);@@ -399,7 +363,6 @@ const PinSetupDialog: React.FC<SetupDialogProps> = ({focusTimerRef.current = setTimeout(fn, delay);}, []);- // Cleanup function to clear the focusTimer when the component unmounts.useEffect(() => {return () => {if (focusTimerRef.current) {@@ -434,26 +397,18 @@ const PinSetupDialog: React.FC<SetupDialogProps> = ({onClose();}, [resetState, onClose]);- // Sanitize input, write a digit, move focus forward, and reset the error.const handlePinDigitChange = (index: number,value: string,isConfirm: boolean,) => {- // Removes every non-digit character and keeps only the last digit.const digit = value.replace(/\D/g, "").slice(-1);- /**- * If the confirmation step is active, update the confirmPin state;- * otherwise, update the pin state.- */-if (isConfirm) {const next = [...confirmPin];next[index] = digit;setConfirmPin(next);- // If it's not the last index, advance focus automatically.if (digit && index < 3) {confirmInputRefs.current[index + 1]?.focus();}@@ -468,11 +423,6 @@ const PinSetupDialog: React.FC<SetupDialogProps> = ({setError("");};- /**- * Invoked on keypress. If the key is Backspace, use the active PIN array- * and, when the current box is empty and not the first one, move focus to- * the previous input.- */const handlePinKeyDown = (index: number,e: React.KeyboardEvent,@@ -487,19 +437,11 @@ const PinSetupDialog: React.FC<SetupDialogProps> = ({}};- /**- * Invoked when the next button is pressed on the first step,- * checks if all digits are present, and proceeds to the confirm step.- */const handleNext = useCallback(() => {if (pin.some((d) => !d)) return;setStep("confirm");}, [pin]);- /**- * If Back is pressed in the confirmation step, reset the- * confirmation array and switch to the entry step.- */const handleBack = useCallback(() => {setStep("enter");setConfirmPin(["", "", "", ""]);@@ -665,8 +607,6 @@ const PinSetupDialog: React.FC<SetupDialogProps> = ({);};-// -- Password Setup Dialog ---const PasswordSetupDialog: React.FC<SetupDialogProps> = ({open,onClose,@@ -871,8 +811,6 @@ const PasswordSetupDialog: React.FC<SetupDialogProps> = ({);};-// -- Auto-lock nested drawer ---interface AutoLockOptionsDrawerProps extends NestedSidebarDrawerVisibilityProps {currentValue: number;}diff --git a/web/apps/photos/src/pages/duplicates.tsx b/web/apps/photos/src/pages/duplicates.tsxindex b2b9e1b461..f83bbd73d3 100644--- a/web/apps/photos/src/pages/duplicates.tsx+++ b/web/apps/photos/src/pages/duplicates.tsx@@ -139,37 +139,11 @@ export default Page;type SortOrder = "prunableCount" | "prunableSize";interface DedupState {- /** Status of the analysis ("loading") process. */analysisStatus: undefined | "started" | "failed" | "completed";- /**- * Groups of duplicates.- *- * These are groups of files that our algorithm has detected as exact- * duplicates, augmented with UI state and various cached properties to make- * them more amenable to be directly used by the UI component.- *- * These are sorted in order of display, reflecting the {@link sortType}- * user preference.- */duplicateGroups: DuplicateGroup[];- /**- * The attribute to use for sorting {@link duplicateGroups}.- */sortOrder: SortOrder;- /**- * The number of files that will be pruned if the user decides to dedup the- * current selection.- */prunableCount: number;- /**- * The size (in bytes) that can be saved if the user decides to dedup the- * current selection.- */prunableSize: number;- /**- * If a dedupe is in progress, then this will indicate its progress- * percentage (a number between 0 and 100).- */dedupeProgress: number | undefined;}@@ -275,12 +249,6 @@ const dedupReducer: React.Reducer<DedupState, DedupAction> = (}};-/**- * Return a copy of the given {@link duplicateGroups}, also sorting them as per- * the given {@link sortOrder}.- *- * Helper method for the reducer.- */const sortedCopyOfDuplicateGroups = (duplicateGroups: DuplicateGroup[],sortOrder: DedupState["sortOrder"],@@ -291,7 +259,6 @@ const sortedCopyOfDuplicateGroups = (: b.prunableCount - a.prunableCount,);-/** Helper method for the reducer. */const deducePrunableCountAndSize = (duplicateGroups: DuplicateGroup[]) => {const prunableCount = duplicateGroups.reduce((sum, { prunableCount, isSelected }) =>@@ -307,18 +274,8 @@ const deducePrunableCountAndSize = (duplicateGroups: DuplicateGroup[]) => {};interface NavbarProps {- /**- * The current sort order.- */sortOrder: SortOrder;- /**- * Called when the user changes the sort order using the sort order menu- * visible via the navbar.- */onChangeSortOrder: (sortOrder: SortOrder) => void;- /**- * Called when the user selects the deselect all option.- */onDeselectAll: () => void;}@@ -339,7 +296,12 @@ const Navbar: React.FC<NavbarProps> = ({borderBottom: `1px solid ${theme.vars.palette.divider}`,})}>- <Box sx={{ minWidth: "100px" /* 2 icons + gap */ }}>+ <Box+ sx={{+ // Match the two right-side icons and their gap.+ minWidth: "100px",+ }}+ ><IconButton onClick={router.back}><ArrowBackIcon /></IconButton>@@ -450,26 +412,10 @@ const Duplicates: React.FC<DuplicatesProps> = ({);interface DuplicatesListProps {- /**- * The width (px) that the list should size itself to.- */width: number;- /**- * The height (px) that the list should size itself to.- */height: number;- /**- * Groups of duplicates. Guaranteed to be non-empty.- */duplicateGroups: DuplicateGroup[];- /**- * The current {@link SortOrder} that is being used for sorting {@link duplicateGroups}.- */sortOrder: SortOrder;- /**- * Called when the user toggles the selection for the duplicate group at the- * given {@link index}.- */onToggleSelection: (index: number) => void;}@@ -493,10 +439,7 @@ const DuplicatesList: React.FC<DuplicatesListProps> = ({const itemData = { layoutParams, duplicateGroups, onToggleSelection };const itemCount = duplicateGroups.length;const itemSize = (index: number) => {- // The height of the header is driven by the height of the Checkbox,- // which is 42px high, and the divider, which is 1px. The rest of the- // height comes from the fixed paddings, margins on the header, the- // divider, and on the row itself.+ // 42px checkbox + 1px divider + the surrounding fixed spacing.const fixedHeight = 24 + 42 + 4 + 1 + 20 + 16;const duplicateGroup = duplicateGroups[index]!;@@ -510,9 +453,7 @@ const DuplicatesList: React.FC<DuplicatesListProps> = ({const itemKey = (index: number, itemData: DuplicatesListItemData) =>itemData.duplicateGroups[index]!.id;- // Derive a key based on aspects whose change should cause the list to be- // recreated. This is the easiest way I've found to get react-window to- // invalidate `itemSize` values when, say, the width changes.+ // Remount to invalidate react-window's cached item sizes.const key = `${width}-${sortOrder}`;return (@@ -534,9 +475,6 @@ const ListItem: React.FC<ListChildComponentProps<DuplicatesListItemData>> =memo(({ index, style, data }) => {const { layoutParams, duplicateGroups, onToggleSelection } = data;- // For smaller screens, hide to divider to reduce visual noise. For- // larger screens, the divider is helpful in guiding the user's eyes to- // the checkbox which is otherwise at the right end of the header.const hideDivider = layoutParams.isSmallerLayout;const duplicateGroup = duplicateGroups[index]!;@@ -566,7 +504,6 @@ const ListItem: React.FC<ListChildComponentProps<DuplicatesListItemData>> =>{t("duplicate_group_description", { count, itemSize })}</Typography>- {/* The size of this Checkbox is 42px. */}<Checkbox {...{ checked, onChange }} /></SpacedRow><Divider@@ -612,12 +549,7 @@ const ItemGrid = styled("div", {type DeduplicateButtonProps = Pick<DedupState,"prunableCount" | "prunableSize" | "dedupeProgress"-> & {- /**- * Called when the user presses the button to remove duplicates.- */- onRemoveDuplicates: () => void;-};+> & { onRemoveDuplicates: () => void };const DeduplicateButton: React.FC<DeduplicateButtonProps> = ({prunableCount,@@ -633,8 +565,7 @@ const DeduplicateButton: React.FC<DeduplicateButtonProps> = ({<Stacksx={{gap: 1,- // Prevent a layout shift by giving a minHeight that is larger- // than all expected states.+ // Reserve space for every button state.minHeight: "45px",justifyContent: "center",flex: 1,diff --git a/web/apps/photos/src/pages/index.tsx b/web/apps/photos/src/pages/index.tsxindex c145da705d..e4ab20bb6a 100644--- a/web/apps/photos/src/pages/index.tsx+++ b/web/apps/photos/src/pages/index.tsx@@ -44,12 +44,10 @@ const Page: React.FC = () => {refreshHost();const currentURL = new URL(window.location.href);- // Store join album context immediately if present in URL- // This ensures it survives the authentication flow+ // Persist join data before authentication redirects discard this URL.const joinAlbumParam = currentURL.searchParams.get("joinAlbum");if (joinAlbumParam && joinAlbumParam !== "true") {try {- // Format: ?joinAlbum=accessToken&collectionId=123#collectionKeyHash&jwt=<jwtToken>const accessToken = joinAlbumParam;const collectionIdParam =currentURL.searchParams.get("collectionId");@@ -60,17 +58,14 @@ const Page: React.FC = () => {undefined;if (accessToken && collectionKeyHash && collectionIdParam) {- // Import the necessary functions to convert the collection keyconst { extractCollectionKeyFromShareURL } =await import("ente-gallery/services/share");- // Convert the hash to base64 for API callsconst tempURL = new URL(window.location.href);tempURL.hash = collectionKeyHash;const collectionKey =await extractCollectionKeyFromShareURL(tempURL);- // Create context from URL parametersconst context: JoinAlbumContext = {accessToken,collectionKey,@@ -172,41 +167,24 @@ const Page: React.FC = () => {export default Page;interface TappableContainerProps {- /**- * Called when the user closes the dialog to set a custom server.- *- * This is our chance to re-read the value of the custom API origin from- * local storage since the user might've changed it.- */onMaybeChangeHost: () => void;}const TappableContainer: React.FC<React.PropsWithChildren<TappableContainerProps>> = ({ onMaybeChangeHost, children }) => {- // [Note: Configuring custom server]- //- // Allow the user to tap 7 times anywhere on the onboarding screen to bring- // up a page where they can configure the endpoint that the app should- // connect to.- //- // See: https://ente.com/help/self-hosting/installation/post-install/+ // Seven background taps open self-hosting settings outside Ente production.const [tapCount, setTapCount] = useState(0);const [showDevSettings, setShowDevSettings] = useState(false);const handleClick: React.MouseEventHandler = (event) => {- // Don't allow this when running on (e.g.) photos.ente.com.if (!shouldAllowChangingAPIOrigin()) return;- // Ignore clicks on buttons when counting up towards 7.if (event.target instanceof HTMLButtonElement) return;- // Ignore clicks when the dialog is already open.if (showDevSettings) return;- // Otherwise increase the tap count,setTapCount(tapCount + 1);- // And show the dev settings dialog when it reaches 7.if (tapCount + 1 == 7) {setTapCount(0);setShowDevSettings(true);@@ -238,10 +216,6 @@ const TappableContainer: React.FC<);};-/**- * Disable the ability to set the custom server when we're running on our own- * production deployment.- */const shouldAllowChangingAPIOrigin = () => {const hostname = new URL(window.location.origin).hostname;return !(@@ -271,7 +245,6 @@ const SlideshowPanel = styled("div")``;const Logo_ = styled("div")`- /* Bias towards the left for better visual alignment with the slides. */padding-inline-end: 1rem;margin-block-start: 32px;@@ -337,14 +310,8 @@ const Slideshow: React.FC = () => {useEffect(() => {const container = containerRef.current!;const left = containerRef.current!.offsetWidth * selectedIndex;- // Smooth scroll doesn't work with Chrome intermittently. A common- // workaround is to wrap the scrollTo in a setTimeout etc, but even that- // doesn't help for our particular scenario.- //- // Ref: https://github.com/facebook/react/issues/23396- //- // As an alternative, scroll twice (once smoothly, once without) to the- // same position so that at least the fallback works on Chrome.+ // Chrome intermittently ignores the smooth scroll.+ // Repeat it without animation as a fallback.container.scrollTo({ left, behavior: "smooth" });setTimeout(() => container.scrollTo({ left }), 500);}, [selectedIndex]);@@ -386,8 +353,6 @@ const Slideshow: React.FC = () => {};const SlidesContainer = styled("div")`- /* Override the center align for ourselves so that we don't revert back to- our intrinsic width. */align-self: stretch;display: flex;overflow-x: hidden;diff --git a/web/apps/photos/src/services/large-files.ts b/web/apps/photos/src/services/large-files.tsindex 0d796ffb21..3e5ba77fbb 100644--- a/web/apps/photos/src/services/large-files.ts+++ b/web/apps/photos/src/services/large-files.ts@@ -9,55 +9,23 @@ import {import { savedCollectionFiles } from "ente-new/photos/services/photos-fdb";import { pullFiles } from "./pull";-/**- * Minimum file size (in bytes) to be considered a "large" file.- *- * This matches the mobile implementation: 10 MB.- */+// Keep the 10 MB threshold aligned with mobile.export const MIN_LARGE_FILE_SIZE = 10 * 1024 * 1024;-/**- * Filter type for large files.- */export type LargeFileFilter = "all" | "photos" | "videos";-/**- * A large file as shown in the UI.- */export interface LargeFileItem {- /**- * A nanoid for this item.- *- * This can be used as the key when rendering the item in a list.- */id: string;- /**- * The underlying file.- */file: EnteFile;- /**- * The size of the file in bytes.- */size: number;- /**- * `true` if the user has marked this item for deletion.- */isSelected: boolean;}-/**- * Find files larger than {@link MIN_LARGE_FILE_SIZE} in the user's library.- *- * @param filter The type of files to include (all, photos, or videos).- *- * @returns An array of {@link LargeFileItem} sorted by file size (descending).- */export const findLargeFiles = async (filter: LargeFileFilter,): Promise<LargeFileItem[]> => {const userID = ensureLocalUser().id;- // Get collections owned by the user.const normalCollections = await savedNormalCollections();const normalOwnedCollections = normalCollections.filter(({ owner }) => owner.id === userID,@@ -66,29 +34,21 @@ export const findLargeFiles = async (normalOwnedCollections.map(({ id }) => id),);- // Get all collection files.const collectionFiles = await savedCollectionFiles();- // Track files we've already added (by file ID) to avoid duplicates- // when the same file exists in multiple collections.const seenFileIDs = new Set<number>();const largeFiles: LargeFileItem[] = [];for (const file of collectionFiles) {- // Skip files not in allowed collections.if (!allowedCollectionIDs.has(file.collectionID)) continue;- // Skip files not owned by the user.if (file.ownerID !== userID) continue;- // Skip files already processed (same file in different collection).if (seenFileIDs.has(file.id)) continue;- // Get file size.const size = file.info?.fileSize;if (!size || size < MIN_LARGE_FILE_SIZE) continue;- // Apply filter.if (!matchesFilter(file, filter)) continue;seenFileIDs.add(file.id);@@ -96,15 +56,11 @@ export const findLargeFiles = async (largeFiles.push({ id: newID("lf_"), file, size, isSelected: false });}- // Sort by size descending (largest first).largeFiles.sort((a, b) => b.size - a.size);return largeFiles;};-/**- * Check if a file matches the given filter.- */const matchesFilter = (file: EnteFile, filter: LargeFileFilter): boolean => {switch (filter) {case "all":@@ -119,14 +75,6 @@ const matchesFilter = (file: EnteFile, filter: LargeFileFilter): boolean => {}};-/**- * Delete selected large files by moving them to trash.- *- * @param largeFiles The list of large file items.- * @param onProgress A function called with progress percentage (0-100).- *- * @returns A set of IDs of the items that were deleted.- */export const deleteSelectedLargeFiles = async (largeFiles: LargeFileItem[],onProgress: (progress: number) => void,@@ -139,69 +87,33 @@ export const deleteSelectedLargeFiles = async (}let completedSteps = 0;- const totalSteps = 2; // trash + sync+ const totalSteps = 2;const tickProgress = () =>onProgress((completedSteps++ / totalSteps) * 100);- // Move files to trash.await moveToTrash(filesToTrash);tickProgress();- // Sync local state.await pullFiles();tickProgress();return new Set(selectedItems.map((item) => item.id));};-/**- * Sort order for large files list.- */export type SortOrder = "desc" | "asc";-/**- * State for the large files page.- */export interface LargeFilesState {- /** Status of the analysis ("loading") process. */analysisStatus: undefined | "started" | "failed" | "completed";- /**- * List of large files.- *- * These are sorted by file size based on sortOrder.- */largeFiles: LargeFileItem[];- /**- * The current filter for file types.- */filter: LargeFileFilter;- /**- * The current sort order (descending = largest first, ascending = smallest first).- */sortOrder: SortOrder;- /**- * The number of files currently selected for deletion.- */selectedCount: number;- /**- * The total size (in bytes) of files currently selected for deletion.- */selectedSize: number;- /**- * If a deletion is in progress, this will indicate its progress- * percentage (a number between 0 and 100).- */deleteProgress: number | undefined;- /**- * Set of selected file IDs (the underlying EnteFile.id).- * Used to persist selection across filter changes.- */+ // Persists selection across filters.selectedFileIDs: Set<number>;}-/**- * Actions for the large files reducer.- */export type LargeFilesAction =| { type: "analyze" }| { type: "analysisFailed" }@@ -216,9 +128,6 @@ export type LargeFilesAction =| { type: "deleteFailed" }| { type: "deleteCompleted"; removedIDs: Set<string> };-/**- * Initial state for the large files reducer.- */export const largeFilesInitialState: LargeFilesState = {analysisStatus: undefined,largeFiles: [],@@ -230,9 +139,6 @@ export const largeFilesInitialState: LargeFilesState = {selectedFileIDs: new Set(),};-/**- * Reducer for the large files page state.- */export const largeFilesReducer = (state: LargeFilesState,action: LargeFilesAction,@@ -243,13 +149,11 @@ export const largeFilesReducer = (case "analysisFailed":return { ...state, analysisStatus: "failed" };case "analysisCompleted": {- // Restore selection state from selectedFileIDsconst selectedFileIDs = state.selectedFileIDs;const filesWithSelection = action.largeFiles.map((item) => ({...item,isSelected: selectedFileIDs.has(item.file.id),}));- // Sort according to current sort order (findLargeFiles always returns desc)const largeFiles = sortedCopyOfLargeFiles(filesWithSelection,state.sortOrder,@@ -266,15 +170,13 @@ export const largeFilesReducer = (}case "changeFilter": {- // No-op if filter hasn't actually changedif (action.filter === state.filter) {return state;}- // Block filter changes during deletion to prevent state corruption+ // Do not change the visible set during deletion.if (state.deleteProgress !== undefined) {return state;}- // Preserve selectedFileIDs when filter changesreturn {...largeFilesInitialState,filter: action.filter,@@ -284,7 +186,7 @@ export const largeFilesReducer = (}case "changeSortOrder": {- // Block sort order changes during deletion+ // Do not change the visible set during deletion.if (state.deleteProgress !== undefined) {return state;}@@ -298,17 +200,14 @@ export const largeFilesReducer = (case "toggleSelection": {const index = action.index;- // Bounds check to prevent crashesif (index < 0 || index >= state.largeFiles.length) {return state;}const item = state.largeFiles[index]!;const newIsSelected = !item.isSelected;- // Create new array with immutably updated itemconst largeFiles = state.largeFiles.map((file, i) =>i === index ? { ...file, isSelected: newIsSelected } : file,);- // Update selectedFileIDsconst selectedFileIDs = new Set(state.selectedFileIDs);if (newIsSelected) {selectedFileIDs.add(item.file.id);@@ -327,8 +226,6 @@ export const largeFilesReducer = (}case "deselectAll": {- // Only deselect currently visible items, preserve selections for- // items not in the current filtered viewconst visibleFileIDs = new Set(state.largeFiles.map((item) => item.file.id),);@@ -352,8 +249,6 @@ export const largeFilesReducer = (}case "selectAll": {- // Add currently visible items to selection, preserve existing- // selections from other filtered viewsconst largeFiles = state.largeFiles.map((item) => ({...item,isSelected: true,@@ -383,7 +278,6 @@ export const largeFilesReducer = (return { ...state, deleteProgress: undefined };case "deleteCompleted": {- // Single pass: filter files and collect removed file IDsconst largeFiles: LargeFileItem[] = [];const removedFileIDs = new Set<number>();for (const item of state.largeFiles) {@@ -393,7 +287,6 @@ export const largeFilesReducer = (largeFiles.push(item);}}- // Filter selectedFileIDs removing deleted onesconst selectedFileIDs = new Set<number>();for (const id of state.selectedFileIDs) {if (!removedFileIDs.has(id)) {diff --git a/web/apps/photos/src/services/pull.ts b/web/apps/photos/src/services/pull.tsindex bf8d34488e..2142b92765 100644--- a/web/apps/photos/src/services/pull.ts+++ b/web/apps/photos/src/services/pull.ts@@ -20,91 +20,18 @@ import { searchDataSync } from "ente-new/photos/services/search";import { pullSettings } from "ente-new/photos/services/settings";import { pullTrash, type TrashItem } from "ente-new/photos/services/trash";-/**- * Called during a full remote pull, before doing the files pull.- *- * [Note: Remote pull]- *- * There are two types of remote pulls we perform:- *- * - A "files" pull: Updating our local state with the latest collections,- * collection files, and trash from remote.- *- * - A "full" pull, which includes the files pull, and more.- *- * The full pull is performed by the gallery page, in the following sequence:- *- * 1. {@link prePullFiles}- * 2. {@link pullFiles}- * 3. {@link postPullFiles}.- *- * The full pull is performed in the following cases:- *- * - On the gallery page load (for both web and desktop).- * - Every 5 minutes thereafter (while the user is on the gallery page).- * - Each time the desktop app gains focus.- * - When the file viewer is closed after performing some operation.- *- * In some other cases, where we know that only specific collection or file- * state needs to be pulled, step 2 ({@link pullFiles}) is performed- * independently. For example, after deduping files, or updating the metadata of- * a file. See also: [Note: Full remote pull vs files pull]- */export const prePullFiles = async () => {await Promise.all([pullSettings(), isMLSupported && pullMLStatus()]);};interface PullFilesOpts {- /**- * Called when the saved collections were replaced by the given- * {@link collections}.- *- * Can be called multiple times during a pull, as each batch of changes is- * received and processed.- */onSetCollections: (collections: Collection[]) => void;- /**- * Called when saved collection files were replaced by the given- * {@link collectionFiles}.- *- * Can be called multiple times during a pull, as each batch of changes is- * received and processed.- */onSetCollectionFiles: (collectionFiles: EnteFile[]) => void;- /**- * Called when saved trashed items were replaced by the given- * {@link trashItems}.- *- * Can be called multiple times during a pull, as each batch of changes is- * received and processed.- */onSetTrashedItems: (trashItems: TrashItem[]) => void;- /**- * Called if one or more files were updated during the pull.- *- * Will be called at most once per pull.- */onDidUpdateCollectionFiles: () => void;}-/**- * Pull the latest collections, collections files and trash items from remote,- * updating our local database and also calling the provided callbacks.- *- * This is a subset of a full remote pull, independently exposed for use at- * times when we only want to pull the file related information (e.g. we just- * made some API request that modified collections or files, and so now want to- * update our local changes to match remote).- *- * See also: [Note: Remote pull]- *- * It is not robust to have multiple of these executing in parallel, and caller- * should have some mechanism to serialize invocations.- *- * @param opts various callbacks that are used by gallery to update its local- * state in tandem with the pull. The callbacks are optional since we might not- * have local state to update, as is the case when this is invoked post dedup.- */+// Do not run pullFiles concurrently.export const pullFiles = async (opts?: PullFilesOpts) => {const collections = await pullCollections();opts?.onSetCollections(collections);@@ -117,9 +44,7 @@ export const pullFiles = async (opts?: PullFilesOpts) => {opts?.onSetTrashedItems,videoPrunePermanentlyDeletedFileIDsIfNeeded,);- // After trash sync, fetch pending removal actions and move affected files- // to the uncategorized collection.- // Wrapped in try-catch since self-hosted servers may not have this endpoint.+ // Older self-hosted servers may not expose pending removal actions.try {await movePendingRemovalActionsToUncategorized(collections);} catch (e) {@@ -138,14 +63,8 @@ export const pullFiles = async (opts?: PullFilesOpts) => {}};-/**- * Called during a full remote pull, after doing the files pull.- *- * See: [Note: Remote pull]- */export const postPullFiles = async (source?: string) => {await Promise.all([searchDataSync(), videoProcessingSyncIfNeeded()]);- // ML sync might take a very long time for initial indexing, so don't wait- // for it to finish.+ // Initial indexing can be long; do not block the remote pull.void mlSync(source ? `remote-pull:${source}` : "remote-pull");};diff --git a/web/apps/photos/src/services/save.ts b/web/apps/photos/src/services/save.tsindex e9a11277e4..9f4881cb24 100644--- a/web/apps/photos/src/services/save.ts+++ b/web/apps/photos/src/services/save.ts@@ -16,47 +16,12 @@ import { fileFileName } from "ente-media/file-metadata";import { FileType } from "ente-media/file-type";import { decodeLivePhoto } from "ente-media/live-photo";-/**- * Save the given {@link files} to the user's device.- *- * If we're running in the context of the web app, the files will be saved to- * the user's download folder. If we're running in the context of our desktop- * app, the user will be prompted to select a directory on their file system and- * the files will be saved therein.- *- * @param files The files to save.- *- * @param title A title to show in the UI notification that indicates the- * progress of the save.- *- * @param onAddSaveGroup A function that can be used to create a save group- * associated with the save. The newly added save group will correspond to a- * notification shown in the UI, and the progress and status of the save can be- * communicated by updating the save group's state using the updater function- * obtained when adding the save group.- */export const downloadAndSaveFiles = (files: EnteFile[],title: string,onAddSaveGroup: AddSaveGroup,) => downloadAndSave(files, title, onAddSaveGroup);-/**- * Save all the files of a collection to the user's device.- *- * This is a variant of {@link downloadAndSaveFiles}, except instead of taking a- * list of files to save, this variant is tailored for saving saves all the- * files that belong to a collection. Otherwise, it broadly behaves similarly;- * see that method's documentation for more details.- *- * When running in the context of the desktop app, instead of saving the files- * in the directory selected by the user, files are saved in a directory with- * the same name as the collection.- *- * @param isHiddenCollectionSummary `true` if the collection is associated with- * a "hidden" collection or pseudo-collection in the app. Only relevant when- * running in the context of the photos app, can be `undefined` otherwise.- */export const downloadAndSaveCollectionFiles = async (collectionSummaryName: string,collectionSummaryID: number,@@ -73,9 +38,6 @@ export const downloadAndSaveCollectionFiles = async (isHiddenCollectionSummary,);-/**- * The lower level primitive that the public API of this module delegates to.- */const downloadAndSave = async (files: EnteFile[],title: string,@@ -98,7 +60,6 @@ const downloadAndSave = async (const total = files.length;if (!files.length) {- // Nothing to download.assertionFailed();return;}@@ -106,7 +67,6 @@ const downloadAndSave = async (suppressMainWindowBlurForTrustedPrompt();const selectedDirPath = await electron.selectDirectory();if (!selectedDirPath) {- // The user cancelled on the directory selection dialog.return;}const downloadDirPath = collectionSummaryName@@ -175,14 +135,6 @@ const downloadAndSave = async (await downloadFilesDesktop(files);};-/**- * Create a new directory on the user's file system with the same name as the- * provided {@link collectionName} under the provided {@link downloadDirPath},- * and return the full path to the created directory.- *- * This function can be used only when running in the context of our desktop- * app, and so such requires an {@link Electron} instance as the witness.- */const mkdirCollectionDownloadFolder = async ({ fs }: Electron,downloadDirPath: string,@@ -201,22 +153,6 @@ const mkdirCollectionDownloadFolder = async (return collectionDownloadPath;};-/**- * Save a file to the given {@link directoryPath} using native filesystem APIs.- *- * This is a sibling of {@link saveAsFile} for use when we are running in the- * context of our desktop app. Unlike the browser, the desktop app can use- * native file system APIs to efficiently write the files on disk without- * needing to prompt the user for each write.- *- * @param electron An {@link Electron} instance, a witness to the fact that- * we're running in the desktop app.- *- * @param file The {@link EnteFile} whose contents we want to save to the user's- * file system.- *- * @param directoryPath The file system directory in which to save the file.- */const saveFileDesktop = async (electron: Electron,file: EnteFile,diff --git a/web/apps/photos/src/services/search/sidebar-search-registry.ts b/web/apps/photos/src/services/search/sidebar-search-registry.tsindex 6c770cdfaa..81a4eaff33 100644--- a/web/apps/photos/src/services/search/sidebar-search-registry.ts+++ b/web/apps/photos/src/services/search/sidebar-search-registry.ts@@ -345,7 +345,7 @@ export const performSidebarAction = async (return (ctx.onShowCollectionSummary(ctx.pseudoIDs.hidden, true)- // See: [Note: Workarounds for unactionable ARIA warnings]+ // Let focus settle before closing to avoid aria-hidden warnings..then(() => wait(10)).then(() => ctx.onClose()));diff --git a/web/apps/photos/src/services/upload-manager.ts b/web/apps/photos/src/services/upload-manager.tsindex 0451f65743..e0d98e02c7 100644--- a/web/apps/photos/src/services/upload-manager.ts+++ b/web/apps/photos/src/services/upload-manager.ts@@ -51,7 +51,6 @@ import watcher from "./watch";export type FileID = number;export type PercentageUploaded = number;-/* localID => fileName */export type UploadFileNames = Map<FileID, string>;export interface UploadCounter {@@ -64,11 +63,7 @@ export interface InProgressUpload {progress: PercentageUploaded;}-/**- * A variant of {@link UploadResult}'s {@link type} values used when segregating- * finished uploads in the UI. "addedSymlink" is treated as "uploaded",- * everything else remains as it were.- */+// The UI groups addedSymlink with uploaded.export type FinishedUploadType = Exclude<UploadResult["type"], "addedSymlink">;export type InProgressUploads = Map<FileID, PercentageUploaded>;@@ -109,12 +104,6 @@ export const favoritedFilesFromUploadBatchResult = (): EnteFile[] => {const filesByID = new Map<number, EnteFile>();- /**- * Filters items with takeoutFavorited set to true, checks if their final upload- * target collection is not hidden, and collects successfully uploaded files- * and returns them to be added to the Favorites collection of the user after- * de-dupe check by fileID.- */for (const itemResult of batchResult.itemResults) {if (!itemResult.takeoutFavorited) continue;@@ -160,7 +149,6 @@ export interface ProgressUpdater {setUploadProgressView: React.Dispatch<React.SetStateAction<boolean>>;}-/** The number of uploads to process in parallel. */const maxConcurrentUploads = 4;export type UploadItemWithCollection = UploadAsset & {@@ -173,13 +161,11 @@ class UIService {// @ts-ignoreprivate progressUpdater: ProgressUpdater;- // UPLOAD LEVEL STATESprivate uploadPhase: UploadPhase = "preparing";private filenames = new Map<number, string>();private hasLivePhoto = false;private uploadProgressView = false;- // STAGE LEVEL STATESprivate perFileProgress = 0;private filesUploadedCount = 0;private totalFilesCount = 0;@@ -279,7 +265,6 @@ class UIService {// eslint-disable-next-line @typescript-eslint/no-unused-varsfor (const [_, progress] of this.inProgressUploads) {- // filter negative indicator values during percentComplete calculationif (progress < 0) {continue;}@@ -293,13 +278,6 @@ class UIService {setFinishedUploads(groupByResult(this.finishedUploads));}- /**- * Update the upload progress shown in the UI to {@link percentage} for the- * file with the given {@link fileLocalID}.- *- * @param percentage The upload completion percentage. It should be a value- * between 0 and 100 (inclusive).- */updateUploadProgress(fileLocalID: number, percentage: number) {this.inProgressUploads.set(fileLocalID, Math.round(percentage));this.updateProgressBarUI();@@ -335,11 +313,6 @@ class UploadManager {private collections = new Map<number, Collection>();private uploadInProgress = false;private fatalUploadError: Error | undefined;- /**- * When `true`, then the next call to {@link abortIfCancelled} will throw.- *- * See: [Note: Upload cancellation].- */private shouldUploadBeCancelled = false;private uiService = new UIService();@@ -385,26 +358,6 @@ class UploadManager {this.uiService.setUploadProgressView(false);}- /**- * Upload files- *- * This method waits for all the files to get uploaded (successfully or- * unsuccessfully) before returning.- *- * It is an error to call this method when there is already an in-progress- * upload.- *- * @param itemsWithCollection The items to upload, each paired with the id- * of the collection that they should be uploaded into.- *- * @param collections The collections to which the files are being uploaded.- *- * These are not all the user's collections - these are just the collections- * mentioned by one or more {@link itemsWithCollection}.- *- * @returns A summary of the completed batch and the per-item upload- * results for the files that were attempted.- */public async uploadItems(itemsWithCollection: UploadItemWithCollection[],collections: Collection[],@@ -443,8 +396,6 @@ class UploadManager {this.abortIfCancelled();- // Live photos might've been clustered together, reset the list- // of files to reflect that.this.uiService.setFiles(clusteredMediaItems);this.uiService.setHasLivePhoto(@@ -481,18 +432,6 @@ class UploadManager {};}- /**- * Upload a single file to the given collection.- *- * @param file A web {@link File} object representing the file to upload.- *- * @param collection The {@link Collection} in which the file should be- * added.- *- * @param sourceEnteFile The {@link EnteFile} from which the file being- * uploaded has been derived. This is used to extract and reassociated- * relevant metadata to the newly uploaded file.- */public async uploadFile(file: File,collection: Collection,@@ -507,12 +446,8 @@ class UploadManager {? { timestamp, dateTime, offset }: undefined;- // Canvas exports do not retain the original file's embedded metadata, so- // preserve the metadata Ente already knows about the source file.- //- // Preserve the richer creationDate when available so the edited copy- // retains the original photo's local capture date/time semantics (and- // optional offset), not just the raw UTC timestamp.+ // Canvas exports lose embedded metadata.+ // Preserve the source's local capture time and location.const externalParsedMetadata = {creationDate,creationTime: creationDate ? undefined : timestamp,@@ -677,7 +612,7 @@ class UploadManager {switch (uploadResult.type) {case "failed":case "blocked":- // Retriable error.+ // Failed and blocked items can be retried.this.failedItems.push(uploadableItem);break;@@ -715,10 +650,6 @@ class UploadManager {this.shouldUploadBeCancelled = true;}- /**- * Return the list of failed items from the last upload, along with other- * state needed to attempt to reupload them.- */public failedItemState() {return {items: [...this.failedItems],@@ -732,57 +663,17 @@ class UploadManager {this.onUploadFile!(file);}- /**- * `true` if an upload is currently in-progress (either a bunch of files- * directly uploaded by the user, or files being uploaded by the folder- * watch functionality).- */public isUploadInProgress = () => {return this.uploadInProgress || watcher.isUploadRunning();};}-/**- * Singleton instance of {@link UploadManager}.- */export const uploadManager = new UploadManager();-/**- * The data operated on by the intermediate stages of the upload.- *- * [Note: Intermediate file types during upload]- *- * As files progress through stages, they get more and more bits tacked on to- * them. These types document the journey.- *- * - The input is {@link UploadItemWithCollection}. This can either be a new- * {@link UploadItemWithCollection}, in which case it'll only have a- * {@link localID}, {@link collectionID} and a {@link uploadItem}. Or it could- * be a retry, in which case it'll not have a {@link uploadItem} but instead- * will have data from a previous stage (concretely, it'll just be a- * relabelled {@link ClusteredUploadItem}), like a snake eating its tail.- *- * - Immediately we convert it to {@link UploadItemWithCollectionIDAndName}.- * This is to mostly systematize what we have, and also attach a- * {@link fileName}.- *- * - These then get converted to "assets", whereby both parts of a live photo- * are combined. This is a {@link ClusteredUploadItem}.- *- * - On to the {@link ClusteredUploadItem} we attach the corresponding- * {@link collection}, giving us {@link UploadableUploadItem}. This is what- * gets queued and then passed to the {@link upload}.- */+// Retry items may already be clustered and omit uploadItem.type UploadItemWithCollectionIDAndName = UploadAsset & {- /** A unique ID for the duration of the upload */localID: number;- /** The ID of the collection to which this file should be uploaded. */collectionID: number;- /**- * The name of the file.- *- * In case of live photos, this'll be the name of the image part.- */fileName: string;};@@ -819,10 +710,6 @@ const splitMetadataAndMediaItems = (],);-/**- * Go through the given files, combining any sibling image + video assets into a- * single live photo when appropriate.- */const clusterLivePhotos = async (_items: UploadItemWithCollectionIDAndName[],parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,@@ -872,8 +759,7 @@ const clusterLivePhotos = async (});index += 2;} else {- // They may already be a live photo (we might be retrying a- // previously failed upload).+ // Retry items may already be clustered live photos.result.push({ ...fa, isLivePhoto: fa.isLivePhoto ?? false });index += 1;}@@ -920,25 +806,15 @@ export const uploadableMediaCount = async (return {count: (await clusterLivePhotos(mediaItems, parsedMetadataJSONMap)).length,- // The presence of Takeout metadata JSONs amongst the uploaded items- // indicates that this is a Google Takeout import.+ // Metadata sidecars identify a Takeout import.isTakeout: parsedMetadataJSONMap.size > 0,};};-/**- * Add logs if our usage increases some high water mark. This is solely so that- * we have some indication in the logs if we get a user report of OOM crashes.- */const logAboutMemoryPressureIfNeeded = () => {if (!globalThis.electron) return;- // performance.memory is deprecated in general as a Web standard, and is- // also not available in the DOM types provided by TypeScript. However, it- // is the method recommended by the Electron team (see the link about the V8- // memory cage). The embedded Chromium supports it fine though, we just need- // to goad TypeScript to accept the type.-+ // Electron recommends this deprecated API, and Chromium still supports it.const { memory } = performance as unknown as {memory: { totalJSHeapSize: number; jsHeapSizeLimit: number };};diff --git a/web/apps/photos/src/utils/file-actions.ts b/web/apps/photos/src/utils/file-actions.tsindex aed755e7f0..7ff8430d6e 100644--- a/web/apps/photos/src/utils/file-actions.ts+++ b/web/apps/photos/src/utils/file-actions.ts@@ -4,11 +4,6 @@ import {type CollectionSummary,} from "ente-new/photos/services/collection-summary";-/**- * Actions that can be performed on files via the context menu.- *- * These correspond to the same operations available in SelectedFileOptions.- */export type FileContextAction =| "sendLink"| "download"@@ -28,44 +23,15 @@ export type FileContextAction =| "removeFromAlbum"| "addPerson";-/**- * Context needed to determine which file actions should be available.- */interface FileActionContext {- /** The current bar mode (albums, hidden-albums, archive-albums, people). */barMode?: GalleryBarMode;- /** Whether we're in search mode. */isInSearchMode: boolean;- /**- * The collection summary for the current view.- *- * Will be undefined if we're in people section or showing search results.- */collectionSummary: CollectionSummary | undefined;- /**- * Whether every selected file is owned by the current user.- */hasOnlyOwnFiles: boolean;- /**- * Whether to show the "Add Person" action.- *- * This depends on ML being enabled and having named people.- */showAddPerson: boolean;- /**- * Whether to show the "Edit Location" action.- *- * This depends on every selected file being owned.- */showEditLocation: boolean;}-/**- * Returns the list of available file actions based on the current context.- *- * This function encapsulates the conditional logic from SelectedFileOptions- * to enable reuse in both the selection bar and the context menu.- */export function getAvailableFileActions(context: FileActionContext,): FileContextAction[] {@@ -90,8 +56,6 @@ export function getAvailableFileActions(insertSendLinkBeforeDownload(actions);}- // Insert "addPerson" before modification actions if enabled- // (not applicable for trash since you can't add people to trashed files)if (showAddPerson && collectionSummary?.id !== PseudoCollectionID.trash) {insertAddPersonBeforeModifications(actions);}@@ -99,9 +63,6 @@ export function getAvailableFileActions(return actions;}-/**- * Returns base actions without the "addPerson" action.- */function getBaseActions(barMode: GalleryBarMode | undefined,isInSearchMode: boolean,@@ -109,7 +70,6 @@ function getBaseActions(hasOnlyOwnFiles: boolean,showEditLocation: boolean,): FileContextAction[] {- // Search mode actionsif (isInSearchMode) {const actions: FileContextAction[] = ["favorite"];if (hasOnlyOwnFiles) {@@ -125,7 +85,6 @@ function getBaseActions(return actions;}- // People mode actionsif (barMode === "people") {const actions: FileContextAction[] = ["favorite",@@ -138,7 +97,6 @@ function getBaseActions(return actions;}- // Trash actionsif (collectionSummary?.id === PseudoCollectionID.trash) {return ["restore", "deletePermanently"];}@@ -160,7 +118,6 @@ function getBaseActions(return actions;}- // Uncategorized actionsif (collectionSummary?.attributes.has("uncategorized")) {const actions: FileContextAction[] = ["download"];if (hasOnlyOwnFiles) {@@ -169,12 +126,10 @@ function getBaseActions(return actions;}- // Hidden albums mode actionsif (barMode === "hidden-albums") {return ["download", "unhide", "trash"];}- // Default (normal albums) actionsconst isUserFavorites =!!collectionSummary?.attributes.has("userFavorites");const isArchiveItems =@@ -182,7 +137,6 @@ function getBaseActions(const actions: FileContextAction[] = [];- // Favorite/unfavorite action shown when not in archive.if (isUserFavorites) {actions.push("unfavorite");} else if (!isArchiveItems) {@@ -219,9 +173,6 @@ function getBaseActions(return actions;}-/**- * Inserts "sendLink" before "download" if present, else prepends it.- */function insertSendLinkBeforeDownload(actions: FileContextAction[]): void {const downloadIndex = actions.indexOf("download");if (downloadIndex !== -1) {@@ -231,10 +182,6 @@ function insertSendLinkBeforeDownload(actions: FileContextAction[]): void {}}-/**- * Actions that modify file visibility or collection membership.- * "addPerson" is inserted before the first of these actions.- */const modificationActions: FileContextAction[] = ["archive","unarchive",@@ -245,9 +192,6 @@ const modificationActions: FileContextAction[] = ["removeFromAlbum",];-/**- * Inserts "addPerson" before the first modification action in the array.- */function insertAddPersonBeforeModifications(actions: FileContextAction[],): void {diff --git a/web/packages/base/app.ts b/web/packages/base/app.tsindex c3136a967c..61a61330dc 100644--- a/web/packages/base/app.ts+++ b/web/packages/base/app.ts@@ -18,58 +18,18 @@ export const appNames = ["space",] as const;-/**- * Arbitrary names that we used as keys for indexing various constants- * corresponding to our apps that rely on this package.- */export type AppName = (typeof appNames)[number];-/**- * The unique key for the app.- *- * This is the name of the Ente app which we're currently running as. It is used- * as a key for various properties that are different across apps.- *- * Parts of our code are shared across apps. Some parts of them also run in- * non-main thread execution contexts like web workers. So there isn't always an- * easy way to figure out what the current app is.- *- * To solve this, we inject the app name during the build process. This is- * available to all our code (shared packages, web workers).- *- * This constant employs an `as` cast to avoid incurring a dynamic check, and as- * such may be incorrect (e.g. when a new app gets added). So apps should- * dynamically validate and log it once somewhere during init.- */+// Build-time injection makes this available inside workers.+// The cast is unchecked; each app must validate the value during startup.export const appName: AppName = buildEnvAppName as AppName;-/**- * True if we're running in our desktop app.- *- * This is similar to checking for `globalThis.electron`, however the advantage- * of this check is that it will also work inside web workers (whose globalThis- * won't have an electron object defined).- *- * This check can still have false positives during dev mode if someone connects- * their browser to port where the desktop app's web app is being served from in- * dev mode. If in the future some code needs to definitely rule out those false- * positives, it'd need a runtime check of the form- * `navigator.userAgent.includes("Electron")`.- */+// Unlike globalThis.electron, this also works inside workers.+// A browser pointed at the desktop dev server can produce a false positive.export const isDesktop = buildEnvIsDesktop;-/**- * Version of the desktop app.- *- * This is only defined when {@link isDesktop} is true.- */export const desktopAppVersion = buildEnvDesktopAppVersion;-/**- * Static (English) title for the app.- *- * This is shown until we have the localized version.- */export const staticAppTitle = {accounts: "Ente Accounts",albums: "Ente Photos",@@ -78,21 +38,13 @@ export const staticAppTitle = {embed: "Ente Photos",share: "Ente Locker",photos: "Ente Photos",- // Ensu (chat) web app.ensu: "Ensu",locker: "Ente Locker",legacy: "Ente Legacy Kit",space: "Ente Space",}[appName];-/**- * Client "package names" for our app.- *- * The package name is used as the "X-Client-Package" header in API requests.- *- * In cases where this code works for both a web and a desktop app for the same- * app (currently only photos), this will be the platform specific package name.- */+// Sent as the X-Client-Package header.export const clientPackageName = (() => {if (isDesktop) {if (appName === "photos") return "io.ente.photos.desktop";@@ -107,7 +59,6 @@ export const clientPackageName = (() => {embed: "io.ente.photos.web", // Use photos package name for embed appshare: "io.ente.share.web",photos: "io.ente.photos.web",- // Ensu (chat) web app.ensu: "io.ente.ensu",locker: "io.ente.locker.web",legacy: "io.ente.legacy.web",@@ -115,15 +66,6 @@ export const clientPackageName = (() => {}[appName];})();-/**- * The client package name, augmented with the client version where applicable.- *- * This string is used as the "client identifier" in payloads (e.g. ML data- * generated by a client).- *- * For the desktop app, it will be client package name and version. Otherwise,- * it'll just be the same as {@link clientPackageName}.- */export const clientIdentifier = (() => {if (isDesktop) {if (!desktopAppVersion)diff --git a/web/packages/base/components/Head.tsx b/web/packages/base/components/Head.tsxindex a7d9ca7750..891b069b9f 100644--- a/web/packages/base/components/Head.tsx+++ b/web/packages/base/components/Head.tsx@@ -24,12 +24,6 @@ const albumsPreviewTitle = "Photos, shared with you";const albumsPreviewDescription = "Tap to view on Ente";const albumsPreviewImage = "https://albums.ente.com/images/preview.png";-/**- * A custom version of "next/head" that sets the title, description, favicon and- * some other boilerplate <head> tags.- *- * This assumes the existence of `public/images/favicon.png`.- */export const CustomHead: React.FC<React.PropsWithChildren<CustomHeadProps>> = ({title,children,@@ -46,21 +40,7 @@ export const CustomHead: React.FC<React.PropsWithChildren<CustomHeadProps>> = ({</Head>);-/**- * A static SSR-ed variant of {@link CustomHead} for use with the albums app- * deployed on production Ente instances for link previews.- *- * In particular,- *- * - Any client side modifications to the document's head will be too late for- * use by the link previews, so the contents of this need to part of the- * static HTML.- *- * - "og:image" needs to be an absolute URL.- *- * To avoid getting in the way of self hosters, only inline this into builds- * that use Ente's production API.- */+// Link preview crawlers only see static HTML, and og:image must be absolute.export const CustomHeadAlbumsStatic: React.FC = () => (<Head><AlbumsFontPreloads />@@ -85,14 +65,7 @@ export const CustomHeadAlbumsStatic: React.FC = () => (</Head>);-/**- * A convenience fan out to conditionally show one of {@link CustomHead} or- * {@link CustomHeadAlbumsStatic}.- *- * Use static production preview tags only when using Ente's production API.- * Custom API builds should not inline production preview metadata into the- * static HTML.- */+// Custom API builds must not embed Ente production preview metadata.export const CustomHeadAlbums: React.FC<CustomHeadProps> = ({ title }) =>isCustomAPIOrigin ? (<CustomHead {...{ title }}>@@ -102,13 +75,6 @@ export const CustomHeadAlbums: React.FC<CustomHeadProps> = ({ title }) =><CustomHeadAlbumsStatic />);-/**- * A static SSR-ed variant of {@link CustomHead} for use with the share app- * (Public Locker) deployed on production Ente instances for link previews.- *- * Similar to {@link CustomHeadAlbumsStatic}, this includes Open Graph meta tags- * with absolute URLs for social media preview images.- */export const CustomHeadShareStatic: React.FC = () => (<Head><title>Ente Locker</title>@@ -130,14 +96,6 @@ export const CustomHeadShareStatic: React.FC = () => (</Head>);-/**- * A convenience fan out to conditionally show one of {@link CustomHead} or- * {@link CustomHeadShareStatic}.- *- * Use static production preview tags only when using Ente's production API.- * Custom API builds should not inline production preview metadata into the- * static HTML.- */export const CustomHeadShare: React.FC<CustomHeadProps> = ({ title }) =>isCustomAPIOrigin ? (<CustomHead {...{ title }} />diff --git a/web/packages/base/components/Notification.tsx b/web/packages/base/components/Notification.tsxindex addf0d96a2..76ef48798a 100644--- a/web/packages/base/components/Notification.tsx+++ b/web/packages/base/components/Notification.tsx@@ -16,115 +16,27 @@ import type {} from "ente-base/components/utils/mui-theme";import { isSxArray } from "ente-base/components/utils/sx";import React from "react";-/**- * Customize the contents of an {@link Notification}.- */export interface NotificationAttributes {- /**- * If set, then the caption is shown first, then the title.- *- * Default is to show the title first, then the caption.- */captionFirst?: boolean;- /**- * The color of the notification.- */color: ButtonProps["color"];- /**- * Optional override to the default InfoIcon shown at the leading edge of- * the notification.- *- * Default: InfoIcon- */startIcon?: React.ReactNode;- /**- * The primary textual content of the notification.- */title: React.ReactNode;- /**- * The secondary textual content of the notification.- *- * It will be ellipsized if it does not fit into a single line.- */caption?: React.ReactNode;- /**- * Callback invoked (if provided) when the user clicks on the notification- * (anywhere except the close button).- *- * The notification is closed when this happens, unless the- * {@link keepOpenOnClick} property is set on the notification instance.- */onClick?: () => void;- /**- * Optional override to the default CloseIcon shown at the trailing edge of- * the notification.- *- * Unlike {@link startIcon} which is not interactable, setting this replaces- * the close button with a icon button showing the given {@link endIcon},- * and on clicking that icon {@link onClick} would be called instead of- * {@link onClose} (which would've been called on clicking the default close- * button in this position).- */endIcon?: React.ReactNode;- /**- * If true, show the default close button after the custom {@link endIcon}.- */showCloseButtonWithEndIcon?: boolean;- /**- * Optional handler when {@link endIcon} is clicked.- *- * If not provided, clicks on the end icon behave the same as clicking the- * notification body.- */onEndIconClick?: () => void;}type NotificationProps = ModalVisibilityProps & {- /**- * Attributes that customize the contents of the notification, and the- * actions that happen on clicking it.- */attributes: NotificationAttributes | undefined;- /**- * If `true`, then the notification is not closed when it is clicked, and- * should be closed by pressing the close icon button it contains.- */keepOpenOnClick?: boolean;- /**- * Horizontal positioning of the notification.- *- * Default: "right".- */horizontal?: "left" | "right";- /**- * Vertical positioning of the notification.- *- * Default: "bottom".- */vertical?: "top" | "bottom";- /**- * Optional time in milliseconds after which the notification closes.- */autoHideDuration?: number;- /**- * sx props to customize the appearance of the underlying MUI- * {@link Snackbar}.- */sx?: SxProps<Theme>;};-/**- * A small notification popup shown on some edge of the screen to notify the- * user of some asynchronous update or error.- *- * In Material UI terms, this is a custom "Snackbar".- *- * A single Notification component can be shared by multiple sources of- * notifications (which means that there can't be multiple of them outstanding- * at the same time from the same source). The source can customize the actual- * contents and appearance of this notification by providing appropriate- * {@link NotificationAttributes}.- */export const Notification: React.FC<NotificationProps> = ({open,onClose,@@ -168,6 +80,7 @@ export const Notification: React.FC<NotificationProps> = ({}};+ // Inner IconButtons render as divs because the notification is a button.return (<Snackbaropen={open}@@ -205,7 +118,7 @@ export const Notification: React.FC<NotificationProps> = ({sx={{gap: 2,alignItems: "center",- // Necessary to get the ellipsizing to work.+ // Bounds the row so descendants can ellipsize.width: "100%",}}>@@ -217,10 +130,8 @@ export const Notification: React.FC<NotificationProps> = ({sx={{flex: 1,gap: 0.5,- // Undo the center alignment done by the button.textAlign: "left",- // This is necessary to trigger the ellipsizing of the- // text in children.+ // Lets the caption shrink and ellipsize.overflow: "hidden",}}>@@ -260,11 +171,7 @@ export const Notification: React.FC<NotificationProps> = ({)}{(!endIcon || showCloseButtonWithEndIcon) && (<IconButton- // Buttons cannot be nested in buttons, so we use a div- // here instead.component="div"- // Inherit the color of the parent button instead of- // using the IconButton defaults.color="inherit"onClick={handleClose}sx={{ bgcolor: "fill.faint" }}diff --git a/web/packages/base/components/OverflowMenu.tsx b/web/packages/base/components/OverflowMenu.tsxindex 9df36745b2..6bd013c837 100644--- a/web/packages/base/components/OverflowMenu.tsx+++ b/web/packages/base/components/OverflowMenu.tsx@@ -19,31 +19,12 @@ const OverflowMenuContext = createContext<OverflowMenuContextT | undefined>();interface OverflowMenuProps {- /**- * An ARIA identifier for the overflow menu when it is displayed.- */ariaID: string;- /**- * The icon for the trigger button.- *- * If not provided, then by default the MoreHoriz icon from MUI is used.- */triggerButtonIcon?: React.ReactNode;- /**- * Optional additional properties for the trigger icon button.- */triggerButtonSxProps?: IconButtonProps["sx"];- /**- * Optional additional sx props for the MUI {@link Paper} that underlies the- * {@link Menu}.- */menuPaperSxProps?: PaperProps["sx"];}-/**- * An overflow menu showing {@link OverflowMenuOptions}, alongwith a button to- * trigger the visibility of the menu.- */export const OverflowMenu: React.FC<React.PropsWithChildren<OverflowMenuProps>> = ({@@ -76,11 +57,7 @@ export const OverflowMenu: React.FC<onClose={() => setAnchorEl(undefined)}slotProps={{paper: { sx: menuPaperSxProps },- list: {- // Disable padding at the top and bottom of the menu list.- disablePadding: true,- "aria-labelledby": ariaID,- },+ list: { disablePadding: true, "aria-labelledby": ariaID },}}anchorOrigin={{ vertical: "bottom", horizontal: "right" }}transformOrigin={{ vertical: "top", horizontal: "right" }}@@ -92,41 +69,15 @@ export const OverflowMenu: React.FC<};interface OverflowMenuOptionProps {- /**- * Called when the menu option is clicked.- */onClick: () => void;- /**- * The color of the text and icons.- *- * Default: "primary".- */color?: "primary" | "critical";- /**- * An optional icon to show at the leading edge of the menu option.- */startIcon?: React.ReactNode;- /**- * An optional icon to show at the trailing edge of the menu option.- */endIcon?: React.ReactNode;- /**- * If true, the menu option will be styled as selected with a hover effect.- */selected?: boolean;- /**- * If true, reduce spacing and sizing for dense menus.- */compact?: boolean;- /**- * If true, the option is shown disabled and cannot be selected.- */disabled?: boolean;}-/**- * Individual options meant to be shown inside an {@link OverflowMenu}.- */export const OverflowMenuOption: React.FC<React.PropsWithChildren<OverflowMenuOptionProps>> = ({@@ -143,11 +94,7 @@ export const OverflowMenuOption: React.FC<const handleClick = () => {onClick();- // We might've already been closed as a result of our containing menu- // getting closed. An example of this is the "Sort by" option in the- // album options overflow menu, where the `onClick` above will result in- // `onClose` being called on our parent menu, so `menuContext` will be- // undefined when we get here.+ // onClick may close the parent and unmount this context first.menuContext?.close();};@@ -162,8 +109,6 @@ export const OverflowMenuOption: React.FC<? theme.vars.palette.text.muted: theme.vars.palette[color].main,- // Reduce the size of the icons a bit to make it fit better with- // the text."& .MuiSvgIcon-root": { fontSize: compact ? "18px" : "20px" },...(selected && {backgroundColor: "rgba(255, 255, 255, 0.08)",@@ -176,9 +121,7 @@ export const OverflowMenuOption: React.FC<sx={{gap: compact ? 1 : 1.5,alignItems: "center",- // Fill our container.width: "100%",- // MUI has responsive padding, use a static value instead.py: compact ? 0.5 : 1,}}>diff --git a/web/packages/base/components/SingleInputForm.tsx b/web/packages/base/components/SingleInputForm.tsxindex de7ebaded4..08bae5e696 100644--- a/web/packages/base/components/SingleInputForm.tsx+++ b/web/packages/base/components/SingleInputForm.tsx@@ -22,65 +22,13 @@ export type SingleInputFormProps = Pick<TextFieldProps,"label" | "placeholder" | "autoComplete" | "autoFocus" | "slotProps"> & {- /** Visual treatment for the form. */variant?: "default" | "v2";- /**- * The type attribute of the HTML input element that will be used.- *- * Default is "text".- *- * In addition to changing the behaviour of the HTML input element, the- * {@link SingleInputForm} component also has special casing for type- * "password", wherein it'll show an adornment at the end of the text field- * allowing the user to show or hide the password.- */inputType?: TextFieldProps["type"];- /**- * The initial value, if any, to prefill in the input.- */initialValue?: string;- /**- * Color of the submit button.- *- * Default: "accent".- */submitButtonColor?: ButtonProps["color"];- /**- * Title for the submit button.- */submitButtonTitle: string;- /**- * Cancellation handler.- *- * This function is called when the user activates the cancel button in the- * form.- *- * If this is not provided, then only a full width submit button will be- * shown in the form (below the input).- */onCancel?: () => void;- /**- * Submission handler. A callback invoked when the submit button is pressed.- *- * During submission, the text input and the submit button are disabled, and- * an indeterminate progress indicator is shown.- *- * If this function rejects then a generic error helper text is shown below- * the text input, and the input (/ buttons) reenabled.- *- * This function is also passed an function that can be used to explicitly- * set the error message that as shown below the text input when a specific- * problem occurs during submission.- *- * @param name The current value of the text input.- *- * @param setFieldError A function that can be called to set the error message- * shown below the text input if submission fails.- *- * Note that if {@link setFieldError} is called, then the {@link onSubmit}- * function should not throw, otherwise the error message shown by- * {@link setFieldError} will get overwritten by the generic error message.- */+ // Do not throw after setFieldError; the catch replaces it with a generic error.onSubmit:| ((name: string, setFieldError: (message: string) => void) => void)| ((@@ -89,20 +37,6 @@ export type SingleInputFormProps = Pick<) => Promise<void>);};-/**- * A TextField and cancel/submit buttons.- *- * A common requirement is taking a single textual input from the user. This is- * a form suitable for that purpose. It contains a single MUI {@link TextField}- * and two accompanying buttons; one to submit, and one to cancel.- *- * Submission is handled as an async function, during which the input is- * disabled and a loading indicator is shown. Errors during submission are shown- * as the helper text associated with the text field.- *- * The input field in the form takes autoFocus automatically on mount. Turn off- * the {@link autoFocus} to disable this behaviour if needed.- */export const SingleInputForm: React.FC<SingleInputFormProps> = ({variant = "default",inputType,@@ -210,12 +144,6 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({</LoadingButton>);- // [Note: Use space as default TextField helperText]- //- // For MUI text fields that use a conditional helperText, e.g. in case of- // errors, use an space as the default helperText in the other cases to- // avoid a layout shift when the helperText is conditionally shown.-return (<form onSubmit={formik.handleSubmit}><TextField@@ -228,6 +156,7 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({margin="normal"disabled={formik.isSubmitting}error={!!formik.errors.value}+ // The space reserves helper-text height before an error appears.helperText={formik.errors.value ?? " "}slotProps={{input:diff --git a/web/packages/base/components/containers.tsx b/web/packages/base/components/containers.tsxindex d2ae57d3ad..fe73d2adfc 100644--- a/web/packages/base/components/containers.tsx+++ b/web/packages/base/components/containers.tsx@@ -1,44 +1,23 @@import { Stack, styled } from "@mui/material";-/**- * A {@link Stack} that takes up at least the height of the entire viewport, and- * centers its children both vertically and horizontally.- */export const Stack100vhCenter = styled(Stack)`min-height: 100vh;justify-content: center;align-items: center;`;-/**- * A flexbox with justify content set to space-between and item alignment set to- * center.- *- * There is also another SpaceBetweenFlex in the old shared package, but that- * one also sets width: 100%. As such, that one should be considered deprecated- * and its uses moved to this one when possible (so that we can then see where- * the width: 100% is essential).- */export const SpacedRow = styled("div")`display: flex;justify-content: space-between;align-items: center;`;-/**- * A flexbox that shows its children after centering them both vertically and- * horizontally.- */export const CenteredRow = styled("div")`display: flex;justify-content: center;align-items: center;`;-/**- * A flexbox that fills the entire flex direction, and shows its children after- * centering them both vertically and horizontally.- */export const CenteredFill = styled("div")`flex: 1;display: flex;@@ -46,18 +25,6 @@ export const CenteredFill = styled("div")`align-items: center;`;-/**- * An empty overlay on top of the nearest relative positioned ancestor.- *- * {@link Overlay} is an an absolute positioned div that fills the entire- * nearest relatively positioned ancestor. It is usually used in tandem with a- * derivate of {@link BaseTile} or {@link BaseTileButton} to show various- * indicators on top of thumbnails; but it can be used in any context where we- * want to overlay (usually) transparent content on top of a component.- *- * For filling much larger areas (e.g. showing a translucent overlay on top of- * the entire screen), use the MUI {@link Backdrop} instead.- */export const Overlay = styled("div")`position: absolute;width: 100%;diff --git a/web/packages/base/components/mui/SidebarDrawer.tsx b/web/packages/base/components/mui/SidebarDrawer.tsxindex b27eea624f..dca29702ac 100644--- a/web/packages/base/components/mui/SidebarDrawer.tsx+++ b/web/packages/base/components/mui/SidebarDrawer.tsx@@ -13,16 +13,6 @@ import { isDesktop } from "ente-base/app";import type { ModalVisibilityProps } from "ente-base/components/utils/modal";import React from "react";-/**- * A MUI {@link Drawer} with a standard set of styling that we use for our left- * and right sidebar panels.- *- * It is width limited to 375px, and always at full width. It also has a default- * padding.- *- * It also does some trickery with a sticky opaque bar to ensure that the- * content scrolls below our inline title bar on desktop.- */export const SidebarDrawer: React.FC<DrawerProps> = ({slotProps,children,@@ -37,7 +27,7 @@ export const SidebarDrawer: React.FC<DrawerProps> = ({maxWidth: "375px",width: "100%",scrollbarWidth: "thin",- // Need to increase specificity to override inherited padding.+ // Extra specificity overrides inherited padding."&&": { padding: 0 },},},@@ -48,15 +38,7 @@ export const SidebarDrawer: React.FC<DrawerProps> = ({</Drawer>);-/**- * When running on desktop, we adds a sticky opaque bar at the top of the- * sidebar with a z-index greater than the expected sidebar contents. This- * ensures that any title bar overlays added by the system (e.g. the traffic- * lights on macOS) have a opaque-ish background and the sidebar contents scroll- * underneath them.- *- * See: [Note: Customize the desktop title bar]- */+// Keep scrolling content behind the desktop titlebar and traffic lights.const AppTitlebarBackdrop = styled("div")(({ theme }) => ({position: "sticky",top: 0,@@ -68,30 +50,15 @@ const AppTitlebarBackdrop = styled("div")(({ theme }) => ({backdropFilter: "blur(12px)",}));-/**- * Common props for a {@link NestedSidebarDrawer} component. In addition to the- * regular modal visibility controls for opening and closing itself, these also- * surface an option to close the entire drawer.- */export type NestedSidebarDrawerVisibilityProps = ModalVisibilityProps & {- /**- * Called when the user wants to close the entire stack of drawers.- *- * Note that this does not automatically imply onClose. Each step in the- * nesting will have to chain their own onCloses to construct a new- * `onRootClose` suitable for passing to its children.- */+ // Each nesting level must chain its own onClose into this callback.onRootClose: () => void;};-/**- * A variant of {@link SidebarDrawer} for second level, nested drawers that are- * shown atop an already visible {@link SidebarDrawer}.- */export const NestedSidebarDrawer: React.FC<NestedSidebarDrawerVisibilityProps & DrawerProps> = ({ onClose, onRootClose, ...rest }) => {- // Intercept backdrop taps and repurpose them to close the entire stack.+ // Backdrop taps close the entire stack.const handleClose: DrawerProps["onClose"] = (_, reason) => {if (reason == "backdropClick") {onClose();@@ -101,22 +68,11 @@ export const NestedSidebarDrawer: React.FC<}};- // MUI doesn't (currently, AFAIK) have support for nested drawers, so we- // emulate that by showing a drawer atop another. To make it fit, we need to- // modify a few knobs.-return (<SidebarDrawer- // Disable the transition (otherwise our nested drawer visibly- // slides in from the wrong direction).+ // A stacked drawer would slide in from the wrong direction.transitionDuration={0}- // Make the backdrop transparent (otherwise we end up with two of- // them - one from the original drawer, and one from this nested- // one).- //- // Note that there is an easy way to hide the backdrop (using the- // `hideBackdrop` attribute), but that takes away our ability to- // intercept backdrop clicks to close it.+ // Keep the backdrop clickable but invisible over the root backdrop.slotProps={{backdrop: { sx: { "&&&": { backgroundColor: "transparent" } } },}}@@ -130,23 +86,12 @@ type SidebarDrawerTitlebarProps = Pick<NestedSidebarDrawerVisibilityProps,"onClose" | "onRootClose"> & {- /** Title for the drawer. */title: string;- /** An optional secondary caption shown below the title. */caption?: string;- /**- * An optional action button shown alongwith the close button at the- * trailing edge of the sidebar.- */actionButton?: React.ReactNode;- /** Whether to show the trailing close button for the root drawer. */showRootCloseButton?: boolean;};-/**- * A bar with a title and back / close buttons, suitable for being used in- * tandem with a {@link NestedSidebarDrawer}.- */export const SidebarDrawerTitlebar: React.FC<SidebarDrawerTitlebarProps> = ({title,caption,@@ -186,15 +131,6 @@ export const SidebarDrawerTitlebar: React.FC<SidebarDrawerTitlebarProps> = ({</Stack>);-/**- * A variant of {@link NestedSidebarDrawer} that additionally shows a title.- *- * {@link NestedSidebarDrawer} is for second level, nested drawers that are- * shown atop an already visible {@link SidebarDrawer}. This component combines- * the {@link NestedSidebarDrawer} with a {@link SidebarDrawerTitlebar} and some- * standard spacing, so that the caller can just provide the content as the- * children.- */export const TitledNestedSidebarDrawer: React.FC<React.PropsWithChildren<NestedSidebarDrawerVisibilityProps &diff --git a/web/packages/base/context.ts b/web/packages/base/context.tsindex ca3ee1fda6..076d7f3967 100644--- a/web/packages/base/context.ts+++ b/web/packages/base/context.ts@@ -3,61 +3,23 @@ import { createContext, useContext } from "react";import { genericErrorDialogAttributes } from "./components/utils/dialog";import log from "./log";-/**- * The type of the context expected to be present in the React tree for all apps- * that use the base package.- *- * It is usually provided by the _app.tsx for the corresponding app.- */export interface BaseContextT {- /**- * Perform the (possibly app specific) logout sequence.- */logout: () => void;- /**- * Show a "mini dialog" with the given attributes.- *- * Mini dialogs (see {@link AttributedMiniDialog}) are meant for simple- * confirmation or notifications. Their appearance and functionality can be- * customized by providing appropriate {@link MiniDialogAttributes}.- */showMiniDialog: (attributes: MiniDialogAttributes) => void;- /**- * Log the given error and show a generic error {@link MiniDialog}.- */onGenericError: (error: unknown) => void;}-/**- * The React {@link Context} of type {@link BaseContextT} available to all React- * components that refer to the base package.- */export const BaseContext = createContext<BaseContextT | undefined>(undefined);-/**- * Utility hook to get the required {@link BaseContextT} that is expected to be- * available to all React components that refer to the base package.- */export const useBaseContext = (): BaseContextT => useContext(BaseContext)!;-/**- * A helper function to create a {@link BaseContext} by deriving derivable- * context values from the minimal subset.- *- * In simpler words, it automatically provides a definition of- * {@link onGenericError} using the given {@link showMiniDialog} prop.- */export const deriveBaseContext = ({logout,showMiniDialog,}: Omit<BaseContextT, "onGenericError">): BaseContextT => {const onGenericError = (e: unknown) => {log.error(e);- // The generic error handler is sometimes called in the context of- // actions that were initiated by a confirmation dialog action handler- // themselves, then we need to let the current one close.- //- // See: [Note: Chained MiniDialogs]+ // Let a dialog action close its dialog before showing the error dialog.setTimeout(() => {showMiniDialog(genericErrorDialogAttributes());}, 0);diff --git a/web/packages/base/file-name.ts b/web/packages/base/file-name.tsindex 4b679d5a24..7b10af7e47 100644--- a/web/packages/base/file-name.ts+++ b/web/packages/base/file-name.ts@@ -1,62 +1,22 @@-/**- * The two parts of a file name - the name itself, and an (optional) extension.- *- * The extension does not include the dot.- */type FileNameComponents = [name: string, extension: string | undefined];-/**- * Split a filename into its components - the name itself, and the extension (if- * any) - returning both. The dot is not included in either.- *- * For example, `foo-bar.png` will be split into ["foo-bar", "png"].- *- * See {@link fileNameFromComponents} for the inverse operation.- */export const nameAndExtension = (fileName: string): FileNameComponents => {const i = fileName.lastIndexOf(".");- // No extensionif (i == -1) return [fileName, undefined];- // A hidden file without an extension, e.g. ".gitignore"if (i == 0) return [fileName, undefined];- // Both components present, just omit the dot.return [fileName.slice(0, i), fileName.slice(i + 1)];};-/**- * If the file name or path has an extension, return a lowercased version of it.- *- * This is handy when comparing the extension to a known set without worrying- * about case sensitivity.- *- * See {@link nameAndExtension} for its more generic sibling.- */export const lowercaseExtension = (fileNameOrPath: string,): string | undefined => {- // We rely on the implementation of nameAndExtension using lastIndexOf to- // allow us to also work on paths.const [, ext] = nameAndExtension(fileNameOrPath);return ext?.toLowerCase();};-/**- * Construct a file name from its components (name and extension).- *- * Inverse of {@link nameAndExtension}.- */export const fileNameFromComponents = (components: FileNameComponents) =>components.filter((x) => !!x).join(".");-/**- * Return the file name portion from the given {@link path}.- *- * This tries to emulate the UNIX `basename` command. In particular, any- * trailing slashes on the path are trimmed, so this function can be used to get- * the name of the directory too.- *- * The path is assumed to use POSIX separators ("/").- */export const basename = (path: string) => {const pathComponents = path.split("/");for (let i = pathComponents.length - 1; i >= 0; i--) {@@ -66,40 +26,13 @@ export const basename = (path: string) => {return path;};-/**- * Return the directory portion from the given {@link path}.- *- * This tries to emulate the UNIX `dirname` command. In particular, any trailing- * slashes on the path are trimmed, so this function can be used to get the path- * leading up to a directory too.- *- * The path is assumed to use POSIX separators ("/").- */export const dirname = (path: string) => {const pathComponents = path.split("/");while (pathComponents.pop() == "") {- /* no-op */+ // Drain trailing separators.}return pathComponents.join("/");};-/**- * Return a new path by joining two path components using the POSIX path- * separator ("/").- *- * This is usually a trivial `p1/p2`, however it also handles the case where p1- * already ends with a trailing slash. This can happen even if p1 is obtained- * from a place which guarantees that only directory paths will be returned,- * because p1 can be the path to a root folder (e.g. "/" on Linux, or "C:/" on- * Windows), and the trivial join would then result in double slashes.- *- * @param p1 A path component that is expected to be using POSIX path- * separators.- *- * @param p2 A path component that is expected to be using POSIX path- * separators.- *- * @returns A path by joining p1 and p2 with a POSIX path separator if needed.- */export const joinPath = (p1: string, p2: string) =>p1.endsWith("/") ? p1 + p2 : `${p1}/${p2}`;diff --git a/web/packages/base/i18n-date.ts b/web/packages/base/i18n-date.tsindex 8b70cb4d1b..773f70b813 100644--- a/web/packages/base/i18n-date.ts+++ b/web/packages/base/i18n-date.ts@@ -1,11 +1,6 @@-/**- * @file Various date formatters.- *- * Note that we rely on the current behaviour of a full reload on changing the- * language. See: [Note: Changing locale causes a full reload].- */import i18n, { t } from "i18next";+// These module-level formatters rely on locale changes doing a full reload.const _dateFormat = new Intl.DateTimeFormat(i18n.language, {weekday: "short",day: "numeric",@@ -33,16 +28,6 @@ interface FormattedDateOptions {omitWeekdayWhenYearIncluded?: boolean;}-/**- * Return a locale aware formatted date from the given {@link Date}.- *- * The behaviour depends upon whether the given {@link date} falls within the- * current calendar year.- *- * - For dates in the current year, year is omitted, e.g, "Fri, 21 Feb".- *- * - Otherwise, the year is included, e.g., "Fri, 21 Feb 2025".- */export const formattedDate = (date: Date, options?: FormattedDateOptions) =>(isSameYear(date)? _dateWithoutYearFormat@@ -54,33 +39,8 @@ export const formattedDate = (date: Date, options?: FormattedDateOptions) =>const isSameYear = (date: Date) =>new Date().getFullYear() === date.getFullYear();-/**- * Return a locale aware formatted time from the given {@link Date}.- *- * Example: "11:51 AM"- */export const formattedTime = (date: Date) => _timeFormat.format(date);-/**- * Return a locale aware formatted date and time from the given {@link Date},- * using the year omission behavior as documented in {@link formattedDate}.- *- * Example:- * - If within year: "Fri, 21 Feb at 11:51 AM".- * - Otherwise: "Fri, 21 Feb 2025 at 11:51 AM"- *- * @param dateOrEpochMicroseconds A JavaScript Date or a numeric epoch- * microseconds value.- *- * [Note: Remote timestamps are epoch microseconds]- *- * Remote talks in terms of epoch microseconds, while JavaScript dates are- * underlain by epoch milliseconds.- *- * As a convenience, this function can be either be directly passed a JavaScript- * date, or it can be given the raw epoch microseconds value and it'll convert- * internally.- */export const formattedDateTime = (dateOrEpochMicroseconds: Date | number,options?: FormattedDateOptions,@@ -94,16 +54,6 @@ const toDate = (dm: Date | number) =>let _relativeTimeFormat: Intl.RelativeTimeFormat | undefined;-/**- * Return a locale aware relative version of the given date.- *- * Example: "in 23 days"- *- * @param dateOrEpochMicroseconds A JavaScript Date or a numeric epoch- * microseconds value.- *- * See: [Note: Remote timestamps are epoch microseconds]- */export const formattedDateRelative = (dateOrEpochMicroseconds: Date | number,) => {@@ -121,7 +71,6 @@ export const formattedDateRelative = (// Math.abs accounts for both past and future scenarios.const elapsed = Math.abs(date.getTime() - Date.now());- // Lazily created, then cached, instance of RelativeTimeFormat.const relativeTimeFormat = (_relativeTimeFormat ??=new Intl.RelativeTimeFormat(i18n.language, {localeMatcher: "best fit",diff --git a/web/packages/base/kv.ts b/web/packages/base/kv.tsindex 3a05e6ffb1..c868769268 100644--- a/web/packages/base/kv.ts+++ b/web/packages/base/kv.ts@@ -1,74 +1,12 @@import { deleteDB, openDB, type DBSchema } from "idb";import log from "./log";-/**- * Key value store schema.- *- * [Note: KV DB]- *- * The use IndexedDB to store arbitrary key-value pairs. The functional- * motivation is to allow these to also be accessed from web workers (local- * storage is limited to the main thread).- *- * The "kv" database consists of one object store, "kv". Keys are strings.- * Values can be arbitrary JSON objects.- *- * [Note: Avoiding IndexedDB flakiness by avoiding indexes]- *- * Sporadically, rarely, but definitely, we ran into issues with IndexedDB- * losing data. e.g. saves from the ML web worker would complete successfully,- * but the saves would not reflect on the main thread, and that data would just- * get lost when the app would refresh.- *- * I'm not sure where the problem lay - in our own code, in the library that we- * are using (idb), within IndexedDB itself, or in Electron/Chrome's- * implementation of it (these cases all came up in the context of the ML code- * that only ran in our desktop app).- *- * A piece of advice I randomly ran across on the internet was to keep it very- * simple, and avoid all indexes. I also recalled that we did not see such- * issues with our older (but now unmaintained) library, localforage, which also- * doesn't use any indexes, and just has a flat single-store schema.- *- * So this may be superstition, but for now the approach I'm taking is to use- * IndexedDB as a key value store only.- */+// Keep this as one store without indexes.+// Indexed variants had rare cross-context data loss.interface KVDBSchema extends DBSchema {- kv: {- key: string;- /**- * Typescript doesn't have a native JSON type, so this needs to be- * unknown- */- value: unknown;- };+ kv: { key: string; value: unknown };}-/**- * A lazily-created, cached promise for KV DB.- *- * [Note: Caching IDB instances in separate execution contexts]- *- * We open the database once (on access), and thereafter save and reuse this- * promise each time something wants to connect to it.- *- * This promise can subsequently get cleared if we need to relinquish our- * connection (e.g. if another client wants to open the face DB with a newer- * version of the schema).- *- * It can also get cleared on logout. In all such cases, it'll automatically get- * recreated on next access.- *- * Note that this is module specific state, so each execution context (main- * thread, web worker) that calls the functions in this module will its own- * promise to the database. To ensure that all connections get torn down- * correctly, we need to perform the following logout sequence:- *- * 1. Terminate all the workers which might have one of the instances in memory.- * This closes their connections.- *- * 2. Delete the database on the main thread.- */let _kvDB: ReturnType<typeof openKVDB> | undefined;const openKVDB = async () => {@@ -97,16 +35,9 @@ const openKVDB = async () => {return db;};-/**- * @returns a lazily created, cached connection to the KV DB.- */const kvDB = () => (_kvDB ??= openKVDB());-/**- * Clear all key values stored in the KV db.- *- * This is meant to be called during logout in the main thread.- */+// Terminate workers first; each execution context caches its own connection.export const clearKVDB = async () => {try {if (_kvDB) (await _kvDB).close();@@ -124,15 +55,6 @@ export const clearKVDB = async () => {});};-/**- * Return the string value stored corresponding to {@link key}, or `undefined`- * if there is no such entry.- *- * Typescript doesn't have a native JSON type, so the return value is type as an- * `unknown`. For primitive types, you can avoid casting by using the- * {@link getKVS} (string), {@link getKVN} (number) or {@link getKVB} (boolean)- * methods that do an additional runtime check of the type.- */export const getKV = async (key: string) => {const db = await kvDB();return db.get("kv", key);@@ -147,39 +69,24 @@ const _getKV = async <T extends string | number | boolean>(if (v === undefined) return undefined;if (typeof v != type)throw new Error(- // This is just an error message, it is fine if stringification- // produces nothing useful always, it might too in some cases.- //+ // Best-effort diagnostic only.// eslint-disable-next-line @typescript-eslint/no-base-to-string`Expected the value corresponding to key ${key} to be a ${type}, but instead got ${String(v)}`,);return v as T;};-/** String variant of {@link getKV}. */export const getKVS = async (key: string) => _getKV<string>(key, "string");-/** Numeric variant of {@link getKV}. */export const getKVN = async (key: string) => _getKV<number>(key, "number");-/** Boolean variant of {@link getKV} */export const getKVB = async (key: string) => _getKV<boolean>(key, "boolean");-/**- * Save the given {@link value} corresponding to {@link key}, overwriting any- * existing value.- *- * @param value Any arbitrary JSON object. Typescript doesn't have a native JSON- * type, so this is typed as a unknown- */export const setKV = async (key: string, value: unknown) => {const db = await kvDB();await db.put("kv", value, key);};-/**- * Remove the entry corresponding to {@link key} (if any).- */export const removeKV = async (key: string) => {const db = await kvDB();await db.delete("kv", key);diff --git a/web/packages/base/log-web.ts b/web/packages/base/log-web.tsindex eec7abc38c..c8ee8552c3 100644--- a/web/packages/base/log-web.ts+++ b/web/packages/base/log-web.ts@@ -2,16 +2,8 @@ import { buildEnvGitSHA, isDevBuild } from "ente-base/env";import log from "ente-base/log";import { appName, appNames } from "./app";-/**- * Log a standard startup banner.- *- * This helps us identify app starts and other environment details in the logs.- *- * @param userID The uid for the currently logged in user, if any.- */export const logStartupBanner = (userID?: number) => {- // Log a warning if appName isn't what it claims to be. See the- // documentation of `appName` for why this is needed.+ // appName is an unchecked build-time value.if (!appNames.includes(appName)) {log.warn(`App name "${appName}" is not one of the known app names: ${JSON.stringify(appNames)}`,@@ -23,20 +15,9 @@ export const logStartupBanner = (userID?: number) => {log.info(`Starting ente-${appName}-web ${buildID}uid ${userID ?? 0}`);};-/**- * Attach handlers to log any unhandled exceptions and promise rejections.- *- * @param attach If true, attach handlers, and if false, remove them. This- * allows us to use this in a React hook that cleans up after itself.- */export const logUnhandledErrorsAndRejections = (attach: boolean) => {const handleError = (event: ErrorEvent) => {- // [Note: Spurious media chrome resize observer errors]- //- // When attaching media chrome controls to the DOM, we get an (AFAICT)- // spurious error in the log. Ignore it. FWIW, the media control tests- // themselves do the same.- // https://github.com/muxinc/elements/blob/f602519f544509f15add8fcc8cbbf7379843dcd3/packages/mux-player/test/player.test.js#L6-L12C5+ // Media Chrome triggers this benign ResizeObserver error.if (event.message =="ResizeObserver loop completed with undelivered notifications."@@ -63,18 +44,7 @@ export const logUnhandledErrorsAndRejections = (attach: boolean) => {}};-/**- * Attach handlers to log any unhandled exceptions and promise rejections in web- * workers.- *- * This is a variant of {@link logUnhandledErrorsAndRejections} that works in- * web workers. It should be called at the top level of the main worker script.- *- * Note: When I tested this, attaching the onerror handler to the worker outside- * the worker (e.g. when creating it in comlink-worker.ts) worked, but attaching- * the "unhandledrejection" event there did not work. Attaching them to `self`- * (the {@link WorkerGlobal}) worked.- */+// Worker promise rejections are only observed when attached inside the worker.export const logUnhandledErrorsAndRejectionsInWorker = () => {const handleError = (event: ErrorEvent) => {log.error("Unhandled error", event.error);@@ -95,14 +65,6 @@ interface LogEntry {const lsKey = "logs";-/**- * Record {@link message} in a persistent log storage.- *- * These strings, alongwith associated timestamps, get added to a small ring- * buffer, whose contents can be later be retrieved by using {@link savedLogs}.- *- * This ring buffer is persisted in the browser's local storage.- */export const logToDisk = (message: string) => {const maxCount = 1000;const log: LogEntry = { logLine: message, timestamp: Date.now() };@@ -132,11 +94,6 @@ const logEntries = (): unknown[] => {return o.logs;};-/**- * Return a string containing all recently saved log messages.- *- * @see {@link persistLog}.- */export const savedLogs = () => logEntries().map(formatEntry).join("\n");const formatEntry = (e: unknown) => {diff --git a/web/packages/base/log.ts b/web/packages/base/log.tsindex cc4de0068b..ded3fe283a 100644--- a/web/packages/base/log.ts+++ b/web/packages/base/log.ts@@ -3,25 +3,10 @@ import { isDevBuild } from "./env";import { logToDisk as webLogToDisk } from "./log-web";import { workerBridge } from "./worker/worker-bridge";-/**- * Whether logs go to disk or are always emitted to the console.- */let shouldLogToDisk = true;-/**- * By default, logs get saved into a ring buffer in the browser's local storage.- * However, in some contexts, e.g. when we're running as the cast app, there is- * no mechanism for the user to retrieve these logs. So this function exists as- * a way to disable the on disk logging and always use the console.- */export const disableDiskLogs = () => (shouldLogToDisk = false);-/**- * Write a {@link message} to the on-disk log.- *- * This is used by the renderer process (via the contextBridge) to add entries- * in the log that is saved on disk.- */export const logToDisk = (message: string) => {const electron = globalThis.electron;if (electron) electron.logToDisk(message);@@ -45,20 +30,16 @@ const messageWithError = (message: string, e?: unknown) => {let es: string;if (e instanceof Error) {- // In practice, we expect ourselves to be called with Error objects, so- // this is the happy path so to say.es = `${e.name}: ${e.message}`;const st = e.stack;if (st) {- // On V8 (as of 2024), the stack trace begins by repeating the error's- // name and message, trim that off.- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack+ // V8 stacks already start with "Name: message".es = st.startsWith(es)- ? es.concat(st.slice(es.length)) /* retain the '\n' */+ ? es.concat(st.slice(es.length)): [es, st].join("\n");}} else {- // For the rest rare cases, use the default string serialization of e.+ // Best-effort for arbitrary thrown values.// eslint-disable-next-line @typescript-eslint/no-base-to-stringes = String(e);}@@ -93,82 +74,20 @@ const logInfo = (...params: unknown[]) => {const logDebug = (param: () => unknown) => {if (isDevBuild) {const p = param();- // Transform- // log.debug(() => ["tag", {x: y}])- // =>- // console.log("[debug] tag", {x: y})if (Array.isArray(p)) {- // tseslint is not happy with us for destructuring any, but this is- // non-production dev build only code, so silence it and go ahead.// eslint-disable-next-line @typescript-eslint/no-unsafe-assignmentconst [tag, ...rest] = p;// eslint-disable-next-line @typescript-eslint/no-unsafe-argumentconsole.log(`[debug] ${tag}`, ...rest);} else {- /* Let console.log serialize it */console.log("[debug]", p);}}};-/**- * Ente's logger.- *- * This is an object that provides functions to log at the corresponding levels:- * error, warn, info or debug.- *- * Whenever we need to save a log message to disk,- *- * - When running under electron these messages are saved to the log maintained- * by the electron app we're running under.- *- * - Otherwise such messages are written to a ring buffer in local storage.- */export default {- /**- * Log an error message with an optional associated error object.- *- * {@link e} is generally expected to be an `instanceof Error` but it can be- * any arbitrary object that we obtain, say, when in a try-catch handler (in- * JavaScript any arbitrary value can be thrown).- *- * If only one argument is specified, and it is not a string, then it is- * taken as the error to be printed, paired with a generic message.- *- * The log is written to disk and printed to the browser console.- */error: logError,- /**- * Sibling of {@link error}, with the same parameters and behaviour, except- * it gets prefixed with a warning instead of an error tag.- */warn: logWarn,- /**- * Log a message.- *- * This is meant as a replacement of {@link console.log}, and takes an- * arbitrary number of arbitrary parameters that it then serializes.- *- * The log is written to disk. However, if logging to disk is disabled by- * using {@link disableDiskLogs}, then the log is printed to the console.- *- * In development builds, the log is always printed to the browser console.- */info: logInfo,- /**- * Log a debug message.- *- * To avoid running unnecessary code in release builds, this takes a- * function to call to get the log message instead of directly taking the- * message. The provided function will only be called in development builds.- *- * The function can return an arbitrary value which is serialized before- * being logged. As a special case, arrays are spread, which allows one to- * write `log.debug(() => ["tag", {x: y}])` and have that be printed as if- * it were `console.log("[debug] tag", {x: y})`.- *- * This log is NOT written to disk. It is printed to the browser console,- * but only in development builds.- */debug: logDebug,};diff --git a/web/packages/base/origins.ts b/web/packages/base/origins.tsindex 1caae8f133..f6028c57c0 100644--- a/web/packages/base/origins.ts+++ b/web/packages/base/origins.ts@@ -1,34 +1,10 @@import { getKVS } from "ente-base/kv";import { buildEnvCustomAPIEndpoint } from "./env";-/**- * Return the origin (scheme, host, port triple) that should be used for making- * API requests to museum.- *- * This defaults "https://api.ente.com", Ente's production API servers, but can- * be overridden when self hosting or developing (see {@link customAPIOrigin}).- */export const apiOrigin = async () =>(await customAPIOrigin()) ?? "https://api.ente.com";-/**- * A convenience function to construct an endpoint in a one-liner.- *- * This avoids us having to create a temporary variable or otherwise complicate- * the call sites since async functions cannot be used inside template literals.- *- * @param path The URL path usually, but can be anything that needs to be- * suffixed to the origin. It must begin with a "/".- *- * @param queryParams An optional object containing query params. This is- * appended to the generated URL after funneling it through- * {@link URLSearchParams}. Each value can be a `string` or `number` or- * `boolean` - all of which are converted to `string`s by using `toString`- *- * > The boolean stringification yields "true" or "false".- *- * @returns path prefixed by {@link apiOrigin}.- */+// path must begin with "/".export const apiURL = async (path: string,queryParams?: Record<string, string | number | boolean>,@@ -44,44 +20,17 @@ export const apiURL = async (return url;};-/**- * Return the overridden API origin, if one is defined by either (in priority- * order):- *- * - Setting the custom server on the landing page (See: [Note: Configuring- * custom server]); or by- *- * - Setting the `NEXT_PUBLIC_ENTE_ENDPOINT` environment variable.- *- * Otherwise return undefined.- */export const customAPIOrigin = async () =>(await getKVS("apiOrigin")) ?? buildEnvCustomAPIEndpoint ?? undefined;-/**- * A static build time constant that is `true` if the API origin has been- * customized through the environment.- */+// This ignores the KV custom server and only reflects the build-time override.export const isCustomAPIOrigin = !!buildEnvCustomAPIEndpoint;-/**- * A convenience wrapper over {@link customAPIOrigin} that returns the only the- * host part of the custom origin (if any).- *- * This is useful in places where we indicate the custom origin in the UI.- */export const customAPIHost = async () => {const origin = await customAPIOrigin();return origin ? new URL(origin).host : undefined;};-/**- * Return the origin that should be used for uploading files.- *- * This defaults to `https://uploader.ente.com`, serviced by a Cloudflare worker- * (see infra/workers/uploader). But if a {@link customAPIOrigin} is set then- * this value is set to the {@link customAPIOrigin} itself, effectively- * bypassing the Cloudflare worker for non-Ente deployments.- */+// Custom deployments bypass Ente's uploader worker.export const uploaderOrigin = async () =>(await customAPIOrigin()) ?? "https://uploader.ente.com";diff --git a/web/packages/base/worker/comlink-worker.ts b/web/packages/base/worker/comlink-worker.tsindex 44169c2e43..23e2ae24ef 100644--- a/web/packages/base/worker/comlink-worker.ts+++ b/web/packages/base/worker/comlink-worker.ts@@ -2,34 +2,11 @@ import { expose, wrap, type Remote } from "comlink";import { ensureElectron } from "ente-base/electron";import log, { logToDisk } from "ente-base/log";-/**- * A minimal wrapper for a web {@link Worker}, proxying a class of type T.- *- * `comlink` is a library that simplifies working with web workers by- * transparently proxying objects across the boundary instead of us needing to- * work directly with the raw postMessage interface.- *- * This class is a thin wrapper over a common usage pattern of comlink. It takes- * a web worker ({@link Worker}) that is expected to have {@link expose}-ed a- * class of type T. It then makes available the main thread handle to this class- * as the {@link remote} property.- *- * It also exposes an object of type {@link WorkerBridge} _to_ the code running- * inside the web worker.- *- * It all gets a bit confusing sometimes, so here is a legend of the parties- * involved:- *- * - ComlinkWorker (wraps the web worker)- * - Web `Worker` (exposes class T)- * - ComlinkWorker.remote (the exposed class T running inside the web worker)- */+// The worker exposes T through remote.+// This thread exposes workerBridge back through the same worker endpoint.export class ComlinkWorker<T extends new () => InstanceType<T>> {- /** The class (T) exposed by the web worker */public remote: Promise<Remote<InstanceType<T>>>;- /** The web worker */public worker: Worker;- /** An arbitrary name associated with this ComlinkWorker for debugging. */private name: string;constructor(name: string, worker: Worker) {@@ -53,20 +30,8 @@ export class ComlinkWorker<T extends new () => InstanceType<T>> {}}-/**- * A set of utility functions that we expose to all web workers that we create.- *- * Inside the worker's code, this can be accessed by using the sibling- * `workerBridge` object after importing it from `worker-bridge.ts`.- *- * Not all workers need access to all these functions, and this can indeed be- * done in a more fine-grained, per-worker, manner if needed. For now, since it- * is just a couple, we just inject them all to all workers.- */const workerBridge = {- // Needed by all workers (likely, but not necessarily).logToDisk,- // Needed by ML worker.convertToJPEG: (imageData: Uint8Array) =>ensureElectron().convertToJPEG(imageData),};diff --git a/web/packages/gallery/components/DownloadStatusNotifications.tsx b/web/packages/gallery/components/DownloadStatusNotifications.tsxindex e4328fc3f1..109f8b171a 100644--- a/web/packages/gallery/components/DownloadStatusNotifications.tsx+++ b/web/packages/gallery/components/DownloadStatusNotifications.tsx@@ -24,57 +24,24 @@ import {import { t } from "i18next";import { useState } from "react";-/** Maximum characters for album name before truncation */const MAX_ALBUM_NAME_LENGTH = 25;const SINGLE_FILE_SUCCESS_AUTO_CLOSE_DELAY_MS = 3000;-/** Truncate album name with ellipsis if it exceeds max length */const truncateAlbumName = (name: string): string => {if (name.length <= MAX_ALBUM_NAME_LENGTH) return name;return name.slice(0, MAX_ALBUM_NAME_LENGTH) + "...";};export interface DownloadStatusNotificationsProps {- /**- * A list of user-initiated downloads for which a status should be shown.- *- * An entry is added to this list when the user initiates the download, and- * remains here until the user explicitly closes the corresponding- * {@link Notification} component that was showing the save group's status.- */saveGroups: SaveGroup[];- /**- * Called when the user closes the download status associated with the given- * {@link saveGroup}.- */onRemoveSaveGroup: (saveGroup: SaveGroup) => void;- /**- * Called when the collection summary with the given {@link collectionID}- * should be shown. If {@link isHiddenCollectionSummary} is set, then any- * reauthentication as appropriate before switching to the hidden section of- * the app is performed first.- *- * and hidden attribute should be shown.- *- * See the documentation of {@link SaveGroup}'s- * {@link collectionSummaryID} property for why we don't store the- * collection summary itself.- */onShowCollectionSummary?: (collectionSummaryID: number | undefined,isHiddenCollectionSummary: boolean | undefined,) => void;- /**- * If true, make each notification full width on mobile phones (MUI "sm"- * and below). Tablet and desktop widths remain unchanged.- */fullWidthOnMobile?: boolean;}-/**- * A component that shows a list of notifications, one each for an active- * user-initiated download.- */export const DownloadStatusNotifications: React.FC<DownloadStatusNotificationsProps> = ({@@ -149,7 +116,6 @@ export const DownloadStatusNotifications: React.FC<const shouldAutoClose =group.total === 1 && isComplete && !hasErrors;- // Determine if this is a ZIP download (web with multiple files or live photo)const isZipDownload = !group.downloadDirPath && group.total > 1;const shouldShowZipPart =isZipDownload &&@@ -157,10 +123,8 @@ export const DownloadStatusNotifications: React.FC<const isDesktopOrSingleFile =!!group.downloadDirPath || group.total === 1;- // Build the status text for the captionlet statusText: React.ReactNode;if (hasErrors) {- // Show specific error message based on failure reasonif (group.failureReason === "network_offline") {statusText = t("download_failed_network_offline");} else if (group.failureReason === "file_error") {@@ -188,7 +152,6 @@ export const DownloadStatusNotifications: React.FC<statusText = t("downloading");}- // Build caption: "Status β’ X / Y files"const completedCount = group.success + group.failed;const progress =group.total === 1@@ -218,7 +181,6 @@ export const DownloadStatusNotifications: React.FC<</Box>);- // Determine the start icon based on statelet startIcon: React.ReactNode;if (hasErrors) {startIcon = <ErrorOutlinedIcon />;@@ -229,10 +191,8 @@ export const DownloadStatusNotifications: React.FC<</GlowingIconWrapper>);} else if (isZipDownload && !group.isDownloadingZip) {- // Preparing state - use loading iconstartIcon = <SpinningIcon />;} else {- // Downloading statestartIcon = (<DroppingIconWrapper><HugeiconsIcon icon={Download01Icon} size={28} />@@ -240,7 +200,6 @@ export const DownloadStatusNotifications: React.FC<);}- // Title is always the album name (truncated)const filesCountTitle = t("files_count", {count: group.total,});@@ -447,44 +406,37 @@ const StopDownloadPrimaryButton = styled(Button)(({ theme }) => ({"&:hover": { backgroundColor: theme.vars.palette.critical.dark },}));-/** CSS keyframes for spinning animation */const spinAnimation = keyframes`from { transform: rotate(0deg); }to { transform: rotate(360deg); }`;-/** CSS keyframes for drop from top animation */const dropAnimation = keyframes`0% { transform: translateY(-100%); opacity: 0.15; }50% { transform: translateY(10%); opacity: 0.6; }100% { transform: translateY(0); opacity: 1; }`;-/** CSS keyframes for green glow animation */const glowAnimation = keyframes`0% { color: var(--mui-palette-fixed-success); }100% { color: inherit; }`;-/** CSS keyframes for fade in animation */const fadeInAnimation = keyframes`0% { opacity: 0; }100% { opacity: 1; }`;-/** Drop animation icon wrapper */const DroppingIconWrapper = styled("span")`display: inline-flex;animation: ${dropAnimation} 0.8s ease-out forwards;`;-/** Glowing icon wrapper for success state */const GlowingIconWrapper = styled("span")`display: inline-flex;animation: ${glowAnimation} 2s ease-out forwards;`;-/** Spinning loading icon wrapper */const SpinningIconWrapper = styled("span")`display: inline-flex;animation:@@ -492,7 +444,6 @@ const SpinningIconWrapper = styled("span")`${spinAnimation} 3s linear infinite;`;-/** Spinning loading icon */const SpinningIcon: React.FC = () => (<SpinningIconWrapper><HugeiconsIcon icon={Loading03Icon} size={28} />diff --git a/web/packages/gallery/components/utils/use-file-input.ts b/web/packages/gallery/components/utils/use-file-input.tsindex a137b34ad3..1c210bb8be 100644--- a/web/packages/gallery/components/utils/use-file-input.ts+++ b/web/packages/gallery/components/utils/use-file-input.ts@@ -1,61 +1,17 @@import { useCallback, useEffect, useRef } from "react";interface UseFileInputParams {- /**- * If `true`, the file open dialog will ask the user to select directories.- * Otherwise it'll ask the user to select files (default).- */directory?: boolean;- /**- * If specified, it'll restrict the type of files that the user can select- * by setting the "accept" attribute of the underlying HTML input element we- * use to surface the file selector dialog. For value of accept can be an- * extension or a MIME type (See- * https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept).- */accept?: string;- /**- * A callback that is invoked when the user selects files.- *- * It will be passed the list of {@link File}s that the user selected.- *- * This will be a list even if the user selected directories - in that case,- * it will be the recursive list of files within this directory.- *- * If the user selected no items, then {@link onCancel} will be invoked.- */onSelect: (selectedFiles: File[]) => void;- /**- * A callback that is invoked when the user cancels on the file / directory- * dialog.- */onCancel: () => void;}interface UseFileInputResult {- /**- * A function to call to get the properties that should be passed to a dummy- * `input` element that needs to be created to anchor the select file- * dialog. This input HTML element is not going to be visible, but it needs- * to be part of the DOM for {@link openSelector} to have effect.- */getInputProps: () => React.HTMLAttributes<HTMLInputElement>;- /**- * A function that can be called to open the select file / directory dialog.- */openSelector: () => void;}-/**- * Wrap a open file selector into an easy to use package.- *- * Returns a {@link UseFileInputResult} which contains a function to get the- * props for an input element, a function to open the file selector, and the- * list of selected files.- *- * See the documentation of {@link UseFileInputParams} and- * {@link UseFileInputResult} for more details.- */export const useFileInput = ({directory,accept,@@ -65,13 +21,9 @@ export const useFileInput = ({const inputRef = useRef<HTMLInputElement | null>(null);useEffect(() => {- // React (as of 19) doesn't support attaching the onCancel event handler- // via props, so do it using its ref.- //- // https://github.com/facebook/react/issues/27858+ // React 19 does not attach input cancellation through props.inputRef.current!.addEventListener("cancel", onCancel);return () => {- // Use optional chaining to avoid spurious errors during HMR.inputRef.current?.removeEventListener("cancel", onCancel);};}, [onCancel]);@@ -92,17 +44,7 @@ export const useFileInput = ({}};- // [Note: webkitRelativePath]- //- // If the webkitdirectory attribute of an <input> HTML element is set then- // the File objects that we get will have `webkitRelativePath` property- // containing the relative path to the selected directory.- //- // https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory- //- // These paths use the POSIX path separator ("/").- // https://stackoverflow.com/questions/62806233/when-using-webkitrelativepath-is-the-path-separator-operating-system-specific- //+ // Directory files expose POSIX paths through webkitRelativePath.const directoryOpts = directory? { directory: "", webkitdirectory: "" }: {};diff --git a/web/packages/gallery/components/viewer/CommentsSidebar.tsx b/web/packages/gallery/components/viewer/CommentsSidebar.tsxindex 7e5b3c795f..176622bca8 100644--- a/web/packages/gallery/components/viewer/CommentsSidebar.tsx+++ b/web/packages/gallery/components/viewer/CommentsSidebar.tsx@@ -42,10 +42,6 @@ import React, {useState,} from "react";-// =============================================================================-// Icons-// =============================================================================-const SendIcon: React.FC = () => (<svgwidth="18"@@ -150,11 +146,6 @@ const PersonIcon: React.FC = () => (</svg>);-// =============================================================================-// Types-// =============================================================================--/** Collection info for the dropdown. */interface CollectionInfo {id: number;name: string;@@ -162,12 +153,7 @@ interface CollectionInfo {coverFile?: EnteFile;}-// =============================================================================-// Utility Functions-// =============================================================================-const formatTimeAgo = (timestampMicros: number): string => {- // Server timestamps are in microseconds, convert to millisecondsconst timestampMs = Math.floor(timestampMicros / 1000);const now = Date.now();const diff = now - timestampMs;@@ -179,7 +165,6 @@ const formatTimeAgo = (timestampMicros: number): string => {const days = Math.floor(hours / 24);if (days < 7) return t("days_ago", { count: days });- // For 7+ days, show actual date using locale-aware formattingconst date = new Date(timestampMs);const currentYear = new Date(now).getFullYear();const locale = i18n.language;@@ -204,10 +189,6 @@ const getParentComment = (return comments.find((c) => c.id === parentID);};-/**- * Truncates comment text to first 100 characters of the first line.- * Adds "..." if multiline or if first line exceeds 100 chars.- */const truncateCommentText = (text: string): string => {const lines = text.split("\n");const firstLine = lines[0] ?? text;@@ -218,26 +199,17 @@ const truncateCommentText = (text: string): string => {return isMultiline ? firstLine + "..." : firstLine;};-// =============================================================================-// Shared Comment Components-// =============================================================================-interface CommentHeaderProps {userName: string;timestamp: number;avatarSize?: number;isMaskedEmail?: boolean;- /** Key used for computing avatar color (e.g., anonUserID for anonymous users). */avatarColorKey?: string;userID?: number;email?: string;useContactDisplay?: boolean;}-/**- * Header component showing avatar, username, and timestamp.- * Used consistently for both root comments and replies.- */const CommentHeader: React.FC<CommentHeaderProps> = ({userName,timestamp,@@ -294,9 +266,6 @@ interface QuotedReplyProps {currentAnonUserID?: string;}-/**- * Shows the quoted parent comment inside a reply bubble.- */const QuotedReply: React.FC<QuotedReplyProps> = ({parentComment,isOwn,@@ -317,9 +286,7 @@ const QuotedReply: React.FC<QuotedReplyProps> = ({email: shouldResolveParent ? parentEmail : undefined,});- // Get the author nameconst getAuthorName = (): string => {- // Check if this is the current user (logged in or anonymous)if (parentComment.userID === currentUserID) {return t("you");}@@ -330,7 +297,6 @@ const QuotedReply: React.FC<QuotedReplyProps> = ({return t("you");}- // For anonymous users, look up in anonUserNamesif (parentComment.anonUserID) {return (anonUserNames?.get(parentComment.anonUserID) ??@@ -338,7 +304,6 @@ const QuotedReply: React.FC<QuotedReplyProps> = ({);}- // For registered users, look up emailreturn shouldResolveParent? resolvedParent.primaryLabel || parentEmail || t("user"): (parentEmail ?? t("user"));@@ -391,79 +356,26 @@ const QuotedReply: React.FC<QuotedReplyProps> = ({);};-// =============================================================================-// Main Component-// =============================================================================-export interface CommentsSidebarProps extends ModalVisibilityProps {- /**- * The file whose comments are being displayed.- */file?: EnteFile;- /**- * The currently active collection ID (when viewing from within a collection).- */activeCollectionID?: number;- /**- * A mapping from file IDs to the IDs of collections they belong to.- */fileNormalCollectionIDs?: Map<number, number[]>;- /**- * Collection summaries indexed by their IDs.- */collectionSummaries?: CollectionSummaries;- /**- * The current user's ID.- */currentUserID?: number;- /**- * Pre-fetched comments by collection ID.- */prefetchedComments?: Map<number, Comment[]>;- /**- * Pre-fetched reactions by collection ID (includes both file and comment reactions).- */prefetchedReactions?: Map<number, UnifiedReaction[]>;- /**- * Pre-fetched user ID to email mapping.- */prefetchedUserIDToEmail?: Map<number, string>;- /**- * Called when a comment is successfully added. The parent should update its- * comments state to include this new comment.- */onCommentAdded?: (comment: Comment) => void;- /**- * Called when a comment is successfully deleted. The parent should update its- * comments state to mark this comment as deleted.- */onCommentDeleted?: (collectionID: number, commentID: string) => void;- /**- * Called when a comment reaction is added. The parent should update its- * reactions state to include this new reaction.- */onCommentReactionAdded?: (reaction: UnifiedReaction) => void;- /**- * Called when a comment reaction is deleted. The parent should update its- * reactions state to remove this reaction.- */onCommentReactionDeleted?: (collectionID: number,reactionID: string,) => void;- /**- * If set, the sidebar will scroll to and highlight this comment.- */highlightCommentID?: string;- /**- * Map of anonymous user ID to decrypted user name.- */anonUserNames?: Map<string, string>;}-/**- * A sidebar panel for displaying and managing comments on a file.- */interface ContextMenuState {comment: Comment;anchorEl: HTMLElement;@@ -500,45 +412,37 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({const hasLoadedRef = useRef(false);const inputRef = useRef<HTMLInputElement>(null);const commentsContainerRef = useRef<HTMLDivElement>(null);- // Ref to preserve isLiked state during context menu close animation+ // The menu stays mounted while contextMenu clears for its close animation.const contextMenuIsLikedRef = useRef(false);- // Comments grouped by collection: collectionID -> commentsconst [commentsByCollection, setCommentsByCollection] = useState<Map<number, Comment[]>>(new Map());- // Selected collection for viewing comments (when in gallery view)const [selectedCollectionID, setSelectedCollectionID] = useState<number | undefined>(undefined);- // Thumbnail URLs for each collection's cover file: collectionID -> URLconst [thumbnailURLs, setThumbnailURLs] = useState<Map<number, string>>(new Map(),);- // Comment reactions: commentID -> reactionID (for current user's likes)const [likedComments, setLikedComments] = useState<Map<string, string>>(new Map(),);- // All reactions by collection: collectionID -> reactions arrayconst [reactionsByCollection, setReactionsByCollection] = useState<Map<number, UnifiedReaction[]>>(new Map());- // Track whether we've scrolled to the highlight comment for this openconst hasScrolledToHighlightRef = useRef(false);- // Focus input when replying to a commentuseEffect(() => {if (replyingTo && inputRef.current) {inputRef.current.focus();}}, [replyingTo]);- // Reset tracking refs when sidebar closesuseEffect(() => {if (!open) {hasScrolledToHighlightRef.current = false;@@ -546,7 +450,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({}}, [open]);- // Scroll to and highlight the target comment when opening from feeduseEffect(() => {if (!open ||@@ -564,7 +467,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({let cleanupTimeout: ReturnType<typeof setTimeout> | undefined;let blinkInterval: ReturnType<typeof setInterval> | undefined;- // Wait for DOM to update after comments state changeconst initialTimeout = setTimeout(() => {const commentWrapper = commentsContainerRef.current?.querySelector(`[data-comment-id="${highlightCommentID}"]`,@@ -572,24 +474,20 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({if (commentWrapper) {hasScrolledToHighlightRef.current = true;- // Scroll to the commentcommentWrapper.scrollIntoView({behavior: "smooth",block: "center",});- // Find the bubble element inside the wrapperconst bubbleElement = commentWrapper.querySelector<HTMLElement>("[data-comment-bubble]",);if (bubbleElement) {- // Wait for scroll to mostly complete, then apply blink highlighthighlightTimeout = setTimeout(() => {const computedStyle = getComputedStyle(bubbleElement);const originalBg = computedStyle.backgroundColor;- // Parse the RGB values to create 80% opacity versionconst rgbMatch = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(originalBg,);@@ -609,12 +507,10 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({: originalBg;}, 300);- // Stop blinking after 1.5 secondsfadeTimeout = setTimeout(() => {if (blinkInterval) clearInterval(blinkInterval);bubbleElement.style.backgroundColor = originalBg;- // Clean up transition stylecleanupTimeout = setTimeout(() => {bubbleElement.style.transition = "";bubbleElement.style.backgroundColor = "";@@ -634,7 +530,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({};}, [open, highlightCommentID, loading, comments]);- // Reset state when the file changes to avoid showing stale datauseEffect(() => {setSelectedCollectionID(undefined);setComments([]);@@ -644,17 +539,14 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({hasLoadedRef.current = false;}, [file?.id]);- // Check if opened from a collection contextconst hasCollectionContext =activeCollectionID !== undefined && activeCollectionID !== 0;- // Get all collections the file belongs toconst fileCollectionIDs = useMemo(() => {if (!file) return [];return fileNormalCollectionIDs?.get(file.id) ?? [];}, [file, fileNormalCollectionIDs]);- // Build collection info list with comment counts and cover files (shared albums only)const collectionsInfo = useMemo((): CollectionInfo[] => {return fileCollectionIDs.filter((collectionID) =>@@ -676,14 +568,12 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({});}, [fileCollectionIDs, collectionSummaries, commentsByCollection]);- // Collections sorted by comment count (descending) for dropdownconst sortedCollectionsInfo = useMemo(() => {return [...collectionsInfo].sort((a, b) => b.commentCount - a.commentCount,);}, [collectionsInfo]);- // Currently selected collection infoconst selectedCollectionInfo = useMemo(() => {const targetID = hasCollectionContext? activeCollectionID@@ -700,16 +590,13 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({sortedCollectionsInfo,]);- // Check if the current user can delete a given comment.- // User can delete if: they authored the comment, OR they are owner/admin of the collection.+ // Authors, collection owners, and shared-collection admins can delete.const canDeleteComment = useCallback((comment: Comment): boolean => {- // Comment author can always delete their own commentif (comment.userID === currentUserID) {return true;}- // Check if user is owner or admin of the selected collectionconst collectionID = selectedCollectionInfo?.id;if (!collectionID || !collectionSummaries) {return false;@@ -720,7 +607,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({return false;}- // User is owner (not sharedIncoming) or admin (sharedIncomingAdmin)return (!summary.attributes.has("sharedIncoming") ||summary.attributes.has("sharedIncomingAdmin")@@ -729,40 +615,29 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({[currentUserID, selectedCollectionInfo, collectionSummaries],);- // Load comments and reactions from prefetched data.+ // Polling refreshes preserve the selection and skip the initial spinner.const loadComments = useCallback(() => {if (!file || !open || !prefetchedComments) return;- // Only show loading spinner on initial load, not during polling refreshconst isInitialLoad = !hasLoadedRef.current;if (isInitialLoad) {setLoading(true);}try {- // Use prefetched datasetCommentsByCollection(prefetchedComments);setReactionsByCollection(prefetchedReactions ?? new Map());- // Set comments for the currently selected collectionif (hasCollectionContext && activeCollectionID) {const activeComments =prefetchedComments.get(activeCollectionID) ?? [];setComments(activeComments);} else {- // For gallery view, only auto-select on initial load.- // Use functional update to check current selection without- // adding selectedCollectionID as a dependency.setSelectedCollectionID((currentSelection) => {if (currentSelection !== undefined) {- // Already have a selection, don't change it.- // The useEffect that watches selectedCollectionID will- // update the displayed comments.return currentSelection;}- // Initial selection: find collection with most comments.- // Only consider shared collections (non-shared ones won't appear in the UI).let maxCount = -1;let bestCollectionID: number | undefined;for (const [@@ -808,14 +683,12 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({collectionSummaries,]);- // Load comments when the sidebar opensuseEffect(() => {if (open) {loadComments();}}, [open, loadComments]);- // Set initial selected collection to the one with most comments (gallery view)useEffect(() => {if (open &&@@ -823,8 +696,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({selectedCollectionID === undefined &&commentsByCollection.size > 0) {- // Find the collection with the most comments.- // Only consider shared collections (non-shared ones won't appear in the UI).let maxCount = -1;let bestCollectionID: number | undefined;for (const [@@ -856,7 +727,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({collectionSummaries,]);- // Update displayed comments when selected collection changes (gallery view)useEffect(() => {if (!hasCollectionContext && selectedCollectionID !== undefined) {const collectionComments =@@ -865,7 +735,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({}}, [hasCollectionContext, selectedCollectionID, commentsByCollection]);- // Fetch thumbnails for each collection's cover fileuseEffect(() => {if (!open || collectionsInfo.length === 0) {return;@@ -905,9 +774,8 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({};}, [open, collectionsInfo]);- // Build liked comments map from reactions when selected collection changes+ // Preserve likes while the sidebar closes.useEffect(() => {- // Don't reset state on close - preserves UI during exit animationif (!open) return;if (!selectedCollectionInfo) {setLikedComments(new Map());@@ -920,7 +788,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({return;}- // Find comment reactions that are likes from the current user.const newLikedComments = new Map<string, string>();for (const reaction of reactions) {if (reaction.commentID && reaction.reactionType === "green_heart") {@@ -949,7 +816,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({replyingTo?.id,);- // Add the new comment to local stateconst newComment: Comment = {id: newCommentID,collectionID,@@ -958,7 +824,8 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({parentCommentID: replyingTo?.id,isDeleted: false,userID: currentUserID ?? 0,- createdAt: Date.now() * 1000, // Microseconds to match server format+ // Server timestamps use microseconds.+ createdAt: Date.now() * 1000,updatedAt: Date.now() * 1000,};setComments((prev) => [...prev, newComment]);@@ -972,10 +839,8 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({setCommentText("");setReplyingTo(null);- // Notify parent to update its comments stateonCommentAdded?.(newComment);- // Scroll to bottom after adding commentsetTimeout(() => {if (commentsContainerRef.current) {commentsContainerRef.current.scrollTop = 0;@@ -992,7 +857,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({setReplyingTo(commentToReply);};- // Handler for keydown: Enter to send, Shift+Enter for new lineconst handleCommentKeyDown = (e: React.KeyboardEvent) => {if (e.key === "Enter" && !e.shiftKey) {e.preventDefault();@@ -1108,7 +972,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({try {await deleteComment(targetComment.id);- // Update local statesetComments((prev) =>prev.map((c) =>c.id === targetComment.id@@ -1131,7 +994,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({return next;});- // Notify parent to update its comments stateonCommentDeleted?.(targetComment.collectionID,targetComment.id,@@ -1143,7 +1005,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({}};- // Filter out deleted comments and sort by timestamp (newest first for column-reverse layout)const sortedComments = [...comments].filter((c) => !c.isDeleted).sort((a, b) => b.createdAt - a.createdAt);@@ -1301,16 +1162,13 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({const commentIsOwn =comment.userID === currentUserID;- // With column-reverse, visual order is reversed from array order- // Visual "above" = higher index, visual "below" = lower index+ // column-reverse makes the next array item visually+ // previous.const prevComment = sortedComments[index + 1];const nextComment = sortedComments[index - 1];- // 10 minutes in microseconds (server timestamps are in microseconds)const GROUP_TIME_THRESHOLD = 10 * 60 * 1000 * 1000;- // Comments are in same sequence if same user AND within 10 minutes- // For anon users, also check if they have the same anonUserIDconst isSameUser = (a: Comment, b: Comment) => {if (a.anonUserID && b.anonUserID) {return a.anonUserID === b.anonUserID;@@ -1342,7 +1200,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({const showOwnTimestamp =commentIsOwn && isFirstInSequence;- // Get the display name, avatar color key, and masked email status for the comment authorconst getCommentAuthorInfo = (): {name: string;avatarColorKey: string;@@ -1351,7 +1208,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({userID?: number;useContactDisplay: boolean;} => {- // If anonymous user, check anonUserNames mapif (comment.anonUserID) {const anonName =anonUserNames?.get(@@ -1360,13 +1216,11 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({`${t("anonymous")} ${comment.anonUserID.slice(-4)}`;return {name: anonName,- // Use name for avatar color (varying length like mobile emails)avatarColorKey: anonName,isMaskedEmail: false,useContactDisplay: false,};}- // For registered users, use emailconst emailFromMap =prefetchedUserIDToEmail?.get(comment.userID,@@ -1374,7 +1228,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({const email = emailFromMap ?? t("user");return {name: email,- // Use email or userID for avatar coloravatarColorKey: emailFromMap? emailFromMap: String(comment.userID),@@ -1554,7 +1407,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({) ?? t("user"));}- // Regular userreturn replyingTo.userID ===currentUserID? t("yourself")@@ -1635,11 +1487,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({);};-// =============================================================================-// Styled Components-// =============================================================================--// Drawer & Layoutconst SidebarDrawer = styled(Drawer)(({ theme }) => ({"& .MuiDrawer-paper": {width: "23vw",@@ -1698,7 +1545,6 @@ const CloseButton = styled(IconButton)(({ theme }) => ({}),}));-// Collection Dropdownconst CollectionDropdownButton = styled(Box)(({ theme }) => ({display: "inline-flex",alignItems: "center",@@ -1753,7 +1599,7 @@ const LoadingContainer = styled(Box)(() => ({justifyContent: "center",alignItems: "center",height: "100%",- // Offset for header (marginBottom: 48) + padding diff (32-24=8) = 56, halved+ // Compensate for the 56px header offset.marginTop: -28,}));@@ -1762,7 +1608,7 @@ const EmptyMessage = styled(Typography)(({ theme }) => ({justifyContent: "center",alignItems: "center",height: "100%",- // Offset for header (marginBottom: 48) + padding diff (32-24=8) = 56, halved+ // Compensate for the 56px header offset.marginTop: -28,color: "#666",...theme.applyStyles("dark", { color: "rgba(255, 255, 255, 0.5)" }),@@ -1827,7 +1673,6 @@ const CommentsContainer = styled(Box)(({ theme }) => ({}),}));-// Comment Headerconst CommentHeaderContainer = styled(Box)(() => ({display: "flex",alignItems: "center",@@ -1864,7 +1709,6 @@ const OwnTimestamp = styled(Typography)(({ theme }) => ({...theme.applyStyles("dark", { color: "rgba(255, 255, 255, 0.7)" }),}));-// Comment Bubblesconst CommentBubbleWrapper = styled(Box, {shouldForwardProp: (prop) =>!["isOwn", "isFirstOwn", "isLastOwn", "isHighlighted"].includes(@@ -1925,7 +1769,6 @@ const QuotedReplyContainer = styled(Box, {})),}));-// Input Areaconst InputContainer = styled(Box)(({ theme }) => ({position: "relative",backgroundColor: "#F3F3F3",@@ -2005,7 +1848,6 @@ const SendButton = styled(IconButton)(({ theme }) => ({}),}));-// Context Menuconst ContextMenuOverlay = styled(Box)(() => ({position: "absolute",top: -25,diff --git a/web/packages/gallery/components/viewer/LikesSidebar.tsx b/web/packages/gallery/components/viewer/LikesSidebar.tsxindex 2424f38d51..5ebbe0f4de 100644--- a/web/packages/gallery/components/viewer/LikesSidebar.tsx+++ b/web/packages/gallery/components/viewer/LikesSidebar.tsx@@ -26,10 +26,6 @@ import React, {useState,} from "react";-// =============================================================================-// Icons-// =============================================================================-const ChevronDownIcon: React.FC = () => (<svgwidth="22"@@ -80,23 +76,14 @@ const PersonIcon: React.FC = () => (</svg>);-// =============================================================================-// Types-// =============================================================================--/** A liker with display info. */interface Liker {id: string;userID: number;anonUserID?: string;userName: string;- /** The actual email when known. */email?: string;- /** Stable fallback key for avatar color when email is missing. */avatarColorKey: string;- /** The first letter of the actual name (not "You") for the avatar. */avatarInitial: string;- /** True if this is a registered user with masked email (show person icon). */isMaskedEmail: boolean;isCurrentUser: boolean;}@@ -142,7 +129,6 @@ const LikerRowItem: React.FC<{ liker: Liker }> = ({ liker }) => {);};-/** Collection info for the dropdown. */interface CollectionInfo {id: number;name: string;@@ -150,48 +136,17 @@ interface CollectionInfo {coverFile?: EnteFile;}-// =============================================================================-// Main Component-// =============================================================================-export interface LikesSidebarProps extends ModalVisibilityProps {- /**- * The file whose likes are being displayed.- */file?: EnteFile;- /**- * The currently active collection ID (when viewing from within a collection).- */activeCollectionID?: number;- /**- * A mapping from file IDs to the IDs of collections they belong to.- */fileNormalCollectionIDs?: Map<number, number[]>;- /**- * Collection summaries indexed by their IDs.- */collectionSummaries?: CollectionSummaries;- /**- * The current user's ID.- */currentUserID?: number;- /**- * Pre-fetched reactions by collection ID (includes both file and comment reactions).- */prefetchedReactions?: Map<number, UnifiedReaction[]>;- /**- * Pre-fetched user ID to email mapping.- */prefetchedUserIDToEmail?: Map<number, string>;- /**- * Map of anonymous user ID to decrypted user name.- */anonUserNames?: Map<string, string>;}-/**- * A sidebar panel for displaying users who liked a file.- */export const LikesSidebar: React.FC<LikesSidebarProps> = ({open,onClose,@@ -207,43 +162,35 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({const [loading, setLoading] = useState(false);const [collectionDropdownOpen, setCollectionDropdownOpen] = useState(false);- // Reactions grouped by collection: collectionID -> reactionsconst [reactionsByCollection, setReactionsByCollection] = useState<Map<number, UnifiedReaction[]>>(new Map());- // Selected collection for viewing likes (when in gallery view)const [selectedCollectionID, setSelectedCollectionID] = useState<number | undefined>(undefined);- // Thumbnail URLs for each collection's cover file: collectionID -> URLconst [thumbnailURLs, setThumbnailURLs] = useState<Map<number, string>>(new Map(),);- // Check if opened from a collection contextconst hasCollectionContext =activeCollectionID !== undefined && activeCollectionID !== 0;- // Get shared collections the file belongs toconst fileCollectionIDs = useMemo(() => {if (!file) return [];const allCollectionIDs = fileNormalCollectionIDs?.get(file.id) ?? [];- // If no collection IDs from fileNormalCollectionIDs,- // use the file's collection ID directly+ // Public viewers may only know the file's own collection.if (allCollectionIDs.length === 0) {return [file.collectionID];}- // Filter to only include shared collectionsreturn allCollectionIDs.filter((id) =>collectionSummaries?.get(id)?.attributes.has("shared"),);}, [file, fileNormalCollectionIDs, collectionSummaries]);- // Build collection info list with like counts and cover filesconst collectionsInfo = useMemo((): CollectionInfo[] => {return fileCollectionIDs.map((collectionID) => {const summary = collectionSummaries?.get(collectionID);@@ -260,12 +207,10 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({});}, [fileCollectionIDs, collectionSummaries, reactionsByCollection]);- // Collections sorted by like count (descending) for dropdownconst sortedCollectionsInfo = useMemo(() => {return [...collectionsInfo].sort((a, b) => b.likeCount - a.likeCount);}, [collectionsInfo]);- // Currently selected collection infoconst selectedCollectionInfo = useMemo(() => {const targetID = hasCollectionContext? activeCollectionID@@ -282,7 +227,6 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({sortedCollectionsInfo,]);- // Get likers for the selected collectionconst likers = useMemo((): Liker[] => {if (!selectedCollectionInfo) return [];const reactions =@@ -290,13 +234,11 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({return reactions.filter((r) => r.reactionType === "green_heart")- .sort((a, b) => b.createdAt - a.createdAt) // Most recent first+ .sort((a, b) => b.createdAt - a.createdAt).map((r) => {- // Check if this is an anonymous userconst isAnonymous =r.anonUserID || r.userID === 0 || r.userID === -1;- // Check if this is the current logged-in user.const isCurrentUser = r.userID === currentUserID;let email: string | undefined;@@ -305,14 +247,12 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({let actualName: string;if (isAnonymous) {- // Use decrypted name from anonUserNames if availableconst decryptedName = r.anonUserID? anonUserNames?.get(r.anonUserID): undefined;actualName =decryptedName ??`${t("anonymous")} ${r.anonUserID?.slice(-4) ?? ""}`;- // Use actualName for avatar color (varying length like mobile emails)email = actualName;avatarColorKey = actualName;userName = actualName;@@ -324,7 +264,6 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({userName = isCurrentUser ? t("you") : actualName;}- // Check if email is masked (starts with *)const isMaskedEmail =!isAnonymous && actualName.startsWith("*");@@ -348,14 +287,13 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({anonUserNames,]);- // Load reactions from prefetched dataconst loadReactions = useCallback(() => {if (!file || !open || !prefetchedReactions) return;setLoading(true);try {- // Use prefetched reactions (filter to only file reactions, not comment reactions)+ // Ignore comment reactions.const filteredReactions = new Map<number, UnifiedReaction[]>();for (const [collectionID, reactions] of prefetchedReactions) {const fileReactions = reactions.filter(@@ -372,16 +310,13 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({}}, [file, open, prefetchedReactions]);- // Track previous open state to detect when sidebar opens+ // Choose the most-liked collection only when the sidebar first opens.const prevOpenRef = useRef(false);- // Load reactions and set initial selection when the sidebar opensuseEffect(() => {if (open && !prevOpenRef.current) {- // Sidebar just opened - load reactions and set initial selectionloadReactions();- // Set initial selection to album with most likes (gallery view only)if (!hasCollectionContext &&prefetchedReactions &&@@ -415,11 +350,10 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({file?.id,]);- // Update local state when prefetchedReactions changes (e.g., like/unlike from heart button)useEffect(() => {if (!open || !file || !prefetchedReactions) return;- // Filter to only file reactions (not comment reactions)+ // Ignore comment reactions.const filteredReactions = new Map<number, UnifiedReaction[]>();for (const [collectionID, reactions] of prefetchedReactions) {const fileReactions = reactions.filter(@@ -431,9 +365,8 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({setReactionsByCollection(filteredReactions);}, [open, file, prefetchedReactions]);- // Fetch thumbnails for each collection's cover file+ // Keep thumbnails while the sidebar closes to avoid an animation flash.useEffect(() => {- // Only fetch when open, don't clear when closing (avoids flash during animation)if (!open || collectionsInfo.length === 0) {return;}@@ -634,11 +567,6 @@ export const LikesSidebar: React.FC<LikesSidebarProps> = ({);};-// =============================================================================-// Styled Components-// =============================================================================--// Drawer & Layoutconst SidebarDrawer = styled(Drawer)(({ theme }) => ({"& .MuiDrawer-paper": {width: "23vw",@@ -697,7 +625,6 @@ const CloseButton = styled(IconButton)(({ theme }) => ({}),}));-// Collection Dropdownconst CollectionDropdownButton = styled(Box)(({ theme }) => ({display: "inline-flex",alignItems: "center",@@ -822,7 +749,7 @@ const LoadingContainer = styled(Box)(() => ({justifyContent: "center",alignItems: "center",height: "100%",- // Offset for header (marginBottom: 48) + padding diff (32-24=8) = 56, halved+ // Compensate for the 56px header offset.marginTop: -28,}));@@ -831,13 +758,12 @@ const EmptyMessage = styled(Typography)(({ theme }) => ({justifyContent: "center",alignItems: "center",height: "100%",- // Offset for header (marginBottom: 48) + padding diff (32-24=8) = 56, halved+ // Compensate for the 56px header offset.marginTop: -28,color: "#666",...theme.applyStyles("dark", { color: "rgba(255, 255, 255, 0.5)" }),}));-// Context Menu Overlayconst ContextMenuOverlay = styled(Box)(() => ({position: "absolute",top: -25,diff --git a/web/packages/gallery/components/viewer/icons.tsx b/web/packages/gallery/components/viewer/icons.tsxindex c31ae9f705..6427281bf8 100644--- a/web/packages/gallery/components/viewer/icons.tsx+++ b/web/packages/gallery/components/viewer/icons.tsx@@ -1,41 +1,19 @@-/**- * @file [Note: SVG paths of MUI icons]- *- * When creating buttons for use with PhotoSwipe, we need to provide just the- * contents of the SVG element (e.g. paths) as an HTML string.- *- * Since we only need a handful, these strings were created by temporarily- * adding the following code in some existing React component to render the- * corresponding MUI icon React component to a string, and retain the path.- *- *- * import { renderToString } from "react-dom/server";- * import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";- *- * console.log(renderToString(<InfoOutlinedIcon />));- */--// The transforms are not part of the originals, they have been applied-// separately to get these icons to align with the ones built into PhotoSwipe.+// PhotoSwipe requires raw SVG markup; named entries came from the matching MUI icons.+// Transforms are local alignment adjustments, not part of the MUI paths.const paths = {// "@mui/icons-material/ErrorOutlined"error: '<path d="M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2M12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8" transform="translate(7, 5.7) scale(0.85)"',- // Custom heart outline icon (30x26 viewBox)heart: '<path d="M12.4926 23.4794C8.64537 20.6025 1.02344 14.0254 1.02344 8.10676C1.02344 4.19475 3.89425 1.02344 7.84162 1.02344C9.88707 1.02344 11.9325 1.70526 14.6598 4.43253C17.3871 1.70526 19.4325 1.02344 21.478 1.02344C25.4253 1.02344 28.2962 4.19475 28.2962 8.10676C28.2962 14.0254 20.6743 20.6025 16.827 23.4794C15.5324 24.4474 13.7872 24.4474 12.4926 23.4794Z" stroke="white" stroke-width="2.04545" stroke-linecap="round" stroke-linejoin="round" fill="none"',- // Custom heart filled icon (30x26 viewBox) - green fill for liked state"heart-fill":'<path d="M12.4926 23.4794C8.64537 20.6025 1.02344 14.0254 1.02344 8.10676C1.02344 4.19475 3.89425 1.02344 7.84162 1.02344C9.88707 1.02344 11.9325 1.70526 14.6598 4.43253C17.3871 1.70526 19.4325 1.02344 21.478 1.02344C25.4253 1.02344 28.2962 4.19475 28.2962 8.10676C28.2962 14.0254 20.6743 20.6025 16.827 23.4794C15.5324 24.4474 13.7872 24.4474 12.4926 23.4794Z" stroke="#22c55e" stroke-width="2.04545" stroke-linecap="round" stroke-linejoin="round" fill="#22c55e"',- // Custom comment bubble icon (28x28 viewBox, scaled to match heart)comment:'<path d="M13.636 25.9087C16.0633 25.9087 18.4361 25.189 20.4544 23.8404C22.4726 22.4919 24.0456 20.5751 24.9745 18.3326C25.9034 16.09 26.1465 13.6224 25.6729 11.2417C25.1994 8.86105 24.0305 6.67426 22.3141 4.95788C20.5978 3.24151 18.411 2.07265 16.0303 1.5991C13.6496 1.12556 11.182 1.3686 8.93944 2.29749C6.69689 3.22639 4.78015 4.79941 3.43161 6.81765C2.08306 8.83589 1.36328 11.2087 1.36328 13.636C1.36328 15.6651 1.85419 17.5783 2.72692 19.2637L1.36328 25.9087L8.00828 24.5451C9.69373 25.4178 11.6083 25.9087 13.636 25.9087Z" stroke="white" stroke-width="2.04545" stroke-linecap="round" stroke-linejoin="round" fill="none" transform="translate(1.5, 1.5) scale(0.9)"',// "@mui/icons-material/AlbumOutlined"live: '<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8m0-12.5c-2.49 0-4.5 2.01-4.5 4.5s2.01 4.5 4.5 4.5 4.5-2.01 4.5-4.5-2.01-4.5-4.5-4.5m0 5.5c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1" transform="translate(2, 8.7) scale(0.75)"',// "@mui/icons-material/VolumeUp"vol: '<path d="M3 9v6h4l5 5V4L7 9zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02M14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77" transform="translate(0, 9) scale(0.75)"',- // Custom star icon (outline)favorite:'<path d="M8.69381 1.56975C9.38617 0.609562 10.7995 0.609562 11.4919 1.56975L13.7114 4.64784C13.9253 4.9445 14.2255 5.16569 14.5699 5.28031L18.1427 6.46961C19.2572 6.84061 19.6939 8.20365 19.0073 9.16808L16.8062 12.2597C16.5941 12.5577 16.4794 12.9156 16.4783 13.2831L16.4669 17.0962C16.4634 18.2857 15.32 19.1281 14.2033 18.764L10.6234 17.5966C10.2784 17.4841 9.90729 17.4841 9.56228 17.5966L5.98245 18.764C4.86575 19.1281 3.72231 18.2857 3.71876 17.0962L3.70737 13.2831C3.70628 12.9156 3.5916 12.5577 3.37946 12.2597L1.17839 9.16808C0.491785 8.20365 0.928537 6.84061 2.04305 6.46961L5.61584 5.28031C5.96017 5.16569 6.26041 4.9445 6.47432 4.64784L8.69381 1.56975Z" fill="none" stroke="white" stroke-width="1.7" transform="translate(5.5, 6)"',- // Custom star icon (filled)"favorite-fill":'<path d="M8.69381 1.56975C9.38617 0.609562 10.7995 0.609562 11.4919 1.56975L13.7114 4.64784C13.9253 4.9445 14.2255 5.16569 14.5699 5.28031L18.1427 6.46961C19.2572 6.84061 19.6939 8.20365 19.0073 9.16808L16.8062 12.2597C16.5941 12.5577 16.4794 12.9156 16.4783 13.2831L16.4669 17.0962C16.4634 18.2857 15.32 19.1281 14.2033 18.764L10.6234 17.5966C10.2784 17.4841 9.90729 17.4841 9.56228 17.5966L5.98245 18.764C4.86575 19.1281 3.72231 18.2857 3.71876 17.0962L3.70737 13.2831C3.70628 12.9156 3.5916 12.5577 3.37946 12.2597L1.17839 9.16808C0.491785 8.20365 0.928537 6.84061 2.04305 6.46961L5.61584 5.28031C5.96017 5.16569 6.26041 4.9445 6.47432 4.64784L8.69381 1.56975Z" transform="translate(5.5, 6)"',// "@mui/icons-material/FileDownloadOutlined"@@ -58,22 +36,6 @@ type IconKeys = Exclude<"favorite-fill" | "fullscreen-exit">;-/**- * Return an object that can be passed verbatim to the "html" option expected by- * PhotoSwipe's registerElement function.- *- * API docs for registerElement:- * https://photoswipe.com/adding-ui-elements/#uiregisterelement-api- *- * Example:- *- * html: {- * isCustomSVG: true,- * inner: '<path d="M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8" transform="translate(3.5, 3.5)" id="pswp__icn-info" />',- * outlineID: "pswp__icn-info",- * }- *- */export const createPSRegisterElementIconHTML = (name: IconKeys) => ({isCustomSVG: true,inner:@@ -85,43 +47,23 @@ export const createPSRegisterElementIconHTML = (name: IconKeys) => ({outlineID: `pswp__icn-${name}`,});-// Favorite is a special case since it consists of two layers: outline and fill.const favoriteInner = () => {- // Main outline (white stroke)const outline = `${paths.favorite} id="pswp__icn-favorite" />`;- // Fill (for favorited state)const fill = `${paths["favorite-fill"]} id="pswp__icn-favorite-fill" />`;return outline + fill;};-// Fullscreen is also a special case since it has two states.const fullscreenInner = () =>`${paths.fullscreen} id="pswp__icn-fullscreen" />${paths["fullscreen-exit"]} id="pswp__icn-fullscreen-exit" />`;-/**- * The path of "@mui/icons-material/Settings" as as string.- *- * Assumes `viewBox="0 0 24 24"`.- */+// Use with viewBox="0 0 24 24".export const settingsSVGPath = `<path d="M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6"></path>`;-/**- * The path for the custom heart outline icon.- *- * Assumes `viewBox="0 0 30 26"`.- */+// Use with viewBox="0 0 30 26".export const heartSVGPath = paths.heart;-/**- * The path for the custom heart filled icon (green).- *- * Assumes `viewBox="0 0 30 26"`.- */+// Use with viewBox="0 0 30 26".export const heartFillSVGPath = paths["heart-fill"];-/**- * The path for the custom comment bubble icon.- *- * Assumes `viewBox="0 0 28 28"`.- */+// Use with viewBox="0 0 28 28".export const commentSVGPath = paths.comment;diff --git a/web/packages/gallery/services/convert-core.ts b/web/packages/gallery/services/convert-core.tsindex 3d4d74270b..645db2efe4 100644--- a/web/packages/gallery/services/convert-core.ts+++ b/web/packages/gallery/services/convert-core.ts@@ -12,32 +12,6 @@ export interface RenderableImageBlobWebOpts {onConvertToJPEGError?: (e: unknown) => void;}-/**- * Return a new {@link Blob} containing an image's data in a format that the- * browser likely knows how to render in an img tag or on a canvas.- *- * The type of the returned blob is set, whenever possible, to the MIME type of- * the data that we're dealing with.- *- * The logic used by this function is:- *- * 1. Try to detect the MIME type of the file from its contents and/or name.- *- * 2. If this detected type is one of the types that we know that the browser- * likely cannot render, continue. Otherwise return the imageBlob that was- * passed in after setting its MIME type.- *- * 3. If the caller provides a native JPEG converter, try that first and return- * the resultant JPEG blob.- *- * 4. If this is an HEIC file and the browser does not have native HEIC support,- * then use our Wasm HEIC converter and return the resultant JPEG blob.- *- * 5. Otherwise return the original with the MIME type if we were able to deduce- * one.- *- * It will catch all errors and return the original in those cases.- */export const renderableImageBlobWeb = async (imageBlob: Blob,fileName: string,@@ -60,8 +34,6 @@ export const renderableImageBlobWeb = async (}if (isHEICExtension(extension)) {- // If the browser already knows how to natively render HEICs,- // e.g. Safari 17+, Wasm conversion is unnecessary and slower.if (mimeType == "image/heic" && (await isHEICSupported())) {log.debug(() => `Using native HEIC support for ${fileName}`,@@ -72,10 +44,6 @@ export const renderableImageBlobWeb = async (}}- // Either it is something that the browser already knows how to render- // (e.g. JPEG/PNG), or is a file extension that might be supported in- // some browsers (e.g. JPEG 2000), or a file extension that we haven't- // specifically whitelisted for conversion.if (!mimeType) {log.info("Attempting to convert a file without a MIME type",@@ -93,16 +61,6 @@ export const renderableImageBlobWeb = async (let _isHEICSupported: Promise<boolean> | undefined;-/**- * Return true if the browser can natively render HEIC files.- *- * For performance, the result of the check is cached. There shouldn't be a- * reason for this cache to need be invalidated, the browser shouldn't suddenly- * drop its HEIC support in the middle of it running.- *- * The check works by trying to load a small HEIC file. Currently, the only- * browser with support for HEIC is Safari.- */export const isHEICSupported = () =>(_isHEICSupported ??= new Promise((resolve) => {const image = new Image();@@ -111,12 +69,6 @@ export const isHEICSupported = () =>image.src = testHEICDataURL;}));-/**- * A data URL encoding the smallest HEIC image (439 bytes).- *- * Source:- * https://github.com/vvideo/detect-audio-video/blob/main/src/image/smallest/index.ts- */const testHEICDataURL ="data:image/heic;base64,AAAAGGZ0eXBoZWljAAAAAG1pZjFoZWljAAABaW1ldGEAAAAAAAAAIWhkbHIAAAAAAAAAAHBpY3QAAAAAAAAAAAAAAAAAAAAADnBpdG0AAAAAAAEAAAAiaWxvYwAAAABEQAABAAEAAAAAAYkAAQAAAAAAAAAuAAAAI2lpbmYAAAAAAAEAAAAVaW5mZQIAAAAAAQAAaHZjMQAAAADpaXBycAAAAMppcGNvAAAAdmh2Y0MBA3AAAAAAAAAAAAAe8AD8/fj4AAAPAyAAAQAYQAEMAf//A3AAAAMAkAAAAwAAAwAeugJAIQABACpCAQEDcAAAAwCQAAADAAADAB6gIIEFluqumubgIaDAgAAAAwCAAAADAIQiAAEABkQBwXPBiQAAABRpc3BlAAAAAAAAAEAAAABAAAAAKGNsYXAAAAABAAAAAQAAAAEAAAAB////wQAAAAL////BAAAAAgAAABBwaXhpAAAAAAMICAgAAAAXaXBtYQAAAAAAAAABAAEEgQKDBAAAADZtZGF0AAAAKigBrwayEx2gkim3i/2Rd0CR/V6h6GbEyV3dheegYfLV9ZwraCH8nff+7w==";@@ -126,20 +78,6 @@ export interface PlayableVideoURLWebOpts {shouldConvertUnplayableVideo?: (videoBlob: Blob) => boolean;}-/**- * Return an object URL containing a video's data in a format that the browser- * likely knows how to play back using a video tag.- *- * Unlike {@link renderableImageBlobWeb}, this uses a simpler flowchart:- *- * 1. If the browser thinks it can play the video, return an object URL created- * directly from the provided {@link videoBlob}, unless the caller asks to- * force a conversion for a known platform quirk.- *- * 2. Otherwise try to convert using FFmpeg if the caller allows it.- *- * 3. On errors, return the original object URL as would've happened for step 1.- */export const playableVideoURLWeb = async (videoFileName: string,videoBlob: Blob,@@ -171,20 +109,16 @@ export const playableVideoURLWeb = async (return videoObjectURL;};+// Arbitrary 100 MB guard against expensive Wasm conversion.const shouldConvertSmallVideo = (videoBlob: Blob) =>- videoBlob.size < 100 * 1024 * 1024; /* 100 MB, arbitrary */+ videoBlob.size < 100 * 1024 * 1024;const videoBlobWithSafariMIME = async (videoFileName: string,videoBlob: Blob,) => {- // Safari-only MIME correction for blob URLs to avoid NotSupportedError.- // Prefer extension-based lookup first (fast, no sniff). Fallback to- // content detection only if extension is unknown.- //- // We use isHEICSupported() as a Safari proxy. Currently, Safari is the only- // browser with native HEIC support, so gating here effectively targets- // Safari engines where stricter blob MIME handling applies.+ // Safari rejects blob URLs whose MIME type is missing or wrong.+ // HEIC support is used as a Safari proxy.if (!(await isHEICSupported())) return videoBlob;const ext = lowercaseExtension(videoFileName);@@ -208,19 +142,7 @@ const videoBlobWithSafariMIME = async (return videoBlob;};-/**- * Try to see if the browser thinks it can play the video pointed to by the- * given {@link url} by creating a video element and initiating playback.- *- * Note that this can sometimes cause false positives if the browser can play- * some of the streams in the video, but not all. For example, the browser may- * be able to play back the video stream, but not the audio stream; in such- * cases this function will return true, causing us to skip conversion, but when- * the user actually plays the video there will be no sound.- *- * To deal with such cases in a holistic manner, we have a streaming variant of- * the video that gets transcoded into a near universal format.- */+// canplay can succeed when only the video stream is supported.const isPlaybackPossible = async (url: string): Promise<boolean> =>new Promise((resolve) => {const t = setTimeout(() => {diff --git a/web/packages/gallery/services/download.ts b/web/packages/gallery/services/download.tsindex d27b54c67b..d165b67cc8 100644--- a/web/packages/gallery/services/download.ts+++ b/web/packages/gallery/services/download.ts@@ -25,24 +25,8 @@ import { hlsPlaylistDataForFile, type HLSPlaylistDataForFile } from "./video";export { NetworkDownloadError, isNetworkDownloadError };export type { FileDownloadOpts, RenderableSourceURLs };-/**- * A class that tracks the state of in-progress downloads and conversions,- * including caching them for subsequent retrieval if appropriate.- *- * External code can use it via its singleton instance, {@link downloadManager}.- * The class will initialize itself on first use, however {@link logout} should- * be called on logout to reset its internal state.- */class DownloadManager {- /**- * Credentials that should be used to download files when we're in the- * context of the public albums app.- */publicAlbumsCredentials: PublicAlbumsCredentials | undefined;- /**- * Credentials that should be used to download files when we're in the- * context of the public memory share app.- */publicMemoryCredentials: PublicMemoryCredentials | undefined;private core = createDownloadManager({@@ -52,69 +36,40 @@ class DownloadManager {playableVideoURL,});- /**- * Reset the internal state of the download manager.- */logout() {this.publicAlbumsCredentials = undefined;this.publicMemoryCredentials = undefined;this.core.logout();}- /**- * Set the credentials that should be used for download files when we're- * running in the context of the public albums app.- */setPublicAlbumsCredentials(credentials: PublicAlbumsCredentials | undefined,) {this.publicAlbumsCredentials = credentials;}- /**- * Set the credentials that should be used for download files when we're- * running in the context of a public memory share.- */setPublicMemoryCredentials(credentials: PublicMemoryCredentials | undefined,) {this.publicMemoryCredentials = credentials;}- /**- * See: [Note: Tracking active file download progress in the UI]- */fileDownloadProgressSubscribe(onChange: () => void) {return this.core.fileDownloadProgressSubscribe(onChange);}- /**- * See: [Note: Tracking active file download progress in the UI]- */fileDownloadProgressSnapshot() {return this.core.fileDownloadProgressSnapshot();}- /**- * Resolves with an URL that points to the file's thumbnail.- */renderableThumbnailURL(file: EnteFile, cachedOnly = false) {return this.core.renderableThumbnailURL(file, cachedOnly);}- /**- * Returns the thumbnail data for a file, downloading it if needed.- */thumbnailData(file: EnteFile, cachedOnly = false) {return this.core.thumbnailData(file, cachedOnly);}- /**- * Return HLS playlist data for a file when viewing a public memory share.- *- * @returns HLS playlist data if available, or undefined if HLS streaming- * is not available for this file.- */hlsPlaylistDataForPublicMemory = async (file: EnteFile,): Promise<HLSPlaylistDataForFile> => {@@ -126,25 +81,14 @@ class DownloadManager {);};- /**- * Return a URL (and associated metadata) that can be used to show the given- * {@link file} within the app, converting its format (on the fly) if needed- * (if possible).- */renderableSourceURLs(file: EnteFile): Promise<RenderableSourceURLs> {return this.core.renderableSourceURLs(file);}- /**- * Return a blob to the file's contents, downloading it needed.- */fileBlob(file: EnteFile, opts?: FileDownloadOpts) {return this.core.fileBlob(file, opts);}- /**- * Return an stream to the file's contents, downloading it needed.- */fileStream(file: EnteFile, opts?: FileDownloadOpts) {return this.core.fileStream(file, opts);}@@ -165,11 +109,6 @@ class DownloadManager {}}- /**- * Download the full contents of {@link file}, automatically choosing the- * credentials for the logged in user, public albums, or public memory share- * depending on the current app context we are in.- */private async downloadFile(file: EnteFile, opts?: FileDownloadOpts) {if (this.publicAlbumsCredentials) {return publicAlbums_downloadFile(@@ -187,15 +126,8 @@ class DownloadManager {}}-/**- * Singleton instance of {@link DownloadManager}.- */export const downloadManager = new DownloadManager();-/**- * The various photos_* functions are used for the actual downloads when- * we're running in the context of the the photos app.- */const photos_downloadThumbnail = async (file: EnteFile) => {const customOrigin = await customAPIOrigin();@@ -213,9 +145,6 @@ const photos_downloadThumbnail = async (file: EnteFile) => {return new Uint8Array(await res.arrayBuffer());};-/**- * Download the full contents of the given {@link EnteFile}.- */const photos_downloadFile = async (file: EnteFile,opts?: FileDownloadOpts,@@ -224,37 +153,8 @@ const photos_downloadFile = async (const customOrigin = await customAPIOrigin();- // [Note: Passing credentials for self-hosted file fetches]- //- // Current Museum versions return a pre-signed object URL after- // authenticating the request with the X-Auth-Token header. The browser can- // then fetch that URL without forwarding Ente credentials to object- // storage.- //- // Older Museum versions redirect from the legacy endpoint. Browsers- // preserve request headers across that redirect, so the legacy fallback- // has to put the token in the query string instead.- //- // Ente's own interactive requests use a proxy instead of directly- // connecting to object storage.- //- // 1. The web browser makes a HTTP GET request to a proxy passing it the- // credentials in the "X-Auth-Token".- //- // 2. The proxy then does both the original steps: (a). Use the credentials- // to get the pre-signed URL, and (b) fetch that pre-signed URL and- // stream back the response.- //- // [Note: User initiated vs background downloads of files]- //- // The faster proxy approach is used for interactive requests to reduce the- // latency for the user (e.g. when the user is waiting to see a full- // resolution file). It can be faster than a direct connection as the proxy- // is network-nearer to the user (See: [Note: Faster uploads via workers])- //- // For background processing (e.g., ML indexing, HLS generation), the direct- // S3 connection (as what'd happen when self hosting) gets used.-+ // Custom origins and background jobs fetch directly.+ // Interactive Ente downloads use the lower-latency proxy.const getFile = async () => {if (customOrigin || background) {return fetchFile(file.id, "file");@@ -268,10 +168,6 @@ const photos_downloadFile = async (return retryEnsuringHTTPOk(getFile);};-/**- * The various publicAlbums_* functions are used for the actual downloads when- * we're running in the context of the the public albums app.- */const publicAlbums_downloadThumbnail = async (file: EnteFile,credentials: PublicAlbumsCredentials,@@ -319,10 +215,6 @@ const publicAlbums_downloadFile = async (return retryEnsuringHTTPOk(getFile);};-/**- * The various publicMemory_* functions are used for the actual downloads when- * we're running in the context of a public memory share.- */const publicMemory_downloadThumbnail = async (file: EnteFile,credentials: PublicMemoryCredentials,diff --git a/web/packages/gallery/services/ffmpeg/index.ts b/web/packages/gallery/services/ffmpeg/index.tsindex 57c4206679..6fcc2e3334 100644--- a/web/packages/gallery/services/ffmpeg/index.ts+++ b/web/packages/gallery/services/ffmpeg/index.ts@@ -22,19 +22,6 @@ import {} from "./constants";import { determineVideoDurationWeb, ffmpegExecWeb } from "./web";-/**- * Generate a thumbnail for the given video using a Wasm FFmpeg running in a web- * worker.- *- * This function is called during upload, when we need to generate thumbnails- * for the new files that the user is adding.- *- * @param blob The input video blob.- *- * @returns JPEG data of the generated thumbnail.- *- * See also {@link generateVideoThumbnailNative}.- */export const generateVideoThumbnailWeb = async (blob: Blob) =>_generateVideoThumbnail((seekTime: number) =>ffmpegExecWeb(makeGenThumbnailCommand(seekTime), blob, "jpeg"),@@ -44,29 +31,12 @@ const _generateVideoThumbnail = async (thumbnailAtTime: (seekTime: number) => Promise<Uint8Array<ArrayBuffer>>,): Promise<Uint8Array<ArrayBuffer>> => {try {- // Try generating thumbnail at seekTime 1 second.return await thumbnailAtTime(1);} catch {- // If that fails, try again at the beginning. If even this throws, let- // it fail.return await thumbnailAtTime(0);}};-/**- * Generate a thumbnail for the given video using a native FFmpeg binary bundled- * with our desktop app.- *- * This function is called during upload, when we need to generate thumbnails- * for the new files that the user is adding.- *- * @param dataOrPath The input video's data or the path to the video on the- * user's local file system. See: [Note: Reading a UploadItem].- *- * @returns JPEG data of the generated thumbnail.- *- * See also {@link generateVideoThumbnailNative}.- */export const generateVideoThumbnailNative = async (electron: Electron,fsUploadItem: FileSystemUploadItem,@@ -88,21 +58,17 @@ const _makeGenThumbnailCommand = (seekTime: number, forHDR: boolean) => [ffmpegPathPlaceholder,"-i",inputPathPlaceholder,- // Seek to seekTime in the video."-ss",`00:00:0${seekTime}`,- // Take the first frame"-vframes","1",- // Apply a filter to this frame"-vf",[// Scale it to a maximum height of 720 keeping aspect ratio, ensuring// that the dimensions are even (subsequent filters require this)."scale=-2:720",forHDR- ? // Apply a tonemap to ensure that thumbnails of HDR videos do- // not look washed out. See: [Note: Tonemapping HDR to HD].+ ? // Tone-map HDR frames so thumbnails are not washed out.["zscale=transfer=linear","tonemap=tonemap=hable:desat=0",@@ -115,19 +81,6 @@ const _makeGenThumbnailCommand = (seekTime: number, forHDR: boolean) => [outputPathPlaceholder,];-/**- * Extract metadata from the given video.- *- * When we're running in the context of our desktop app _and_ we're passed an- * upload item that resolves to a path of the user's file system, this uses the- * native FFmpeg bundled with our desktop app. Otherwise it uses a Wasm build of- * FFmpeg running in a web worker.- *- * This function is called during upload, when we need to extract the- * "ffmetadata" of videos that the user is uploading.- *- * @param uploadItem The video item being uploaded.- */export const extractVideoMetadata = async (uploadItem: UploadItem,): Promise<ParsedMetadata> => {@@ -143,23 +96,6 @@ export const extractVideoMetadata = async ();};-/**- * The FFmpeg command to use to extract metadata from videos.- *- * Options:- *- * - `-c [short for codex] copy`- * - copy is the [stream_specifier](ffmpeg.org/ffmpeg.html#Stream-specifiers)- * - copies all the stream without re-encoding- *- * - `-map_metadata`- * - http://ffmpeg.org/ffmpeg.html#Advanced-options (search for map_metadata)- * - copies all stream metadata to the output- *- * - `-f ffmetadata`- * - https://ffmpeg.org/ffmpeg-formats.html#Metadata-2- * - dump metadata from media files into a simple INI-like utf-8 text file- */const extractVideoMetadataCommand = [ffmpegPathPlaceholder,"-i",@@ -173,23 +109,8 @@ const extractVideoMetadataCommand = [outputPathPlaceholder,];-/**- * Convert the output produced by running the FFmpeg- * {@link extractVideoMetadataCommand} into a {@link ParsedMetadata}.- *- * @param ffmpegOutput The bytes containing the output of the FFmpeg command.- */const parseFFmpegExtractedMetadata = (ffmpegOutput: Uint8Array) => {- // The output is a utf8 INI-like text file with key=value pairs interspersed- // with comments and newlines.- //- // https://ffmpeg.org/ffmpeg-formats.html#Metadata-2- //- // On Windows, while I couldn't find it documented anywhere, the generated- // ffmetadata file uses Unix line separators ("\n"). But for the sake of- // extra (albeit possibly unnecessary) safety, handle both \r\n and \n- // separators in the split. See: [Note: ffmpeg newlines]-+ // Accept both line endings across FFmpeg builds.const lines = new TextDecoder().decode(ffmpegOutput).split(/\r?\n/);const isPair = (xs: string[]): xs is [string, string] => xs.length == 2;const kvPairs = lines.map((property) => property.split("=")).filter(isPair);@@ -198,6 +119,7 @@ const parseFFmpegExtractedMetadata = (ffmpegOutput: Uint8Array) => {const result: ParsedMetadata = {};+ // Prefer QuickTime metadata because it retains the time-zone offset.const creationDate =parseFFMetadataDate(kv.get("com.apple.quicktime.creationdate")) ??parseFFMetadataDate(kv.get("creation_time"));@@ -212,12 +134,6 @@ const parseFFmpegExtractedMetadata = (ffmpegOutput: Uint8Array) => {return result;};-/**- * Parse a location string found in the FFmpeg metadata attributes.- *- * This is meant to parse either the "com.apple.quicktime.location.ISO6709"- * (preferable) or the "location" key (fallback).- */const parseFFMetadataLocation = (s: string | undefined) => {if (!s) return undefined;@@ -236,15 +152,6 @@ const parseFFMetadataLocation = (s: string | undefined) => {return { latitude, longitude };};-/**- * Parse a date/time string found in the FFmpeg metadata attributes.- *- * This is meant to parse either the "com.apple.quicktime.creationdate"- * (preferable) or the "creation_time" key (fallback).- *- * Both of these are expected to be ISO 8601 date/time strings, but we prefer- * "com.apple.quicktime.creationdate" since it includes the time zone offset.- */const parseFFMetadataDate = (s: string | undefined) => {if (!s) return undefined;@@ -254,8 +161,7 @@ const parseFFMetadataDate = (s: string | undefined) => {return undefined;}- // While not strictly required, we retain the same behaviour as the image- // Exif parser of ignoring dates whose epoch is 0.+ // Match the image parser by rejecting the Unix epoch.if (!d.timestamp) {log.warn(`Ignoring zero video metadata date string "${s}"`);return undefined;@@ -264,17 +170,6 @@ const parseFFMetadataDate = (s: string | undefined) => {return d;};-/**- * Extract the duration (in seconds) from the given video- *- * This is a sibling of {@link extractVideoMetadata}, except it tries to- * determine the duration of the video. The duration is not part of the- * "ffmetadata", and is instead a property of the video itself.- *- * @param uploadItem The video item being uploaded.- *- * @return the duration of the video in seconds (a floating point number).- */export const determineVideoDuration = async (uploadItem: UploadItem,): Promise<number> =>@@ -284,17 +179,6 @@ export const determineVideoDuration = async (toPathOrZipEntry(uploadItem),);-/**- * Convert a video from a format that is not supported in the browser to MP4.- *- * This function is called when the user views a video or a live photo, and we- * want to play it back. The idea is to convert it to MP4 which has much more- * universal support in browsers.- *- * @param blob The video blob.- *- * @returns The mp4 video blob.- */export const convertToMP4 = async (blob: Blob,): Promise<Blob | Uint8Array<ArrayBuffer>> => {diff --git a/web/packages/gallery/services/ffmpeg/web.ts b/web/packages/gallery/services/ffmpeg/web.tsindex 06ce7e4e31..ca83b99902 100644--- a/web/packages/gallery/services/ffmpeg/web.ts+++ b/web/packages/gallery/services/ffmpeg/web.ts@@ -12,16 +12,11 @@ import {outputPathPlaceholder,} from "./constants";-/** Lazily initialized and loaded FFmpeg instance. */let _ffmpeg: Promise<FFmpeg> | undefined;-/** Queue of in-flight requests. */+// Interleaved ffmpeg.wasm calls can corrupt its memory.const _ffmpegTaskQueue = new PromiseQueue<Uint8Array<ArrayBuffer> | number>();-/**- * Return the shared {@link FFmpeg} instance, lazily creating and loading it if- * needed.- */const ffmpegLazy = (): Promise<FFmpeg> => (_ffmpeg ??= createFFmpeg());const createFFmpeg = async () => {@@ -30,56 +25,20 @@ const createFFmpeg = async () => {coreURL: "https://assets.ente.com/ffmpeg-core-0.12.10/ffmpeg-core.js",wasmURL: "https://assets.ente.com/ffmpeg-core-0.12.10/ffmpeg-core.wasm",});- // This is too noisy to enable even during development. Uncomment to taste.- // ffmpeg.on("log", (e) => log.debug(() => ["[ffmpeg]", e.message]));return ffmpeg;};-/**- * Run the given FFmpeg command using a Wasm FFmpeg running in a web worker.- *- * This is a sibling of {@link ffmpegExec} exposed by the desktop app in- * `ipc.ts`. As a rough ballpark, currently the native FFmpeg integration in the- * desktop app is 10-20x faster than the Wasm one.- *- * See: [Note: FFmpeg in Electron].- *- * @param command The FFmpeg command to execute.- *- * @param blob The input blob on which to run the command.- *- * @param outputFileExtension The extension of the (temporary) output file which- * will be generated by the command.- *- * @returns The contents of the output file generated as a result of executing- * {@link command} on {@link blob}.- */export const ffmpegExecWeb = async (command: FFmpegCommand,blob: Blob,outputFileExtension: string,): Promise<Uint8Array<ArrayBuffer>> => {const ffmpeg = await ffmpegLazy();- // Interleaving multiple ffmpeg.execs causes errors like- //- // > "Out of bounds memory access (evaluating 'Module["_malloc"](len)')"- //- // So serialize them using a promise queue.return _ffmpegTaskQueue.add(() =>ffmpegExec(ffmpeg, command, outputFileExtension, blob),) as Promise<Uint8Array<ArrayBuffer>>;};-/**- * Determine the duration of the given video blob.- *- * This is a specialized variant of {@link ffmpegExecWeb} that uses the same- * queue but internally uses ffprobe to try and determine the video's duration.- *- * @param blob The input blob on which to run the command, provided as a blob.- *- * @returns The duration of the {@link blob} (if it indeed is a video).- */export const determineVideoDurationWeb = async (blob: Blob,): Promise<number> => {@@ -98,8 +57,6 @@ const ffmpegExec = async (const outputSuffix = outputFileExtension ? "." + outputFileExtension : "";const outputPath = newID("out_") + outputSuffix;- // Exit status of the ffmpeg.exec invocation.- // `0` if no error, `!= 0` if timeout (1) or error.let status: number | undefined;return withInputMount(ffmpeg, blob, async (inputPath) => {@@ -141,8 +98,7 @@ const ffmpegExec = async (try {await ffmpeg.deleteFile(outputPath);} catch (e) {- // Output file might not even exist if the command did not succeed,- // so only log on success.+ // A failed command may not create the output file.if (status === 0) {log.error(`Failed to remove output ${outputPath}`, e);}@@ -204,18 +160,6 @@ const FFProbeOutputIsHDR = z.object({streams: z.array(z.object({ color_transfer: z.string().optional() })),});-/**- * A variant of the {@link isHDRVideo} function in the desktop app source (see- * `ffmpeg.ts`), except here we have access to ffprobe and can use that instead- * of parsing the ffmpeg stderr.- *- * See: [Note: Alternative FFmpeg command for HDR videos]- *- * @param inputFilePath The path to a video file on the FFmpeg FS.- *- * @returns `true` if this file is likely a HDR video. Exceptions are treated as- * `false` to make this function safe to invoke without breaking the happy path.- */const isHDRVideo = async (ffmpeg: FFmpeg, inputFilePath: string) => {let jsonString: string | undefined;try {@@ -223,15 +167,9 @@ const isHDRVideo = async (ffmpeg: FFmpeg, inputFilePath: string) => {ffmpeg,[["-i", inputFilePath],- // Show information about streams."-show_streams",- // Select the first video stream. This is not necessarily- // correct in a multi stream file because the ffmpeg automatic- // mapping will use the highest resolution stream, but short of- // reinventing ffmpeg's resolution mechanism, it is a reasonable- // assumption for our current heuristic check.+ // FFmpeg may auto-select another stream in multi-stream files.["-select_streams", "v:0"],- // Output JSON["-of", "json"],["-o", "output.json"],].flat(),@@ -253,26 +191,16 @@ const isHDRVideo = async (ffmpeg: FFmpeg, inputFilePath: string) => {}};-/**- * Return the textual output produced by verbatim invoking the given ffprobe- * {@link cmd} that is expected to writes to a file named {@link outputFilePath}- * in the FFmpeg FS.- *- * The file generated at {@link outputFilePath} is removed in all cases.- */const ffprobeOutput = async (ffmpeg: FFmpeg,cmd: string[],outputPath: string,) => {- // Exit status of the ffmpeg.ffprobe invocation.- // `0` if no error, `!= 0` if timeout (1) or error.let status: number | undefined;try {status = await ffmpeg.ffprobe(cmd);- // Currently, ffprobe incorrectly returns status -1 on success.- // https://github.com/ffmpegwasm/ffmpeg.wasm/issues/817+ // ffmpeg.wasm currently returns -1 on success.if (status !== 0 && status != -1) {log.info(`[wasm] ffprobe command failed with exit code ${status}: ${cmd.join(" ")}`,@@ -303,23 +231,7 @@ const FFProbeOutputDuration = z.object({const ffprobeExecVideoDuration = async (ffmpeg: FFmpeg, blob: Blob) =>withInputMount(ffmpeg, blob, async (inputPath) => {- // Determine the video duration from the container, bypassing the issues- // with stream selection.- //- // ffprobe -v error -show_entries format=duration -of- // default=noprint_wrappers=1:nokey=1 input.mp4- //- // Source:- // https://trac.ffmpeg.org/wiki/FFprobeTips#Formatcontainerduration- //- // Reference: https://ffmpeg.org/ffprobe.html- //- // Since we cannot grab the stdout easily, the command has been modified- // to output to a file instead. However, in doing the command seems to- // have become flaky - for certain videos, it outputs extra lines and- // not just the duration. So we also switch to the JSON output for more- // robust behaviour, and parse the duration from it.-+ // Scalar output can contain extra lines; JSON is more reliable.const jsonString = await ffprobeOutput(ffmpeg,[diff --git a/web/packages/gallery/services/save-core.ts b/web/packages/gallery/services/save-core.tsindex b40db07b11..6eb9178332 100644--- a/web/packages/gallery/services/save-core.ts+++ b/web/packages/gallery/services/save-core.ts@@ -25,13 +25,8 @@ export interface DownloadAndSaveFilesWebOpts {isHiddenCollectionSummary?: boolean;}-/**- * Download limits optimized for different devices and browsers.- */interface DownloadLimits {- /** Number of concurrent file downloads. */concurrency: number;- /** Maximum size of a ZIP batch in bytes. */maxZipSize: number;}@@ -51,12 +46,6 @@ const createJSZip = async (): Promise<JSZip> => {return new JSZipConstructor();};-/**- * Get download limits for the current device.- *- * - Mobile devices: 4 concurrent, 100MB max- * - Desktop: 8 concurrent, 250MB max- */const getDownloadLimits = (): DownloadLimits => {if (cachedLimits) return cachedLimits;@@ -71,8 +60,8 @@ const getDownloadLimits = (): DownloadLimits => {(ua.includes("macintosh") && navigator.maxTouchPoints > 1);cachedLimits = isMobile- ? { concurrency: 4, maxZipSize: 100 * 1024 * 1024 } // 100MB- : { concurrency: 8, maxZipSize: 250 * 1024 * 1024 }; // 250MB+ ? { concurrency: 4, maxZipSize: 100 * 1024 * 1024 }+ : { concurrency: 8, maxZipSize: 250 * 1024 * 1024 };return cachedLimits;};@@ -105,7 +94,6 @@ export const downloadAndSaveFilesWeb = async ({}: DownloadAndSaveFilesWebOpts) => {const total = files.length;if (!files.length) {- // Nothing to download.assertionFailed();return;}@@ -122,9 +110,7 @@ export const downloadAndSaveFilesWeb = async ({const failedFiles: EnteFile[] = [];let isDownloading = false;let updateSaveGroup: UpdateSaveGroup = () => undefined;- // Track the next ZIP batch index across retries so part numbers continue- // sequentially (e.g., if initial download creates Parts 1-5 and fails,- // retry creates Part 6+ instead of starting over at Part 1).+ // Retries continue part numbering instead of overwriting earlier ZIPs.let nextZipBatchIndex = 1;const downloadFilesWeb = async (@@ -133,7 +119,6 @@ export const downloadAndSaveFilesWeb = async ({) => {if (!filesToDownload.length || isDownloading) return;- // Reset counts first if this is a retry, before any other logicif (resetFailedCount) {updateSaveGroup((g) => ({...g,@@ -143,7 +128,6 @@ export const downloadAndSaveFilesWeb = async ({failedFiles.length = 0;}- // If already offline, mark all files as failed so retry is availableif (!navigator.onLine) {log.info("Download skipped - network is offline");for (const file of filesToDownload) {@@ -158,13 +142,11 @@ export const downloadAndSaveFilesWeb = async ({}isDownloading = true;- // Only clear on first download, not retry (already cleared above)if (!resetFailedCount) {failedFiles.length = 0;}try {- // Single non-live-photo file: download directly without zippingconst singleFile = filesToDownload[0];if (filesToDownload.length === 1 &&@@ -183,7 +165,6 @@ export const downloadAndSaveFilesWeb = async ({updateSaveGroup((g) => ({ ...g, failed: g.failed + 1 }));}} else {- // Multiple files or live photo: use ZIPnextZipBatchIndex = await saveAsZip(downloader,filesToDownload,@@ -234,10 +215,6 @@ export const downloadAndSaveFilesWeb = async ({await downloadFilesWeb(files);};-/**- * A helper class to accumulate files into ZIP batches and download them when- * the batch size limit is reached.- */class ZipBatcher {private zipPromise = createJSZip();private currentBatchSize = 0;@@ -266,34 +243,22 @@ class ZipBatcher {this.includePartNumber = includePartNumber || startingBatchIndex > 1;}- /**- * Get the next batch index that would be used for the next ZIP file.- * This is useful for tracking progress across retries.- */getNextBatchIndex(): number {return this.batchIndex;}- /**- * Add file data to the current ZIP batch. If adding this file would exceed- * the batch size limit, the current batch is downloaded first.- */async addFile(data: Uint8Array | Blob, fileName: string): Promise<void> {const size = data instanceof Blob ? data.size : data.byteLength;- // If adding this file would exceed the limit and we have files in the- // batch, download the current batch first.if (this.currentBatchSize > 0 &&this.currentBatchSize + size > this.maxZipSize) {this.includePartNumber = true;await this.downloadCurrentBatch();- // Notify that we're now preparing a new partthis.onStateChange?.(false, this.batchIndex);}- // Ensure unique file names within the ZIPconst uniqueName = this.getUniqueName(fileName);this.usedNames.add(uniqueName);const zip = await this.zipPromise;@@ -302,9 +267,6 @@ class ZipBatcher {this.currentFileCount++;}- /**- * Download any remaining files in the current batch.- */async flush(): Promise<void> {if (this.currentBatchSize > 0) {await this.downloadCurrentBatch();@@ -335,7 +297,6 @@ class ZipBatcher {this.onStateChange?.(false, this.batchIndex);}- // Reset for next batchthis.zipPromise = createJSZip();this.currentBatchSize = 0;this.currentFileCount = 0;@@ -343,10 +304,6 @@ class ZipBatcher {this.batchIndex++;}- /**- * Generate a unique file name within the ZIP by appending a suffix if the- * name already exists.- */private getUniqueName(fileName: string): string {if (!this.usedNames.has(fileName)) {return fileName;@@ -366,7 +323,6 @@ class ZipBatcher {}}-/** Result of downloading and processing a single file for ZIP inclusion. */type DownloadedFileData =| { type: "regular"; fileName: string; data: Uint8Array }| {@@ -377,9 +333,6 @@ type DownloadedFileData =videoData: Uint8Array;};-/**- * Download and process a single file, returning the data ready for ZIP.- */const downloadFileForZip = async (downloader: BrowserSaveDownloader,file: EnteFile,@@ -403,21 +356,6 @@ const downloadFileForZip = async (}};-/**- * Save multiple files as ZIP archives to the user's download folder.- *- * Files are batched into ZIPs using device-specific size limits. If the total- * exceeds that limit, multiple ZIP files will be downloaded. Downloads are- * performed concurrently for better performance.- *- * @param files The files to download and add to the ZIP.- * @param baseName The base name for the ZIP file(s).- * @param onSuccess Callback invoked after each file is successfully added.- * @param onError Callback invoked when a file fails to download.- * @param canceller An AbortController to check for cancellation.- * @param startingBatchIndex The batch index to start from (for retries).- * @returns The next batch index to use for subsequent ZIPs (useful for retries).- */const saveAsZip = async (downloader: BrowserSaveDownloader,files: EnteFile[],@@ -443,15 +381,10 @@ const saveAsZip = async (includePartNumber,);- // Set initial part numberupdateSaveGroup((g) => ({ ...g, currentPart: startingBatchIndex }));- // Queue of files to processlet fileIndex = 0;- // Track if we've gone offline to stop processing immediately.- // Using an object so the value can be mutated by event handlers and- // checked synchronously by the async workers.const networkState = { isOffline: !navigator.onLine };const handleOffline = () => {networkState.isOffline = true;@@ -462,8 +395,7 @@ const saveAsZip = async (window.addEventListener("offline", handleOffline);window.addEventListener("online", handleOnline);- // Mutex for serializing ZIP additions (download is concurrent, but adding- // to the ZIP must be serialized to avoid race conditions with batching)+ // Downloads run concurrently; ZIP mutation must stay serial.let zipMutex: Promise<void> = Promise.resolve();const withZipLock = async <T>(fn: () => Promise<T>): Promise<T> => {const prev = zipMutex;@@ -477,14 +409,11 @@ const saveAsZip = async (}};- // Process a single file: download, then add to ZIPconst processFile = async (): Promise<boolean> => {- // Stop immediately if offline or cancelledif (networkState.isOffline || canceller.signal.aborted) {return false;}- // Get next file to processconst currentIndex = fileIndex++;if (currentIndex >= files.length) {return false;@@ -492,18 +421,15 @@ const saveAsZip = async (const file = files[currentIndex]!;try {- // Check again before starting download (value can change via event handler)+ // Event handlers can change this between awaits.// eslint-disable-next-line @typescript-eslint/no-unnecessary-conditionif (networkState.isOffline) {- // Put this file back for retryonError(file, new Error("Network offline"));return false;}- // Download happens concurrentlyconst downloadedData = await downloadFileForZip(downloader, file);- // Adding to ZIP is serialized via mutexawait withZipLock(async () => {if (downloadedData.type === "livePhoto") {await batcher.addFile(@@ -523,15 +449,14 @@ const saveAsZip = async (});onSuccess();} catch (e) {- // Individual file failed - mark it for retry but continue with others- // Only log non-network errors to avoid log spam when offline+ // Event handlers can change this during the download.// eslint-disable-next-line @typescript-eslint/no-unnecessary-conditionif (!networkState.isOffline) {log.error(`Failed to download file ${file.id}, skipping`, e);}onError(file, e);- // Only stop all processing if we went offline (not for individual failures)+ // Event handlers can change this during the download.// eslint-disable-next-line @typescript-eslint/no-unnecessary-conditionif (networkState.isOffline) {updateSaveGroup((g) => ({@@ -540,33 +465,28 @@ const saveAsZip = async (}));return false;}- // Mark as file error for individual failuresupdateSaveGroup((g) => ({...g,failureReason: g.failureReason ?? "file_error",}));- // Continue processing remaining files even if this one failed}return true;};- // Worker that continuously processes files until doneconst worker = async (): Promise<void> => {while (await processFile()) {- // Continue processing+ // Continue processing.}};try {- // Start concurrent workersconst workers = Array.from({ length: Math.min(concurrency, files.length) },() => worker(),);await Promise.all(workers);- // If we went offline, mark remaining files as failedif (networkState.isOffline) {updateSaveGroup((g) => ({...g,@@ -580,14 +500,12 @@ const saveAsZip = async (}}- // Flush whatever we have (even partial) unless cancelledif (!canceller.signal.aborted) {await batcher.flush();}return batcher.getNextBatchIndex();} finally {- // Clean up event listenerswindow.removeEventListener("offline", handleOffline);window.removeEventListener("online", handleOnline);}diff --git a/web/packages/gallery/services/upload/date.ts b/web/packages/gallery/services/upload/date.tsindex 3b200bf83c..6b38d607e7 100644--- a/web/packages/gallery/services/upload/date.ts+++ b/web/packages/gallery/services/upload/date.ts@@ -1,17 +1,7 @@import { nameAndExtension } from "ente-base/file-name";import log from "ente-base/log";-/**- * Try to extract a date (as epoch microseconds) from a file name by matching it- * against certain known patterns for media files.- *- * This uses all sorts of arbitrary heuristics gathered over time from feedback- * by users. In particular, this is meant to capture the dates from screenshots- * and chat app forwards.- *- * If the filename doesn't match a known pattern, or if there is some error- * during the parsing, return `undefined`.- */+// These heuristics recover dates from screenshots and chat app exports.export const tryParseEpochMicrosecondsFromFileName = (fileName: string,): number | undefined => {@@ -23,41 +13,24 @@ export const tryParseEpochMicrosecondsFromFileName = (}};-// Not sure why we have a try catch, but until there is a chance to validate-// that it doesn't indeed throw, keep this actual logic into this separate and-// more readable function.const parseEpochMicrosecondsFromFileName = (fileName: string) => {let date: Date | undefined;fileName = fileName.trim();- // Known patterns.if (fileName.startsWith("IMG-") || fileName.startsWith("VID-")) {- // WhatsApp media files- // - e.g. "IMG-20171218-WA0028.jpg"+ // WhatsApp: IMG-20171218-WA0028.jpgconst p = fileName.split("-");const dateString = p[1];if (dateString) {date = parseDateFromFusedDateString(dateString);}} else if (fileName.startsWith("Screenshot_")) {- // Screenshots on Android- // - e.g. "Screenshot_20181227-152914.jpg"+ // Android: Screenshot_20181227-152914.jpgconst dateString = fileName.replace("Screenshot_", "");date = parseDateFromFusedDateString(dateString);} else if (fileName.startsWith("signal-")) {- // Signal images- //- // Signal Android uses "yyyy-MM-dd-HH-mm-ss-SSS"- // https://github.com/signalapp/Signal-Android/commit/39e14e922bf3f5f11b796455355f69e2189d482f- //- // e.g. "signal-2024-08-17-21-58-10-982-1.jpg"- //- // Signal Desktop uses "YYYY-MM-DD-HHmmss"- // https://github.com/signalapp/Signal-Desktop/blob/41216f1378899709d03507649e4a602cebb0d064/js/views/attachment_view.js#L97- //- // e.g. "signal-2018-08-21-100217.jpg"- //+ // Signal Android and Desktop use different timestamp layouts.const p = fileName.split("-");if (p.length > 5) {const dateString = `${p[1]}${p[2]}${p[3]}-${p[4]}${p[5]}${p[6]}`;@@ -72,23 +45,7 @@ const parseEpochMicrosecondsFromFileName = (fileName: string) => {const [name] = nameAndExtension(fileName);if (name.endsWith("_iOS")) {- // Parse (some) iOS filenames.- //- // As reported by a customer, iOS sometimes (unknown exactly when)- // does not retain the Exif date but instead puts it in the filename- // in a format like `20230427_145116000_iOS.jpg`, and that Apple- // Photos can parse it back from there.- //- // I couldn't find more official documentation from a quick look,- // but there do seem to be other people on the internet- // corraborating this:- //- // > iOS 11, (older versions do the same thing), when I take a photo- // > or video, the filename consists of the following:- // > 20170923_220934000_iOS ... file name is based on UTC/GMT time.- // >- // > https://discussions.apple.com/thread/8087977-+ // iOS exports can encode UTC as 20230427_145116000_iOS.jpg.const p = name.split("_");if (p.length == 3) {const dateString = `${p[0]}-${p[1]}`;@@ -97,39 +54,26 @@ const parseEpochMicrosecondsFromFileName = (fileName: string) => {}}- // Generic pattern.if (!date) {date = parseDateFromDigitGroups(fileName);}- // Ignore invalid.if (!date || isNaN(date.getTime())) {return undefined;}- // Convert to epoch microseconds.const unixTime = date.getTime() * 1000;if (unixTime === Date.UTC(0, 0, 0, 0, 0, 0, 0) || unixTime === 0) {- // Ignore dateTimeStrings of the form "0000:00:00 00:00:00". We do- // encounter such missing data in the wild.+ // Zero dates occur in real files as missing metadata.return undefined;} else if (unixTime > Date.now() * 1000) {- // We shouldn't be ignoring future dates, but since this is a file name- // parser, a future date usually indicates that we parsed some unrelated- // number that shouldn't have been parsed.+ // A future filename date is usually an unrelated number we matched.return undefined;} else {return unixTime;}};-/**- * An intermediate data structure we use for the functions in this file. It- * stores the various components of a JavaScript date.- *- * In particular, the month is 0-indexed, as it is for the JavaScript Date's- * `getMonth`.- */interface DateComponents {year: number;month: number;@@ -139,14 +83,9 @@ interface DateComponents {second: number;}-/**- * Parse a date from a string of the form "YYYYMMDD-HHMMSS". Any extra- * characters at the end are ignored.- */const parseDateFromFusedDateString = (s: string) =>validateAndGetDateFromComponents({year: Number(s.slice(0, 4)),- // JavaScript Date's month is 0-indexed.month: Number(s.slice(4, 6)) - 1,day: Number(s.slice(6, 8)),hour: Number(s.slice(9, 11)),@@ -154,26 +93,16 @@ const parseDateFromFusedDateString = (s: string) =>second: Number(s.slice(13, 15)),});-/**- * Try to see if we can parse an date from a string with arbitrary separators.- *- * For example, consider a string like "2018-08-19 12:34:45". We see if it is- * possible to extract six symbol separated digit groups from the string. If so,- * we use them to form a date.- */export const parseDateFromDigitGroups = (s: string) => {const [year, month, day, hour, minute, second] = s.match(/\d+/g) ?? [];- // If the filename has 8 consecutive and then 6 consecutive digits, then- // there is a high possibility that it is a date of the form- // "YYYYMMDD-HHMMSS".+ // Also recognize fused YYYYMMDD-HHMMSS dates.if (year?.length == 8 && month?.length == 6) {return parseDateFromFusedDateString(year + "-" + month);}return validateAndGetDateFromComponents({year: Number(year),- // JavaScript Date's month is 0-indexed.month: Number(month) - 1,day: Number(day),hour: Number(hour),@@ -185,7 +114,7 @@ export const parseDateFromDigitGroups = (s: string) => {const validateAndGetDateFromComponents = (components: DateComponents) => {let date = dateFromComponents(components);if (hasTimeValues(components) && !isTimePartValid(date, components)) {- // If the date has time values but they are not valid then remove them.+ // Keep a valid date even when its time is invalid.date = dateFromComponents({...components,hour: 0,diff --git a/web/packages/gallery/services/upload/metadata-json.ts b/web/packages/gallery/services/upload/metadata-json.tsindex e0c0ec5e95..ce54d7a88e 100644--- a/web/packages/gallery/services/upload/metadata-json.ts+++ b/web/packages/gallery/services/upload/metadata-json.ts@@ -1,5 +1,3 @@-/** @file Dealing with the JSON metadata sidecar files */-import { ensureElectron } from "ente-base/electron";import { nameAndExtension } from "ente-base/file-name";import log from "ente-base/log";@@ -10,46 +8,15 @@ import type {} from "ente-gallery/services/upload";import { readStream } from "ente-gallery/utils/native-stream";-/**- * The data we read from the JSON metadata sidecar files.- *- * The metadata JSON file format is similar to the JSON metadata sidecar format- * produced by Google Takeout. This is so that the user can import their Google- * Takeouts while preserving the metadata.- *- * During export the Ente app also writes out its own metadata in a similar and- * compatible format so that the user can easily round trip (i.e. export their- * data out of Ente, and import it back again). This also allows users to reuse- * existing third party tools for working with the takeout format.- */export interface ParsedMetadataJSON {creationTime?: number;modificationTime?: number;location?: Location;description?: string;favorited?: true;- /**- * true if the takeout metadata JSON contained a- * googlePhotosOrigin.fromPartnerSharing key, i.e. the file was shared with- * the user via Google Photos partner sharing.- */fromPartnerSharing?: true;}-/**- * Derive a key for the given {@link jsonFileName} that should be used to index- * into the {@link ParsedMetadataJSON} JSON map.- *- * @param pathPrefix The {@link UploadPathPrefix}, if available.- *- * @param collectionID The collection to which we're uploading.- *- * @param jsonFileName The file name for the JSON file.- *- * @returns A key suitable for indexing into the metadata JSON map.- *- * @see also {@link matchJSONMetadata}.- */export const metadataJSONMapKeyForJSON = (pathPrefix: UploadPathPrefix | undefined,collectionID: number,@@ -67,51 +34,20 @@ const makeKey3 = (fileName: string,) => `${pathPrefix ?? ""}-${collectionID}-${fileName}`;-/**- * Return the matching entry, if any, from {@link parsedMetadataJSONMap} for the- * {@link pathPrefix}, {@link collectionID} and {@link fileName} combination.- *- * This is the sibling of {@link metadataJSONMapKeyForJSON}, except for deriving- * the filename key we might have to try a bunch of different variations, so- * this does not return a single key but instead tries the combinations until it- * finds an entry in the map, and returns the found entry instead of the key.- *- * In brief,- *- * - When inserting the metadata entry into {@link parsedMetadataJSONMap}, we- * use {@link metadataJSONMapKeyForJSON}.- *- * - When reading back the metadata entry from {@link parsedMetadataJSONMap}, we- * use {@link matchJSONMetadata}- */export const matchJSONMetadata = (pathPrefix: UploadPathPrefix | undefined,collectionID: number,fileName: string,parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>,): ParsedMetadataJSON | undefined => {- // Break the fileName down into its components.let [name, extension] = nameAndExtension(fileName);if (extension) {extension = "." + extension;}- // Save the original name before any modifications for fallback lookups.const originalName = name;- // Trim off a suffix like "(1)" from the name, remembering what we trimmed- // since we need to add it back later.- //- // It needs to be handled separately because of the clipping (see below).- // The numbered suffix (if present) is not clipped. It is added at the end- // of the clipped ".supplemental-metadata" portion, instead of after the- // original filename.- //- // For example, "IMG_1234(1).jpg" would have a metadata filename of either- // "IMG_1234.jpg(1).json" or "IMG_1234.jpg.supplemental-metadata(1).json".- // And if the filename is too long, it gets turned into something like- // "IMG_1234.jpg.suppl(1).json".-+ // Takeout moves a trailing "(n)" after any clipped metadata suffix.let numberedSuffix = "";const endsWithNumberedSuffixWithBrackets = /\(\d+\)$/.exec(name);if (endsWithNumberedSuffixWithBrackets) {@@ -119,30 +55,21 @@ export const matchJSONMetadata = (numberedSuffix = endsWithNumberedSuffixWithBrackets[0];}- // Removes the "-edited" suffix, if present, so that the edited file can be- // associated to the original file's metadataJSON file as edited files don't- // have their own metadata files.-+ // Edited files reuse the original file's sidecar.const editedFileSuffix = "-edited";if (name.endsWith(editedFileSuffix)) {name = name.slice(0, -1 * editedFileSuffix.length);}- // Convenience function to vary only the file name component when- // constructing a key. Delegates to `makeKey3`.const makeKey = (fn: string) => makeKey3(pathPrefix, collectionID, fn);- // Derive a key from the collection name, file name and the suffix if any.let baseFileName = `${name}${extension}`;let key = makeKey(`${baseFileName}${numberedSuffix}`);let takeoutMetadata = parsedMetadataJSONMap.get(key);if (takeoutMetadata) return takeoutMetadata;- // If the file name is greater than 46 characters, then Google Photos, with- // its infinite storage, clips the file name. In such cases we need to use- // the clipped file name to get the key.-+ // Takeout clips sidecar base names to 46 characters.const maxGoogleFileNameLength = 46;key = makeKey(`${baseFileName.slice(0, maxGoogleFileNameLength)}${numberedSuffix}`,@@ -151,20 +78,7 @@ export const matchJSONMetadata = (takeoutMetadata = parsedMetadataJSONMap.get(key);if (takeoutMetadata) return takeoutMetadata;- // Newer Takeout exports are attaching a ".supplemental-metadata" suffix to- // the file name of the metadataJSON file, you know, just to cause havoc,- // and then clipping the file name if it's too long (ending up with- // filenames "very_long_file_name.jpg.supple.json").- //- // Note that If the original filename is longer than 46 characters, then the- // ".supplemental-metadata" suffix gets completely removed during the- // clipping, along with a portion of the original filename (as before).- //- // For example, if the original filename is 45 characters long, then- // everything except for the "." from ".supplemental-metadata" will get- // clipped. So the metadata file ends up with a filename like- // "filename_that_is_45_chars_long.jpg..json".-+ // Newer exports append this suffix before clipping.const supplSuffix = ".supplemental-metadata";baseFileName = `${name}${extension}${supplSuffix}`;key = makeKey(@@ -174,10 +88,7 @@ export const matchJSONMetadata = (takeoutMetadata = parsedMetadataJSONMap.get(key);if (takeoutMetadata) return takeoutMetadata;- // Some Google Takeout exports keep the numbered suffix in its original- // position instead of moving it to the end. For example, "skytree (2).jpg"- // may have metadata in "skytree (2).jpg.supplemental-metadata.json" instead- // of "skytree.jpg.supplemental-metadata(2).json". Try that pattern too.+ // Some exports leave "(n)" before the extension.if (numberedSuffix) {const originalBaseFileName = `${originalName}${extension}${supplSuffix}`;key = makeKey(originalBaseFileName.slice(0, maxGoogleFileNameLength));@@ -187,9 +98,6 @@ export const matchJSONMetadata = (return takeoutMetadata;};-/**- * Try to parse the contents of a metadata JSON file from a Google Takeout.- */export const tryParseTakeoutMetadataJSON = async (uploadItem: UploadItem,): Promise<ParsedMetadataJSON | undefined> => {@@ -201,9 +109,6 @@ export const tryParseTakeoutMetadataJSON = async (}};-/**- * Try to parse an album name from an album-level Google Takeout metadata JSON.- */export const tryParseTakeoutAlbumNameMetadataJSON = async (uploadItem: UploadItem,): Promise<string | undefined> => {@@ -230,17 +135,10 @@ const uploadItemText = async (uploadItem: UploadItem) => {const parseMetadataJSONText = (text: string) => {const metadataJSON_ = JSON.parse(text) as unknown;- // Ignore non objects.if (typeof metadataJSON_ != "object") return undefined;- // Ignore null.if (!metadataJSON_) return undefined;- // Ignore arrays.if (Array.isArray(metadataJSON_)) return undefined;- // At this point, `metadataJSON_` is an `object`, but TypeScript won't let- // me index it. The following is the simplest (but unsafe) way I could think- // of for convincing TypeScript to allow me to index `metadataJSON` with- // `string`s.const metadataJSON = metadataJSON_ as Record<string, unknown>;const parsedMetadataJSON: ParsedMetadataJSON = {};@@ -277,15 +175,6 @@ const parseMetadataJSONText = (text: string) => {return parsedMetadataJSON;};-/**- *- * @param text- * @returns metadata.json.title which is the album name- *- * This function receives the contents of the metadata.json- * and check whether it's a valid object and if so then- * tries to parse the title and return it.- */const parseAlbumNameMetadataJSONText = (text: string) => {const metadataJSON_ = JSON.parse(text) as unknown;if (typeof metadataJSON_ != "object") return undefined;@@ -296,15 +185,6 @@ const parseAlbumNameMetadataJSONText = (text: string) => {return parseGTNonEmptyString(metadataJSON.title);};-/**- * Parse a nullish epoch seconds timestamp string from a field in a Google- * Takeout JSON, converting it into epoch microseconds if it is found.- *- * Note that the metadata provided by Google does not include the time zone- * where the photo was taken, it only has an epoch seconds value. There is an- * associated formatted date value (e.g. "17 Feb 2021, 03:22:16 UTC") but that- * seems to be in UTC and doesn't have the time zone either.- */const parseGTTimestamp = (o: unknown): number | undefined => {if (o && typeof o == "object" && "timestamp" in o) {const ot = o.timestamp;@@ -312,11 +192,8 @@ const parseGTTimestamp = (o: unknown): number | undefined => {if (typeof ot == "string") {timestamp = parseInt(ot, 10);} else if (typeof ot == "number") {- // Ente desktop 1.7.11 and earlier used to write out a number, which- // is the correct datatype, but that makes it inconsistent with the- // numbers-as-string that Google takeout writes.- //- // So now we write out strings, and read either.+ // Google writes strings; Ente desktop 1.7.11 and earlier wrote+ // numbers.timestamp = Math.floor(ot);}if (timestamp && !Number.isNaN(timestamp)) {@@ -326,12 +203,6 @@ const parseGTTimestamp = (o: unknown): number | undefined => {return undefined;};-/**- * Parse a (latitude, longitude) location pair field in a Google Takeout JSON.- *- * Apparently Google puts in (0, 0) to indicate missing data, so this function- * only returns a parsed result if both components are present and non-zero.- */const parseGTLocation = (o: unknown): Location | undefined => {if (o &&@@ -342,14 +213,11 @@ const parseGTLocation = (o: unknown): Location | undefined => {typeof o.longitude == "number") {const { latitude, longitude } = o;+ // Takeout uses (0, 0) for missing locations.if (latitude !== 0 || longitude !== 0) return { latitude, longitude };}return undefined;};-/**- * Parse a string from a field in a Google Takeout JSON, treating empty strings- * as undefined.- */const parseGTNonEmptyString = (o: unknown): string | undefined =>o && typeof o == "string" ? o : undefined;diff --git a/web/packages/gallery/services/upload/thumbnail.ts b/web/packages/gallery/services/upload/thumbnail.tsindex 178b9fa2df..b2d0ca3c49 100644--- a/web/packages/gallery/services/upload/thumbnail.ts+++ b/web/packages/gallery/services/upload/thumbnail.ts@@ -11,43 +11,13 @@ import { heicToJPEG } from "ente-media/heic-convert";import { scaledImageDimensions } from "ente-media/image";import { withTimeout } from "ente-utils/promise";-/** Maximum width or height of the generated thumbnail */const maxThumbnailDimension = 720;-/** Maximum size (in bytes) of the generated thumbnail */-const maxThumbnailSize = 100 * 1024; // 100 KB--/**- * Timeout (ms) to wait before giving up on canvas thumbnail generation.- *- * [Note: Rendering arbitrary file types to the canvas needs a timeout]- *- * When generating thumbnails on the web (or as a fallback on the desktop app),- * we use an HTML canvas. We take the file's content, a blob, and load it on the- * canvas by creating an image URL for this blob (using `createObjectURL`).- *- * In case when the browser knows how to render images of this type, this works- * great. Later we can read off the thumbnail from the (resized) canvas.- *- * However, if this in not a file format that the browser can understand, then- * this process just hangs. There isn't a trivial way of knowing beforehand- * which browser will support which file type, so we need to add a timeout.- */+const maxThumbnailSize = 100 * 1024;++// Unsupported browser formats may never fire a load or error event.+// Bound the canvas fallback so upload can continue.const canvasThumbnailGenerationTimeout = 30 * 1000;-/**- * Generate a JPEG thumbnail for the given image or video blob.- *- * The thumbnail has a smaller file size so that is quick to load. But more- * importantly, it uses a universal file format (JPEG in our case) so that the- * thumbnail itself can be opened in all clients, even those like the web client- * itself that might not yet have support for more exotic formats.- *- * @param blob The image or video blob whose thumbnail we want to generate.- *- * @param fileTypeInfo The type information for the file this blob came from.- *- * @return The JPEG data of the generated thumbnail.- */export const generateThumbnailWeb = async (blob: Blob,fileTypeInfo: FileTypeInfo,@@ -175,22 +145,6 @@ export const generateVideoThumbnailUsingCanvas = async (blob: Blob) => {return await compressedJPEGData(canvas);};-/**- * Generate a JPEG thumbnail for the given file or path using native tools.- *- * This function only works when we're running in the context of our desktop- * app, and this dependency is enforced by the need to pass the {@link electron}- * object which we use to perform IPC with the Node.js side of our desktop app.- *- * @param fsUploadItem The image or video file on the user's file system whose- * thumbnail we want to generate.- *- * @param fileTypeInfo The type information for {@link fsUploadItem}.- *- * @return The JPEG data of the generated thumbnail.- *- * See also {@link generateThumbnailWeb}.- */export const generateThumbnailNative = async (electron: Electron,fsUploadItem: FileSystemUploadItem,@@ -204,10 +158,6 @@ export const generateThumbnailNative = async (): ffmpeg.generateVideoThumbnailNative(electron, fsUploadItem);-/**- * A fallback, black, thumbnail for use in cases where thumbnail generation- * fails.- */export const fallbackThumbnail = (): Uint8Array<ArrayBuffer> =>Uint8Array.from(atob(blackThumbnailB64), (c) => c.charCodeAt(0));diff --git a/web/packages/gallery/utils/detect-type.ts b/web/packages/gallery/utils/detect-type.tsindex 819c43dbfc..2bd3d63739 100644--- a/web/packages/gallery/utils/detect-type.ts+++ b/web/packages/gallery/utils/detect-type.ts@@ -7,49 +7,9 @@ import {} from "ente-media/file-type";import { fileTypeFromBuffer } from "file-type";-/**- * Read the file's initial contents or use the file's name to detect its type.- *- * This is a more convenient to use abstraction over- * {@link detectFileTypeInfoFromChunk} for use when we already have a- * {@link File} object. See that method's documentation for more details.- *- * @param file A {@link File} object- *- * @returns The detected {@link FileTypeInfo}.- */export const detectFileTypeInfo = async (file: File): Promise<FileTypeInfo> =>detectFileTypeInfoFromChunk(() => readInitialChunkOfFile(file), file.name);-/**- * The lower layer implementation of the type detector.- *- * Usually, when the code already has a {@link File} object at hand, it is- * easier to use the higher level {@link detectFileTypeInfo} function.- *- * However, this lower level function is also exposed for use in cases like- * during upload where we might not have a File object and would like to provide- * the initial chunk of the file's contents in a different way.-- * This function first reads an initial chunk of the file and tries to detect- * the file's {@link FileTypeInfo} from it. If that doesn't work, it then falls- * back to using the file's name to detect it.- *- * If neither of these two approaches work, it throws an exception.- *- * If we were able to detect the file type, but it is explicitly not a media- * (image or video) format that we support, then also this function will throw- * an exception. Such exceptions can be identified using the- * {@link isFileTypeNotSupportedError} predicate.-*- * @param readInitialChunk A function to call to read the initial chunk of the- * file's data. There is no strict requirement for the size of the chunk this- * function should return, generally the first few KBs should be good.- *- * @param fileNameOrPath The full path or just the file name of the file whose- * type we're trying to determine. This is used by the fallback layer that tries- * to detect the type info from the file's extension.- */export const detectFileTypeInfoFromChunk = async (readInitialChunk: () => Promise<Uint8Array>,fileNameOrPath: string,@@ -67,24 +27,18 @@ export const detectFileTypeInfoFromChunk = async (} else if (mimeType.startsWith("video/")) {fileType = FileType.video;} else {- // This string should satisfy `isFileTypeNotSupportedError`.+ // Keep this prefix in sync with isFileTypeNotSupportedError.throw new Error(`Unsupported file format (MIME type ${mimeType})`);}- return {- fileType,- // See https://github.com/sindresorhus/file-type/blob/main/core.d.ts- // for the full list of ext values.- extension: typeResult.ext,- mimeType,- };+ return { fileType, extension: typeResult.ext, mimeType };} catch (e) {const extension = lowercaseExtension(fileNameOrPath);const known = KnownFileTypeInfos.find((f) => f.extension == extension);if (known) return known;if (extension && KnownNonMediaFileExtensions.includes(extension)) {- // This string should satisfy `isFileTypeNotSupportedError`.+ // Keep this prefix in sync with isFileTypeNotSupportedError.throw new Error(`Unsupported file format (extension ${extension})`,{ cause: e },diff --git a/web/packages/gallery/utils/file.ts b/web/packages/gallery/utils/file.tsindex e3bedd1aef..0626fc6f23 100644--- a/web/packages/gallery/utils/file.ts+++ b/web/packages/gallery/utils/file.ts@@ -1,22 +1,8 @@import type { EnteFile } from "ente-media/file";import { fileCreationPhotoSortTime } from "ente-media/file-metadata";-/**- * Sort the given list of {@link EnteFile}s in place.- *- * Like the JavaScript Array#sort, this method modifies the {@link files}- * argument. It sorts {@link files} in place, and then returns a reference to- * the same mutated array.- *- * By default, files are sorted so that the newest one is first. The optional- * {@link sortAsc} flag can be set to `true` to sort them so that the oldest one- * is first.- */export const sortFiles = (files: EnteFile[], sortAsc = false) => {- // Sort based on the local photo creation date shown in the UI.- //- // For files with same creation date, sort based on the time of last- // modification.+ // Break equal displayed creation dates by modification time.const factor = sortAsc ? -1 : 1;const sortTimeByFile = new Map<EnteFile, number>();const sortTimeForFile = (file: EnteFile) => {@@ -36,29 +22,8 @@ export const sortFiles = (files: EnteFile[], sortAsc = false) => {});};-/**- * [Note: Collection file]- *- * File IDs themselves are unique across all the files for the user (in fact,- * they're unique across all the files in an Ente instance).- *- * However, we can have multiple entries for the same file ID in our local- * database and/or remote responses because the unit of account is not file, but- * a "Collection File" β a collection and file pair.- *- * For example, if the same file is symlinked into two collections, then we will- * have two "Collection File" entries for it, both with the same file ID, but- * with different collection IDs.- *- * This function returns files such that only one of these entries is returned.- * The entry that is returned is arbitrary in general, this function just picks- * the first one for each unique file ID.- *- * If this function is invoked on a list on which {@link sortFiles} has already- * been called, which by default sorts such that the newest file is first, then- * this function's behaviour would be to return the newest file from among- * multiple files with the same ID but different collections.- */+// A file can appear once per collection with the same global file ID.+// Keep the first entry; sorting before this chooses which membership survives.export const uniqueFilesByID = (files: EnteFile[]) => {const seen = new Set<number>();return files.filter(({ id }) => {@@ -68,11 +33,6 @@ export const uniqueFilesByID = (files: EnteFile[]) => {});};-/**- * Segment the given {@link files} into lists indexed by their collection ID.- *- * Order is preserved.- */export const groupFilesByCollectionID = (files: EnteFile[]) =>files.reduce((result, file) => {const id = file.collectionID;diff --git a/web/packages/gallery/utils/native-stream.ts b/web/packages/gallery/utils/native-stream.tsindex edf8c83d66..7ba4adfdce 100644--- a/web/packages/gallery/utils/native-stream.ts+++ b/web/packages/gallery/utils/native-stream.ts@@ -1,41 +1,9 @@-/**- * @file Streaming IPC communication with the Node.js layer of our desktop app.- *- * NOTE: These functions only work when we're running in our desktop app.- *- * See: [Note: IPC streams].- */-import type { Electron, ElectronMLWorker, ZipItem } from "ente-base/types/ipc";import { z } from "zod";import type { FileSystemUploadItem } from "../services/upload";-/**- * Stream the given file or zip entry from the user's local file system.- *- * This only works when we're running in our desktop app since it uses the- * "stream://" protocol handler exposed by our custom code in the Node.js layer.- * See: [Note: IPC streams].- *- * To avoid accidentally invoking it in a non-desktop app context, it requires- * the {@link Electron} (or a functionally similar) object as a parameter (even- * though it doesn't need or use it).- *- * @param pathOrZipItem Either the path on the file on the user's local file- * system whose contents we want to stream. Or a tuple containing the path to a- * zip file and the name of the entry within it.- *- * @return A ({@link Response}, size, lastModifiedMs) triple.- *- * * The response contains the contents of the file. In particular, the `body`- * {@link ReadableStream} property of this response can be used to read the- * files contents in a streaming manner.- *- * * The size is the size of the file that we'll be reading from disk.- *- * * The lastModifiedMs value is the last modified time of the file that we're- * reading, expressed as epoch milliseconds.- */+// Electron arguments prove these are desktop calls.+// The native protocol handlers do not otherwise use them.export const readStream = async (_: Electron | ElectronMLWorker,pathOrZipItem: string | ZipItem,@@ -74,20 +42,6 @@ const readNumericHeader = (res: Response, key: string) => {return value;};-/**- * Write the given stream to a file on the local machine.- *- * This only works when we're running in our desktop app since it uses the- * "stream://" protocol handler exposed by our custom code in the Node.js layer.- * See: [Note: IPC streams].- *- * To avoid accidentally invoking it in a non-desktop app context, it requires- * the {@link Electron} object as a parameter (even though it doesn't use it).- *- * @param path The path on the local machine where to write the file to.- *- * @param stream The stream which should be written into the file.- */export const writeStream = async (_: Electron,path: string,@@ -96,23 +50,10 @@ export const writeStream = async (const params = new URLSearchParams({ path });const url = new URL(`stream://write?${params.toString()}`);- // The duplex parameter needs to be set to 'half' when streaming requests.- //- // Currently browsers, and specifically in our case, since this code runs- // only within our desktop (Electron) app, Chromium, don't support 'full'- // duplex mode (i.e. streaming both the request and the response).- // https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requestsconst req = new Request(url, {- // GET can't have a bodymethod: "POST",- // [Note: duplex param required for stream body]- //- // The duplex parameter needs to be set to 'half' when streaming- // requests. However, TypeScript's libdom.d.ts does not include the- // "duplex" parameter, so we need to silence the tsc error. e.g. see- // https://github.com/node-fetch/node-fetch/issues/1769.- //- // @ts-expect-error See: [Note: duplex param required for stream body]+ // Chromium requires duplex for streamed request bodies.+ // @ts-expect-error duplex is missing from lib.dom.d.ts.duplex: "half",body: stream,});@@ -124,22 +65,6 @@ export const writeStream = async ();};-/**- * Initate a conversion to MP4, streaming the video contents to the node side.- *- * This is a variant of {@link writeStream} tailored for the conversion to MP4.- *- * @param _ An {@link Electron} instance, witness to the fact that we're running- * in the context of the desktop app. It is otherwise not used.- *- * @param video A {@link Blob} containing the video to convert.- *- * @returns a token that can then be passed to {@link readVideoStream} to- * retrieve the converted MP4 file. This three step sequence (write/read/done)- * can then be ended by using {@link videoStreamDone}).- *- * See: [Note: Convert to MP4].- */export const initiateConvertToMP4 = async (_: Electron,video: Blob,@@ -152,65 +77,14 @@ export const initiateConvertToMP4 = async (};const GenerateHLSResult = z.object({- /**- * A token that can be used to passed to {@link readVideoStream} to retrieve- * the generated HLS playlist.- */playlistToken: z.string(),- /**- * The dimensions (width and height in pixels) of the generated video stream.- */dimensions: z.object({ width: z.number(), height: z.number() }),- /**- * The size (in bytes) of the file containing the encrypted video segments.- */videoSize: z.number(),- /**- * The ID of the uploaded encrypted video segment file on the remote bucket.- */videoObjectID: z.string(),});export type GenerateHLSResult = z.infer<typeof GenerateHLSResult>;-/**- * Initate the generation of a HLS stream, streaming the source video contents- * to the node side.- *- * This is a variant of {@link writeStream} tailored for the HLS generation. It- * is similar to {@link initiateConvertToMP4}, but also supports streaming- * {@link FileSystemUploadItem}s and {@link ReadableStream}s.- *- * @param _ An {@link Electron} instance, witness to the fact that we're running- * in the context of the desktop app. It is otherwise not used.- *- * @param video The video to convert.- *- * - If we're called during the upload process, then this will be set to the- * {@link FileSystemUploadItem} that was uploaded. This way, we can directly- * use the on-disk file instead of needing to download the original from- * remote.- *- * - Otherwise it should be a {@link ReadableStream} of the video contents.- *- * @param fileID The ID of the {@link EnteFile} for which we're generating the- * HLS.- *- * @param fetchURL The fully resolved API URL for obtaining the pre-signed URLs- * to which the video segment file should be uploaded.- *- * @param authToken The user's auth token (for making the request to- * {@link fetchURL}).- *- * @returns a token that can be used to retrieve the generated HLS playlist, and- * metadata about the generated video (See {@link GenerateHLSResult}).- *- * In case the video is such that it doesn't require a separate stream to be- * generated (e.g. it is a small video using an already compatible codec), then- * this function will return `undefined`.- *- * See: [Note: Preview variant of videos].- */export const initiateGenerateHLS = async (_: Electron,video: FileSystemUploadItem | ReadableStream,@@ -229,18 +103,14 @@ export const initiateGenerateHLS = async (if (video instanceof ReadableStream) {body = video;} else {- // video is a DesktopUploadItembody = null;if (typeof video == "string") {- // Path to a regular file on the user's file system.params.set("path", video);} else if (Array.isArray(video)) {- // Path within a zip file on the user's file system.const [zipPath, entryName] = video;params.set("zipPath", zipPath);params.set("entryName", entryName);} else {- // A File with a path. Use the path.params.set("path", video.path);}}@@ -248,27 +118,20 @@ export const initiateGenerateHLS = async (const url = `stream://video?${params.toString()}`;const res = await fetch(url, {method: "POST",- // @ts-expect-error See: [Note: duplex param required for stream body]+ // Chromium requires duplex for streamed request bodies.+ // @ts-expect-error duplex is missing from lib.dom.d.ts.duplex: "half",body,});if (!res.ok)throw new Error(`Failed to write stream to ${url}: HTTP ${res.status}`);+ // 204 means the original video can be streamed as-is.if (res.status == 204) return undefined;return GenerateHLSResult.parse(await res.json());};-/**- * Variant of {@link readStream} tailored for video conversion.- *- * @param token A token obtained from a video conversion operation like- * {@link initiateConvertToMP4} or {@link initiateGenerateHLS}.- *- * @returns a Response that contains the data associated with the provided- * token.- */export const readVideoStream = async (_: Electron,token: string,@@ -287,15 +150,12 @@ export const readVideoStream = async (return res;};-/**- * Sibling of {@link readVideoStream} to let the native side know when we are- * done reading the response, so it can dispose any temporary resources.- */+// Call this after readVideoStream so native temporary files are released.export const videoStreamDone = async (_: Electron,token: string,): Promise<void> => {- // The value for `done` is arbitrary, only its presence matters.+ // Native checks only for the presence of done.const params = new URLSearchParams({ token, done: "1" });const url = new URL(`stream://video?${params.toString()}`);diff --git a/web/packages/gallery/utils/units.ts b/web/packages/gallery/utils/units.tsindex 229ec2ab9d..2ed94bd389 100644--- a/web/packages/gallery/utils/units.ts+++ b/web/packages/gallery/utils/units.ts@@ -1,31 +1,10 @@import { t } from "i18next";-/**- * Localized unit keys.- *- * For each of these, there is expected to be a localized key under- * "storage_unit". e.g. "storage_unit.tb".- */const units = ["b", "kb", "mb", "gb", "tb"];-/**- * Convert the given number of {@link bytes} to their equivalent GB string with- * {@link precision}.- *- * The returned string does not have the GB suffix.- */export const bytesInGB = (bytes: number, precision = 0): string =>(bytes / (1024 * 1024 * 1024)).toFixed(precision);-/**- * Convert the given number of {@link bytes} to a user visible string in an- * appropriately sized unit.- *- * The returned string includes the (localized) unit suffix, e.g. "TB".- *- * @param precision Modify the number of digits after the decimal point.- * Defaults to 2.- */export function formattedByteSize(bytes: number, precision = 2): string {if (bytes <= 0) return `0 ${t("storage_unit.mb")}`;@@ -49,20 +28,6 @@ interface FormattedStorageByteSizeOptions {round?: boolean;}-/**- * Convert the given number of storage {@link bytes} to a user visible string in- * an appropriately sized unit.- *- * This differs from {@link formattedByteSize} in that while- * {@link formattedByteSize} is meant for arbitrary byte sizes, this function- * has a few additional beautification heuristics that we want to apply when- * displaying the "storage size" (in different contexts) as opposed to, say, a- * generic "file size".- *- * @param options {@link FormattedStorageByteSizeOptions}.- *- * @return A user visible string, including the localized unit suffix.- */export const formattedStorageByteSize = (bytes: number,options?: FormattedStorageByteSizeOptions,@@ -77,8 +42,7 @@ export const formattedStorageByteSize = (let quantity = bytes / Math.pow(1024, i);let unit = units[i];- // Round up bytes, KBs and MBs to the bigger unit whenever they'll come of- // as more than 0.1.+ // Prefer 0.1 of the next unit over values above 100.if (quantity > 100 && i < units.length - 2) {quantity /= 1024;unit = units[i + 1];@@ -86,9 +50,8 @@ export const formattedStorageByteSize = (quantity = Number(quantity.toFixed(1));- // Truncate or round storage sizes to trim off unnecessary and potentially- // obscuring precision when they are larger that 10 GB.- if (bytes >= 10 * 1024 * 1024 * 1024 /* 10 GB */) {+ // Storage displays above 10 GB omit fractional precision.+ if (bytes >= 10 * 1024 * 1024 * 1024) {if (options?.round) {quantity = Math.ceil(quantity);} else {diff --git a/web/packages/media/file-metadata.ts b/web/packages/media/file-metadata.tsindex 89c89f9690..6ef4059e38 100644--- a/web/packages/media/file-metadata.ts+++ b/web/packages/media/file-metadata.ts@@ -64,9 +64,7 @@ export interface FilePublicMagicMetadataData {dateTime?: string;// UTC offset of the place where the photo was taken. e.g. "+02:00".offsetTime?: string;- // Edits to the creationTime metadata field.editedTime?: number;- // Edits to the title metadata field.editedName?: string;w?: number;h?: number;@@ -209,29 +207,22 @@ export interface ParsedMetadata {cameraModel?: string;}-// Photos in the wild frequently have no UTC offset attached to their embedded-// date/time, and users expect to see the time of the place where the photo was-// taken (a New Year's Eve photo should show midnight regardless of the-// viewer's timezone). So dates are kept as local date/time strings and must-// not be treated as UTC instants, even when an offset is available; the offset-// is retained only as extra context.+// Photo dates often have no UTC offset.+// Keep their wall-clock time local; offset is context, not display time.export interface ParsedMetadataDate {// A partial ISO 8601 date/time string guaranteed not to have a timezone// offset. e.g. "2023-08-23T18:03:00.000".dateTime: string;// A UTC offset of the form "Β±HH:mm" or "Z", when available.offset: string | undefined;- // Epoch microseconds derived from dateTime and offset. When offset is- // absent, dateTime is assumed to be in the timezone where this code runs,- // which is not always correct (e.g. vacation photos).+ // Epoch microseconds. Without offset, this uses the current timezone.timestamp: number;}export const parseMetadataDate = (s: string,): ParsedMetadataDate | undefined => {- // Milliseconds to epoch microseconds. Without an offset in s, Date parses- // it in the current timezone.+ // Date uses the current timezone when s has no offset.const timestamp = new Date(s).getTime() * 1000;if (isNaN(timestamp)) return undefined;@@ -246,18 +237,12 @@ export const parseMetadataDate = (sWithoutOffset = s;}- // Browsers parse partial ISO 8601 strings even though that is not- // standard. When the offset is absent, they parse date-only forms as UTC- // but date-time forms as local time; see- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format- // Appending "Z" to strings longer than "yyyy-mm-dd" (10 characters) forces- // UTC for both forms, so toISOString below returns the same value back.+ // Browsers parse date-only forms as UTC but date-time forms as local.+ // Force date-time forms through UTC so both canonicalize the same way.const date = new Date(sWithoutOffset + (sWithoutOffset.length <= 10 ? "" : "Z"),);- // toISOString is always UTC with a trailing "Z"; dropping the "Z" gives- // the canonical offset-less form.const dateTime = dropLast(date.toISOString());return { dateTime, offset, timestamp };diff --git a/web/packages/new/photos/components/DevSettings.tsx b/web/packages/new/photos/components/DevSettings.tsxindex dcb33790cb..6ea667b219 100644--- a/web/packages/new/photos/components/DevSettings.tsx+++ b/web/packages/new/photos/components/DevSettings.tsx@@ -22,21 +22,14 @@ import { z } from "zod";import { SlideUpTransition } from "./mui/SlideUpTransition";interface DevSettingsProps {- /** If `true`, then the dialog is shown. */open: boolean;- /** Called when the dialog wants to be closed. */onClose: () => void;}-/**- * A dialog allowing the user to set the API origin that the app connects to.- * See: [Note: Configuring custom server].- */export const DevSettings: React.FC<DevSettingsProps> = ({ open, onClose }) => {const fullScreen = useIsSmallWidth();const handleDialogClose: ModalProps["onClose"] = (_, reason: string) => {- // Don't close on backdrop clicks.if (reason != "backdropClick") onClose();};@@ -56,14 +49,8 @@ export const DevSettings: React.FC<DevSettingsProps> = ({ open, onClose }) => {type ContentsProps = Pick<DevSettingsProps, "onClose">;const Contents: React.FC<ContentsProps> = (props) => {- // We need two nested components.- //- // - The initialAPIOrigin cannot be in our parent (the top level- // DevSettings) otherwise it gets preserved across dialog reopens instead- // of being read from storage on opening the dialog.- //- // - The initialAPIOrigin cannot be in our child (Form) because Formik- // doesn't have supported for async initial values.+ // This boundary reloads the stored origin on every dialog open.+ // Form stays separate because Formik cannot await initial values.const [initialAPIOrigin, setInitialAPIOrigin] = useState<string | undefined>();@@ -74,24 +61,19 @@ const Contents: React.FC<ContentsProps> = (props) => {[],);- // Even though this is async, this should be instantaneous, we're just- // reading the value from the local IndexedDB.if (initialAPIOrigin === undefined) return <></>;return <Form {...{ initialAPIOrigin }} {...props} />;};-type FormProps = ContentsProps & {- /** The initial value of API origin to prefill in the text input field. */- initialAPIOrigin: string;-};+type FormProps = ContentsProps & { initialAPIOrigin: string };const Form: React.FC<FormProps> = ({ initialAPIOrigin, onClose }) => {const formik = useFormik({initialValues: { apiOrigin: initialAPIOrigin },validate: ({ apiOrigin }) => {try {- // The expression is not unused, it is used to validate the URL.+ // Constructing the URL performs validation.// eslint-disable-next-line @typescript-eslint/no-unused-expressionsapiOrigin && new URL(apiOrigin);} catch {@@ -103,9 +85,6 @@ const Form: React.FC<FormProps> = ({ initialAPIOrigin, onClose }) => {try {await updateAPIOrigin(values.apiOrigin);} catch (e) {- // The person using this functionality is likely a developer and- // might be helped more by the original error instead of a- // friendlier but less specific message.setErrors({apiOrigin: e instanceof Error ? e.message : String(e),});@@ -117,9 +96,7 @@ const Form: React.FC<FormProps> = ({ initialAPIOrigin, onClose }) => {},});- // Show validation errors only after the form has been submitted once (the- // touched state of apiOrigin gets set too early, perhaps because of the- // autoFocus).+ // Auto-focus marks this field touched before submission.const hasError =formik.submitCount > 0 &&formik.touched.apiOrigin &&@@ -141,11 +118,7 @@ const Form: React.FC<FormProps> = ({ initialAPIOrigin, onClose }) => {onChange={formik.handleChange}onBlur={formik.handleBlur}error={hasError}- helperText={- hasError- ? formik.errors.apiOrigin- : " " /* always show an empty string to prevent a layout shift */- }+ helperText={hasError ? formik.errors.apiOrigin : " "}slotProps={{input: {endAdornment: (@@ -190,18 +163,6 @@ const Form: React.FC<FormProps> = ({ initialAPIOrigin, onClose }) => {);};-/**- * Save {@link origin} to local storage after verifying it with a ping.- *- * The given {@link origin} will be verifying by making an API call to the- * `/ping` endpoint. If that succeeds, then it will be saved to local storage,- * and all subsequent API calls will use it as the {@link apiOrigin}.- *- * See: [Note: Configuring custom server].- *- * @param origin The new API origin to use. Pass an empty string to clear the- * previously saved API origin (if any).- */const updateAPIOrigin = async (origin: string) => {if (!origin) {await removeKV("apiOrigin");diff --git a/web/packages/new/photos/components/FileDateTimePicker.tsx b/web/packages/new/photos/components/FileDateTimePicker.tsxindex de1e3740c8..a2f39e43b9 100644--- a/web/packages/new/photos/components/FileDateTimePicker.tsx+++ b/web/packages/new/photos/components/FileDateTimePicker.tsx@@ -9,40 +9,13 @@ import type { ParsedMetadataDate } from "ente-media/file-metadata";import React, { useState } from "react";interface FileDateTimePickerProps {- /**- * The initial date to preselect in the date/time picker.- *- * If not provided, the current date/time is used.- */initialValue?: Date;- /**- * Callback invoked when the user makes and confirms a date/time.- */onAccept: (date: ParsedMetadataDate) => void;- /**- * Optional callback invoked when the picker has been closed.- *- * > Note: This is only informational, for the caller to update their state.- * > The picker has already been closed at this point.- */onDidClose?: () => void;}-/**- * A customized version of MUI DateTimePicker suitable for use in selecting and- * modifying the date/time for a photo.- *- * On success, it returns a {@link ParsedMetadataDate} which contains the a- * local date/time string representation of the selected date, the current UTC- * offset, and an epoch timestamp. The idea is that the user is picking a- * date/time in the hypothetical timezone of where the photo was taken.- *- * We return local (current) UTC offset, but this might be different from what- * the user is imagining when they're picking a date. So it should be taken as- * an advisory, and only used if the photo does not already have an associated- * UTC offset. For more discussion of the caveats and nuances around this, see- * [Note: Photos are always in local date/time].- */+// The returned offset is the current local offset, not necessarily the photo's.+// Preserve an existing photo offset instead of replacing it with this one.export const FileDateTimePicker: React.FC<FileDateTimePickerProps> = ({initialValue,onAccept,@@ -74,21 +47,12 @@ export const FileDateTimePicker: React.FC<FileDateTimePickerProps> = ({onOpen={() => setOpen(true)}disableFuture={true}timeSteps={{ minutes: 1 }}- /* The dialog grows too big on the default portrait mode with- our theme customizations. So we instead use the landscape- layout if the screen is large enough. */+ // Our themed portrait dialog is too tall for larger screens.orientation={isSmallWidth ? "portrait" : "landscape"}onAccept={handleAccept}slots={{ field: EmptyField }}slotProps={{- /* The time picker has a smaller height than the calendar,- which causes an ungainly layout shift. Prevent this by- giving a minimum height to the picker.-- The constant 336px will likely change in the future when- MUI gets updated, so this solution is fragile. However- MUI is anyways intending to replace the TimeClock with a- DigitalTimePicker that has a better UX. */+ // Match the calendar height to prevent a mode-switch jump.layout: {sx: { ".MuiTimeClock-root": { minHeight: "336px" } },},@@ -98,43 +62,16 @@ export const FileDateTimePicker: React.FC<FileDateTimePickerProps> = ({);};-/**- * We don't wish to render any UI for the MUI DateTimePicker when it is closed,- * and instead only wish to use it as a dialog that we trigger ourselves.- *- * To achieve this we provide this nop-DOM element as the "field" slot to the- * date/time picker.- *- * See: https://mui.com/x/react-date-pickers/custom-field/- */+// The picker is only a dialog; it must not render a closed-state field.const EmptyField: React.FC = () => <></>;-/**- * A variant of {@link parseMetadataDate} that does the same thing, but for- * {@link Dayjs} instances.- */const parseMetadataDateFromDayjs = (d: Dayjs): ParsedMetadataDate => {- // `Dayjs.format` returns an ISO 8601 string of the form- // 2020-04-02T08:02:17-05:00'.- //- // https://day.js.org/docs/en/display/format- //- // This is different from the JavaScript `Date.toISOString` which also- // returns an ISO 8601 string, but with the time zone descriptor always set- // to UTC Zulu ("Z").- //- // The behaviour of Dayjs.format is more convenient for us, since it does- // both things we wish for:- // - Display the date in the local timezone- // - Include the timezone offset.-+ // Unlike Date.toISOString, this preserves local time and its offset.const s = d.format();let dateTime: string;let offset: string | undefined;- // Check to see if there is a time-zone descriptor of the form "Z" or- // "Β±05:30" or "Β±0530" at the end of s.const m = /Z|[+-]\d\d:?\d\d$/.exec(s);if (m?.index) {dateTime = s.substring(0, m.index);diff --git a/web/packages/new/photos/components/ImageEditorOverlay.tsx b/web/packages/new/photos/components/ImageEditorOverlay.tsxindex bbac274abe..9d2dd31bac 100644--- a/web/packages/new/photos/components/ImageEditorOverlay.tsx+++ b/web/packages/new/photos/components/ImageEditorOverlay.tsx@@ -64,19 +64,7 @@ import React, {import { savedCollections } from "../services/photos-fdb";export type ImageEditorOverlayProps = ModalVisibilityProps & {- /**- * The (Ente) file to edit.- */file: EnteFile;- /**- * Called when the user activates the button to save a copy of the given- * {@link enteFile} to their Ente account with the edits they have made.- *- * @param editedFile A Web {@link File} containing the edited contents.- * @param collection The collection to which the edited file should be- * added.- * @param enteFile The original {@link EnteFile}.- */onSaveEditedCopy: (editedFile: File,collection: Collection,@@ -115,9 +103,6 @@ export const ImageEditorOverlay: React.FC<ImageEditorOverlayProps> = ({const parentRef = useRef<HTMLDivElement | null>(null);const [fileURL, setFileURL] = useState<string | undefined>(undefined);- // The MIME type of the original file that we are editing.- //- // It should generally be present, but it is not guaranteed to be.const [mimeType, setMIMEType] = useState<string | undefined>(undefined);const [currentRotationAngle, setCurrentRotationAngle] = useState(0);@@ -169,7 +154,6 @@ export const ImageEditorOverlay: React.FC<ImageEditorOverlayProps> = ({};const parentBounds = parentRef.current!.getBoundingClientRect();- // calculate the offset created by centering the canvas in its parentconst offsetX = (parentBounds.width - canvasBounds.width) / 2;const offsetY = (parentBounds.height - canvasBounds.height) / 2;@@ -183,11 +167,8 @@ export const ImageEditorOverlay: React.FC<ImageEditorOverlayProps> = ({const offsetX = e.pageX - rect.left - rect.width / 2;const offsetY = e.pageY - rect.top - rect.height / 2;- // The threshold near the corners of the crop box in which dragging is- // assumed as not the intention.const cornerThreshold = 20;- // check if the cursor is near the corners of the boxconst isNearLeftOrRightEdge =e.pageX < rect.left + cornerThreshold ||e.pageX > rect.right - cornerThreshold;@@ -196,7 +177,6 @@ export const ImageEditorOverlay: React.FC<ImageEditorOverlayProps> = ({e.pageY > rect.bottom - cornerThreshold;if (isNearLeftOrRightEdge && isNearTopOrBottomEdge) {- // cursor is near a corner, do not initiate draggingsetIsGrowing(true);setStartX(e.pageX);setStartY(e.pageY);@@ -213,7 +193,6 @@ export const ImageEditorOverlay: React.FC<ImageEditorOverlayProps> = ({const handleDrag: React.MouseEventHandler = (e) => {if (!isDragging && !isGrowing) return;- // d- variables are the delta change between start and nowconst dx = e.pageX - startX;const dy = e.pageY - startY;@@ -237,7 +216,6 @@ export const ImageEditorOverlay: React.FC<ImageEditorOverlayProps> = ({let newX = prev.x + dx;let newY = prev.y + dy;- // constrain the new position to the canvas boundaries, accounting for the offsetnewX = Math.max(offsetX,Math.min(newX, offsetX + canvasBounds.width - prev.width),@@ -349,7 +327,6 @@ export const ImageEditorOverlay: React.FC<ImageEditorOverlayProps> = ({useEffect(() => {if (currentRotationAngle >= 360 || currentRotationAngle <= -360) {- // set back to 0setCurrentRotationAngle(0);}}, [currentRotationAngle]);@@ -535,7 +512,7 @@ export const ImageEditorOverlay: React.FC<ImageEditorOverlayProps> = ({},}}sx={{- backgroundColor: "background.default" /* Opaque */,+ backgroundColor: "background.default",width: "100%",zIndex: "var(--mui-zIndex-modal)",}}@@ -739,21 +716,6 @@ const confirmEditorCloseDialogAttributes = (continue: { text: t("discard"), color: "critical", action: onConfirm },});-/**- * Create a new {@link File} with the contents of the given canvas.- *- * @param canvas A {@link HTMLCanvasElement} whose contents we want to download- * as a file.- *- * @param originalFileName The name of the original file which was used to seed- * the canvas. This will be used as a base name for the generated file (with an- * "-edited" suffix).- *- * @param originalMIMEType The MIME type of the original file which was used to- * seed the canvas. When possible, we try to download a file in the same format,- * but this is not guaranteed and depends on browser support. If the original- * MIME type can not be preserved, a PNG file will be downloaded.- */const canvasToFile = async (canvas: HTMLCanvasElement,originalFileName: string,@@ -762,9 +724,7 @@ const canvasToFile = async (const image = new Image();image.src = canvas.toDataURL();- // Browsers are required to support "image/png". They may also support- // "image/jpeg" and "image/webp". Potentially they may even support more- // formats, but to keep this scoped we limit to these three.+ // PNG is guaranteed; preserve JPEG or WebP when possible.let [mimeType, extension] = ["image/png", "png"];switch (originalMIMEType) {case "image/jpeg":@@ -897,12 +857,9 @@ const getCropRegionArgs = (cropBoxEle: HTMLDivElement,canvasEle: HTMLCanvasElement,) => {- // get the bounding rectangle of the crop boxconst cropBoxRect = cropBoxEle.getBoundingClientRect();- // Get the bounding rectangle of the canvasconst canvasRect = canvasEle.getBoundingClientRect();- // calculate the scale of the canvas display relative to its actual dimensionsconst displayScale = canvasEle.width / canvasRect.width;// calculate the coordinates of the crop box relative to the canvas and adjust for any scrolling by adding scroll offsets@@ -928,16 +885,11 @@ const FreehandCropRegion = forwardRef() => {return (<>- {/* Top overlay */}<CropOverlayRegionTemplate- // Height up to the top of the crop box.sx={{ top: 0, left: 0, right: 0, height: `${cropBox.y}px` }}/>- {/* Bottom overlay */}<CropOverlayRegionTemplate- // Height from the bottom of the crop box to the bottom of- // the canvas.sx={{bottom: 0,left: 0,@@ -946,27 +898,20 @@ const FreehandCropRegion = forwardRef(}}/>- {/* Left overlay */}<CropOverlayRegionTemplatesx={{top: `${cropBox.y}px`,left: 0,- // Width up to the left side of the crop box.width: `${cropBox.x}px`,- // Same height as the crop box.height: `${cropBox.height}px`,}}/>- {/* Right overlay */}<CropOverlayRegionTemplatesx={{top: `${cropBox.y}px`,right: 0,- // Width from the right side of the crop box to the- // right side of the canvas.width: `calc(100% - ${cropBox.x + cropBox.width}px)`,- // Same height as the crop box.height: `${cropBox.height}px`,}}/>@@ -1040,7 +985,6 @@ const TransformMenu: React.FC<CommonMenuProps> = ({setCanvasLoading,setTransformationPerformed,}) => {- // Crops the canvas according to originalHeight and originalWidth without compoundingconst cropCanvas = (canvas: HTMLCanvasElement,widthRatio: number,diff --git a/web/packages/new/photos/components/PeopleList.tsx b/web/packages/new/photos/components/PeopleList.tsxindex bdf51a1934..80d17ddf9e 100644--- a/web/packages/new/photos/components/PeopleList.tsx+++ b/web/packages/new/photos/components/PeopleList.tsx@@ -15,9 +15,6 @@ export interface SearchPeopleListProps {onSelectPerson: (personID: string) => void;}-/**- * Shows a list of {@link Person}s in the empty state of the search bar.- */export const SearchPeopleList: React.FC<SearchPeopleListProps> = ({people,onSelectPerson,@@ -74,45 +71,16 @@ const SearchPersonButton = styled(UnstyledButton)();export interface FilePeopleListProps {- /**- * The {@link EnteFile} whose information we are showing.- */file: EnteFile;- /**- * The list of faces in the file that are associated with a person.- */annotatedFaceIDs: AnnotatedFaceID[];- /**- * Called when the user selects a face in the list.- */onSelectFace: (annotatedFaceID: AnnotatedFaceID) => void;- /**- * People that were manually associated with the file, and should be shown- * in addition to detected faces.- */manuallyAssignedPeople?: Person[];- /**- * Called when the user selects a person (used for manually assigned people).- */onSelectPerson?: (personID: string) => void;- /**- * If set, show an option to manually associate the file with a person.- */onAddPerson?: () => void;- /**- * Title/tooltip for the "add person" button (if shown).- */addPersonTitle?: string;- /**- * Label shown under the "add person" button (if shown).- */addPersonLabel?: string;}-/**- * Show the list of faces in the given file that are associated with a specific- * person.- */export const FilePeopleList: React.FC<FilePeopleListProps> = ({file,annotatedFaceIDs,@@ -229,17 +197,9 @@ const AddPersonAvatar = styled("div")();export interface SuggestionFaceListProps {- /**- * Faces, each annotated with the corresponding {@link EnteFile}, to show in- * the list.- */faces: PreviewableFace[];}-/**- * Show the sampling of faces from a given cluster that is being offered as a- * suggestion to the user.- */export const SuggestionFaceList: React.FC<SuggestionFaceListProps> = ({faces,}) => {@@ -275,19 +235,10 @@ const SuggestionFace = styled("div")``;type FaceCropImageViewProps = PreviewableFace & {- /** Width and height for the placeholder. */placeholderDimension: number;};-/**- * An image view showing the face crop for the given face.- *- * The image is read from the "face-crops" {@link BlobCache}, regenerating it if- * needed (which is why also need to pass the associated file).- *- * While the image is being fetched or regenerated, or if it doesn't exist, a- * placeholder is shown.- */+// Missing local crops are regenerated from the associated file.const FaceCropImageView: React.FC<FaceCropImageViewProps> = ({faceID,file,diff --git a/web/packages/new/photos/components/Tiles.tsx b/web/packages/new/photos/components/Tiles.tsxindex 30c3782c00..5d4cba227a 100644--- a/web/packages/new/photos/components/Tiles.tsx+++ b/web/packages/new/photos/components/Tiles.tsx@@ -14,47 +14,15 @@ import { faceCrop } from "../services/ml";import { UnstyledButton } from "./UnstyledButton";interface ItemCardProps {- /**- * One of the *Tile components to use as the top level element.- */TileComponent: React.FC<React.PropsWithChildren>;- /**- * Optional file whose thumbnail (if any) should be should be shown.- */coverFile?: EnteFile | undefined;- /**- * Optional ID of a specific face within {@link coverFile} to show.- *- * Precondition: {@link faceID} must be an ID of a face that belongs to the- * given {@link coverFile}.- */+ // This face must belong to coverFile.coverFaceID?: string | undefined;- /**- * Optional boolean indicating if the user is currently scrolling.- *- * This is used as a hint by the file downloader to prioritize downloads.- */+ // The downloader uses this to adjust thumbnail priority.isScrolling?: boolean;- /**- * Optional click handler.- */onClick?: () => void;}-/**- * A generic card that can be be used to represent collections, files, people -- * anything that (usually) has an associated "cover photo".- *- * Usually, we provide it a {@link coverFile} prop to set the file whose- * thumbnail should be shown in the card. However, an additional- * {@link coverFaceID} prop can be used to show the face crop for that specific- * face within the cover file.- *- * Note that while the common use case is to use this with a cover photo (and an- * additional cover faceID), both of these are optional and the item card can- * also be used as a static component without an associated cover image by- * covering it with an opaque overlay.- */export const ItemCard: React.FC<React.PropsWithChildren<ItemCardProps>> = ({TileComponent,coverFile,@@ -102,16 +70,8 @@ export const ItemCard: React.FC<React.PropsWithChildren<ItemCardProps>> = ({);};-/**- * A generic "base" tile, meant to be used (after setting dimensions) as the- * {@link TileComponent} provided to an {@link ItemCard}.- *- * Use {@link Overlay} (usually via one of its presets) to overlay content on- * top of the tile.- */const BaseTile = styled("div")`display: flex;- /* Act as container for the absolutely positioned 'Overlay's. */position: relative;border-radius: 4px;overflow: hidden;@@ -125,45 +85,26 @@ const BaseTile = styled("div")`user-select: none;`;-/**- * A 48x48 TileComponent used in search result dropdown's preview files and- * other places.- */export const PreviewItemTile = styled(BaseTile)`width: 48px;height: 48px;`;-/**- * A rectangular, TV-ish tile used in the gallery bar.- */export const BarItemTile = styled(BaseTile)`width: 90px;height: 64px;color: white;`;-/**- * A square tile used on the duplicates listing.- */export const DuplicateItemTile = styled(BaseTile)`- /* The thumbnails are not interactable, reset the pointer */cursor: initial;`;-/**- * A variant of {@link BaseTile} meant for use when the tile is interactable.- */export const BaseTileButton = styled(UnstyledButton)`- /* Buttons reset this to the special token buttontext */color: inherit;- /* Buttons reset this to center */text-align: inherit;- /* Rest of this is mostly verbatim from BaseTile ... */-display: flex;- /* Act as container for the absolutely positioned 'Overlay's. */position: relative;border-radius: 4px;overflow: hidden;@@ -175,19 +116,11 @@ export const BaseTileButton = styled(UnstyledButton)`}`;-/**- * A large 150x150 TileComponent used when, for example, when showing the list- * of collections in the all collections view and in the collection selector.- */export const LargeTileButton = styled(BaseTileButton)`width: 150px;height: 150px;`;-/**- * An {@link Overlay} suitable for hosting textual content at the top left of- * small and medium sized tiles.- */export const TileTextOverlay = styled(Overlay)`padding: 4px;background: linear-gradient(@@ -197,10 +130,6 @@ export const TileTextOverlay = styled(Overlay)`);`;-/**- * A variation of {@link TileTextOverlay} for use with larger tiles like the- * {@link CollectionTile}.- */export const LargeTileTextOverlay = styled(Overlay)`padding: 8px;color: white;@@ -213,16 +142,6 @@ export const LargeTileTextOverlay = styled(Overlay)`);`;-/**- * A {@link LargeTileButton} suitable for use as the trigger for creating a new- * entry (e.g. creating new album, or a new person).- *- * It is styled to go well with other {@link LargeTileButton}s that display- * existing entries, except this one can allow the user to create a new item.- *- * The child is expected to be a text, it'll be wrapped in a {@link Typography}- * and shown at the top left of the button.- */export const LargeTileCreateNewButton: React.FC<React.PropsWithChildren<ButtonishProps>> = ({ onClick, children }) => (@@ -245,11 +164,6 @@ export const LargeTileCreateNewButton: React.FC<</LargeTileButton>);-/**- * An {@link Overlay} suitable for showing text at the bottom center of the- * tile. Used by the tiles in trash (for showing the days until deletion) and- * duplicate listing (for showing the collection name).- */export const TileBottomTextOverlay = styled(Overlay)`display: flex;justify-content: center;@@ -259,10 +173,6 @@ export const TileBottomTextOverlay = styled(Overlay)`color: white;`;-/**- * An {@link Overlay} for use with large file tiles, providing a container- * for selection indicators and file size labels.- */export const LargeFileTileOverlay = styled(Overlay)`display: flex;pointer-events: none;diff --git a/web/packages/new/photos/services/ml/blob.ts b/web/packages/new/photos/services/ml/blob.tsindex 872b8349c6..85a13ca3e8 100644--- a/web/packages/new/photos/services/ml/blob.ts+++ b/web/packages/new/photos/services/ml/blob.ts@@ -14,35 +14,11 @@ import { fileFileName } from "ente-media/file-metadata";import { FileType } from "ente-media/file-type";import { decodeLivePhoto } from "ente-media/live-photo";-/**- * The encoded, undecoded image contents that should be indexed for a given- * file.- *- * The native side decodes all the formats we care about itself, so unlike- * {@link fetchRenderableEnteFileBlob} there is no JPEG conversion involved.- */+// These are encoded source bytes; the native pipeline performs decoding.export interface IndexableImageSource {bytes: Uint8Array<ArrayBuffer>;}-/**- * Return the original image contents for the native ML pipeline to index.- *- * - For images this is the original image itself: the local file when we're- * called during an upload from this client, otherwise the downloaded (and- * decrypted) original.- * - For videos it is their (JPEG) thumbnail.- * - For live photos it is the image component of the live photo.- *- * @param file The {@link EnteFile} to index.- *- * @param puItem If we're called during the upload process, then this will be- * set to the {@link ProcessableUploadItem} that was uploaded so that we can- * directly use the on-disk file instead of needing to download the original.- *- * @param electron The {@link ElectronMLWorker} instance that we can use to- * IPC with the Node.js layer.- */export const fetchIndexableImageSource = async (file: EnteFile,puItem: ProcessableUploadItem | undefined,@@ -66,11 +42,8 @@ export const fetchIndexableImageSource = async (const blob = await readNonVideoUploadItem(uploadItem, electron);const bytes = new Uint8Array(await blob.arrayBuffer());- // Revalidate after stabilizing the bytes. Multiple files are- // fetched ahead of the serialized native analysis queue, so a- // path must not remain as a deferred reference to mutable file- // system contents. If it changed while we were reading it,- // fall through and use the uploaded remote original instead.+ // Fetches run ahead of serialized native analysis.+ // Recheck the path after reading so replaced files use remote bytes.if (await fileSystemUploadItemIfUnchanged(puItem,@@ -86,7 +59,6 @@ export const fetchIndexableImageSource = async ();}}- // The file on disk has changed. Fetch it from remote instead.}const originalFileBlob = await downloadManager.fileBlob(file, {@@ -104,13 +76,7 @@ export const fetchIndexableImageSource = async (}};-/**- * Return renderable image bytes derived from an already fetched source.- *- * This is used when the native decoder rejects a format that the desktop app- * can convert to JPEG. Keeping conversion separate from fetching ensures the- * fallback uses the same stable bytes as the initial analysis attempt.- */+// Decoder fallback must convert the same stable bytes used by native analysis.export const renderableImageBytes = async (file: EnteFile,source: IndexableImageSource,@@ -122,17 +88,6 @@ export const renderableImageBytes = async (return new Uint8Array(await blob.arrayBuffer());};-/**- * Read the given {@link uploadItem} into an in-memory representation.- *- * See: [Note: Reading a UploadItem]- *- * @param uploadItem An {@link UploadItem} which we are trying to index. The- * code calling us guarantees that this function will not be called for videos.- *- * @returns a web {@link File} that can be used to access the upload item's- * contents.- */const readNonVideoUploadItem = async (uploadItem: UploadItem,electron: ElectronMLWorker,@@ -143,8 +98,7 @@ const readNonVideoUploadItem = async (uploadItem,);const path = typeof uploadItem == "string" ? uploadItem : uploadItem[1];- // This function will not be called for videos, and for images- // it is reasonable to read the entire stream into memory here.+ // Native indexing never calls this for videos, so buffer the image.return new File([await response.arrayBuffer()], basename(path), {lastModified: lastModifiedMs,});@@ -157,13 +111,6 @@ const readNonVideoUploadItem = async (}};-/**- * Return a renderable one (possibly involving a JPEG conversion) blob for the- * given {@link EnteFile}.- *- * - The original will be downloaded if needed.- * - The original will be converted to JPEG if needed.- */export const fetchRenderableEnteFileBlob = async (file: EnteFile,): Promise<Blob> => {@@ -186,7 +133,6 @@ export const fetchRenderableEnteFileBlob = async (} else if (fileType == FileType.image) {return await renderableImageBlob(originalFileBlob, fileFileName(file));} else {- // A layer above us should've already filtered these out.throw new Error(`Cannot index unsupported file type ${fileType}`);}};diff --git a/web/packages/new/photos/services/ml/clip.ts b/web/packages/new/photos/services/ml/clip.tsindex 6c36897c6f..7ea304ebc4 100644--- a/web/packages/new/photos/services/ml/clip.ts+++ b/web/packages/new/photos/services/ml/clip.ts@@ -3,110 +3,37 @@ import { savedCLIPIndexes } from "./db";import { dotProduct } from "./math";import type { CLIPMatches } from "./worker-types";-/**- * The version of the CLIP indexing pipeline implemented by the current client.- */export const clipIndexingVersion = 1;-/**- * The CLIP embedding for a file (and some metadata).- *- * See {@link FaceIndex} for a similar structure with more comprehensive- * documentation.- *- * ---- *- * [Note: Natural language search using CLIP]- *- * CLIP (Contrastive Language-Image Pretraining) is a neural network trained on- * (image, text) pairs. It can be thought of as two separate (but jointly- * trained) encoders - one for images, and one for text - that both map to the- * same embedding space.- *- * We use this for natural language search (aka "magic search") within the app:- *- * 1. Pre-compute an embedding for each image.- *- * 2. When the user searches, compute an embedding for the search term.- *- * 3. Use cosine similarity to find the find the image (embedding) closest to- * the text (embedding).- *- * More details are in our [blog- * post](https://ente.com/blog/image-search-with-clip-ggml/) that describes the- * initial launch of this feature using the GGML runtime.- *- * Since the initial launch, we've switched over to another runtime,- * [ONNX](https://onnxruntime.ai), started using Apple's- * [MobileCLIP](https://github.com/apple/ml-mobileclip/) as the model and have- * made other implementation changes, but the overall gist remains the same.- *- * Note that we don't train the neural network - we only use one of the publicly- * available pre-trained neural networks for inference. These neural networks- * are wholly defined by their connectivity and weights. ONNX, our ML runtimes,- * loads these weights and instantiates a running network that we can use to- * compute the embeddings.- *- * Theoretically, the same CLIP model can be loaded by different frameworks /- * runtimes, but in practice each runtime has its own preferred format, and- * there are also quantization tradeoffs. So there is a specific model (a binary- * encoding of weights) tied to our current runtime that we use.- *- * To ensure that the embeddings, for the most part, can be shared, whenever- * possible we try to ensure that all the preprocessing steps, and the model- * itself, is the same across clients - web and mobile.- */+// Remote indexes are shared across clients.+// Keep model and preprocessing compatible.export interface CLIPIndex {- /**- * The CLIP embedding.- *- * This is an array of 512 floating point values that represent the- * embedding of the image in the same space where we'll embed the text so- * that both of them can be compared using a cosine distance.- */embedding: number[];}export type RemoteCLIPIndex = CLIPIndex & {- /** An integral version number of the indexing algorithm / pipeline. */version: number;- /** The UA for the client which generated this embedding. */client: string;- /**- * Bitmask describing the runtime that generated this index. An absent- * value on legacy remote data is parsed as zero.- */flags: number;};-export type LocalCLIPIndex = CLIPIndex & {- /** The ID of the {@link EnteFile} whose index this is. */- fileID: number;-};+export type LocalCLIPIndex = CLIPIndex & { fileID: number };-/**- * Find the files whose CLIP embedding "matches" the given {@link searchPhrase}.- *- * The result can also be `undefined`, which indicates that the download for the- * ML model is still in progress (trying again later should succeed).- */export const _clipMatches = async (searchPhrase: string,electron: ElectronMLWorker,): Promise<CLIPMatches | undefined> => {- // The native pipeline returns the embedding already normalized.const textEmbedding =await electron.computeCLIPTextEmbeddingIfAvailable(searchPhrase);+ // Undefined means the text model is still downloading.if (!textEmbedding) return undefined;const items = (await cachedOrReadCLIPIndexes()).map(({ fileID, embedding }) =>- // The dot product gives us cosine similarity here since both the- // vectors are already normalized.+ // Both embeddings are normalized, so this is cosine similarity.[fileID, dotProduct(embedding, textEmbedding)] as const,);- // This score threshold was obtain heuristically. 0.2 generally gives solid- // results, and around 0.15 we start getting many false positives (all this- // is query dependent too).+ // The heuristic threshold trades recall against query-dependent false+ // positives.return new Map(items.filter(([, score]) => score >= 0.175));};@@ -114,17 +41,7 @@ let _cachedCLIPIndexes:| { fileID: number; embedding: Float32Array }[]| undefined;-/**- * Cache the CLIP indexes when possible to avoid converting them from number[]- * to Float32Array during the match for-loop itself.- *- * Converting them to Float32Array gives a big performance boost (See: [Note:- * Dot product performance]). But doing that each time loses out on the- * amortized benefit, so this temporary cache is as attempt to alleviate that.- *- * Use {@link clearCachedCLIPIndexes} to clear the cache (e.g. after indexing- * produces potentially new CLIP indexes).- */+// Reusing Float32Arrays avoids conversion inside every search.const cachedOrReadCLIPIndexes = async () =>(_cachedCLIPIndexes ??= (await savedCLIPIndexes()).map(({ fileID, embedding }) => ({diff --git a/web/packages/new/photos/services/ml/cluster.ts b/web/packages/new/photos/services/ml/cluster.tsindex e24d22cf7e..d1ff890599 100644--- a/web/packages/new/photos/services/ml/cluster.ts+++ b/web/packages/new/photos/services/ml/cluster.ts@@ -18,23 +18,10 @@ import {} from "./face";import { dotProduct } from "./math";-/**- * A face cluster is an set of faces, and a nanoid to uniquely identify it.- *- * These are local only clusters. The clusters that are synced with remote are- * part of "cgroup" user entities.- */+// Local-only; synced clusters live in cgroup user entities.export interface FaceCluster {- /**- * A nanoid for this cluster.- */id: string;- /**- * An unordered set of ids of the faces that belong to this cluster.- *- * For ease of transportation and persistence this is an array, but it- * should conceptually be thought of as a set.- */+ // Treat this as a set even though persistence uses an array.faces: string[];}@@ -57,29 +44,11 @@ export type ClusterFacesReason =| "rename-cgroup"| "set-cgroup-pinned";-/** A {@link Face} annotated with data needed during clustering. */export type ClusterFace = Omit<Face, "embedding"> & {embedding: Float32Array;isBadFace: boolean;};-/**- * Generates clusters from the given faces using a batched form of linear- * clustering, with a bit of lookback (and a dollop of heuristics) to get the- * clusters to merge across batches.- *- * The same logic is used for both the initial clustering and subsequent- * incremental updates, just that the incremental updates will be much faster- * since most of the files will be skipped (as they already have a cluster- * assigned to them).- *- * [Note: Draining the event loop during clustering]- *- * The clustering is a synchronous operation, but we make it async to- * artificially drain the worker's event loop after each mini-batch so that- * other interactions with the worker (where this code runs) do not get stalled- * while clustering is in progress.- */export const _clusterFaces = async (faceIndexes: FaceIndex[],localFiles: EnteFile[],@@ -88,35 +57,18 @@ export const _clusterFaces = async () => {const startTime = Date.now();- // A flattened array of filtered and annotated faces.const filteredFaces = [...enumerateFaces(faceIndexes)];- // Sort faces temporally (a heuristic for better clusters), with the newest- // ones first.+ // Newest faces first improves the clustering heuristic.const faces = sortFacesNewestOnesFirst(filteredFaces, localFiles);- // Start with clusters we have currently (whether from remote or from a- // previous local run, but preferring the remote ones).let clusters: FaceCluster[] = [];- // Get the locally available remote cluster groups.const cgroups = await savedCGroups();- // Sort them so that the latest ones are first.- //- // This is not expected to be something that makes a functional difference- // but is done as part of a general theme of not making strict assumptions- // about the clusters we get from remote.- //- // In particular, the same face ID can be in different clusters. In such- // cases we should assign it arbitrarily assign it to the last cluster we- // find it in. Such leeway is intentionally provided to allow clients some- // slack in how they implement the sync without needing to make an blocking- // API request for every user interaction.-+ // A face can occur in multiple remote clusters; newest assignment wins.const sortedCGroups = cgroups.sort((a, b) => b.updatedAt - a.updatedAt);- // Fill in clusters from remote cgroups, and also construct rejected lookup.const rejectedClusterIDsForFaceID = new Map<string, Set<string>>();for (const cgroup of sortedCGroups) {if (cgroup.data.rejectedFaceIDs.length == 0) {@@ -137,21 +89,13 @@ export const _clusterFaces = async (}}- // Add on the clusters we have available locally.clusters = clusters.concat(await savedFaceClusters());- // For fast reverse lookup - map from the id of a face to the id of the- // cluster to which it belongs.const faceIDToClusterID = new Map<string, string>();- // For fast reverse lookup - map from the id of a face to the index of its- // corresponding cluster in the clusters array.const faceIDToClusterIndex = new Map<string, number>();- // Fill in the maps with the existing data. Since the remote clusters come- // first, they'll be preferred over any existing local clusters for the same- // face (as is the desired behaviour).-+ // Remote assignments precede and override duplicate local assignments.for (const [i, cluster] of clusters.entries()) {for (const faceID of cluster.faces) {if (!faceIDToClusterID.has(faceID)) {@@ -161,8 +105,6 @@ export const _clusterFaces = async (}}- // IDs of the clusters which were modified. We use this information to- // determine which cgroups need to be updated on remote.const modifiedClusterIDs = new Set<string>();const state = {@@ -172,9 +114,7 @@ export const _clusterFaces = async (modifiedClusterIDs,};- // Process the faces in batches, but keep an overlap between batches to- // allow "links" to form with existing clusters.-+ // Overlap batches so clusters can link across their boundaries.const total = faces.length;const batchSize = 10000;const offsetIncrement = 7500;@@ -197,20 +137,13 @@ export const _clusterFaces = async (return { clusters, modifiedClusterIDs };};-/**- * A generator function that returns a stream of eligible {@link ClusterFace}s- * by flattening all the the faces present in the given {@link faceIndices}.- *- * During this, it also converts the embeddings to Float32Arrays to speed up the- * dot product calculations that will happen during clustering and attaches- * other information that the clustering algorithm needs.- */function* enumerateFaces(faceIndices: FaceIndex[]) {for (const fi of faceIndices) {for (const face of fi.faces) {if (face.blur > 10 && face.score > 0.8) {yield {...face,+ // Convert once; dot products are the hot path.embedding: new Float32Array(face.embedding),isBadFace: isBadFace(face),};@@ -219,21 +152,11 @@ function* enumerateFaces(faceIndices: FaceIndex[]) {}}-/**- * Sort faces by the local photo creation date of the file which contains them.- * The sorting is in descending order, so the newest file is first.- *- * Sorting faces temporally is meant as a heuristic for better clusters.- */const sortFacesNewestOnesFirst = (faces: ClusterFace[],localFiles: EnteFile[],) => {const localFileByID = new Map(localFiles.map((f) => [f.id, f]));- // In unexpected scenarios, we might run clustering without having the- // corresponding EnteFile available locally. This shouldn't happen, so log- // an warning, but meanwhile let the clustering proceed by assigning such- // files an arbitrary sort time.const sortTimeByFaceID = new Map<string, number>();for (const { faceID } of faces) {const file = localFileByID.get(fileIDFromFaceID(faceID)!);@@ -265,7 +188,6 @@ const isBadFace = (face: Face) =>const isSidewaysFace = (face: Face) =>faceDirection(face.detection) != "straight";-/** Generate a new cluster ID. */const newClusterID = () => newNonSecureID("cluster_");interface ClusteringState {@@ -291,47 +213,40 @@ const clusterBatchLinear = async ([[], []],);+ // Common incremental case; avoids the O(nΒ²) loop.if (!unclusteredFaces.length) {- // Optimization: early exit if nothing in batch is unclustered. In a- // single test (so it might be not be a universal benefit) of ~8k faces,- // it helped reduce the no-op time by 10x.onProgress({ completed: batch.length, total: batch.length });return;}- // Sort the faces so that the already clustered ones are at the front.+ // Existing clusters must come first because matches only look backward.const faces = clusteredFaces.concat(unclusteredFaces);- // For each face in the batchfor (const [i, fi] of faces.entries()) {if (i % 100 == 0) {onProgress({ completed: i, total: batch.length });- // See: [Note: Draining the event loop during clustering]+ // Yield so clustering does not block other worker requests.await wait(0);}- // If the face is already part of a cluster, then skip it.if (state.faceIDToClusterID.has(fi.faceID)) continue;const rejectedClusters = rejectedClusterIDsForFaceID.get(fi.faceID);- // Find the nearest neighbour among the previous faces in this batch.let nnIndex: number | undefined;let nnCosineSimilarity = 0;for (let j = i - 1; j >= 0; j--) {- // ! This is an O(n^2) loop, be careful when adding more code here.-+ // O(nΒ²): keep this loop minimal.const fj = faces[j]!;- // The vectors are already normalized, so we can directly use their- // dot product as their cosine similarity.+ // Embeddings are normalized, so this is cosine similarity.const csim = dotProduct(fi.embedding, fj.embedding);if (csim <= nnCosineSimilarity) continue;const threshold = fj.isBadFace ? 0.84 : 0.76;if (csim < threshold) continue;- // Don't add the face back to a cluster it has been rejected from.+ // Never return a face to a cluster the user rejected.if (rejectedClusters) {const cjx = state.faceIDToClusterIndex.get(fj.faceID);if (cjx !== undefined) {@@ -347,7 +262,6 @@ const clusterBatchLinear = async (}if (nnIndex !== undefined) {- // Found a neighbour close enough, add ourselves to its cluster.const nnFace = faces[nnIndex]!;const nnClusterIndex = state.faceIDToClusterIndex.get(nnFace.faceID,@@ -359,7 +273,6 @@ const clusterBatchLinear = async (nnCluster.faces.push(fi.faceID);state.modifiedClusterIDs.add(nnCluster.id);} else {- // No neighbour within the threshold. Create a new cluster.const clusterID = newClusterID();const clusterIndex = state.clusters.length;const cluster = { id: clusterID, faces: [fi.faceID] };@@ -372,25 +285,15 @@ const clusterBatchLinear = async (}};-/**- * Use the output of the clustering phase to (a) update any remote cgroups that- * have changed, and (b) update our locally persisted clusters.- *- * @param masterKey The user's master key (as a base64 string), required for- * updating the cgroups on remote if needed.- */export const reconcileClusters = async (clusters: FaceCluster[],modifiedClusterIDs: Set<string>,masterKey: string,) => {- // Index clusters by their ID for fast lookup.const clusterByID = new Map(clusters.map((c) => [c.id, c]));- // Get the existing remote cluster groups.const cgroups = await savedCGroups();- // Find the cgroups that have changed since we started.const changedCGroups = cgroups.map((cgroup) => {for (const cluster of cgroup.data.assigned) {@@ -399,9 +302,8 @@ export const reconcileClusters = async (...cgroup,data: {...cgroup.data,- // Map assigned cluster IDs to latest cluster objects.- // If any referenced cluster is missing, throw to avoid- // silently losing data or writing nulls to remote.+ // Missing assignments must fail; dropping them+ // would overwrite remote data.assigned: cgroup.data.assigned.map(({ id }) => {const c = clusterByID.get(id);if (!c)@@ -418,24 +320,20 @@ export const reconcileClusters = async (}).filter((g) => !!g);- // Update remote if needed.if (changedCGroups.length) {await updateOrCreateUserEntities("cgroup", changedCGroups, masterKey);log.info(`Updated ${changedCGroups.length} remote cgroups`);}- // Find which clusters are part of remote cgroups.const isRemoteClusterID = new Set<string>();for (const cgroup of cgroups) {for (const cluster of cgroup.data.assigned)isRemoteClusterID.add(cluster.id);}- // Locally save clusters that are not part of any remote cgroup.await saveFaceClusters(clusters.filter(({ id }) => !isRemoteClusterID.has(id)),);- // Refresh our local state if we'd updated remote.if (changedCGroups.length) await pullUserEntities("cgroup", masterKey);};diff --git a/web/packages/new/photos/services/ml/crop.ts b/web/packages/new/photos/services/ml/crop.tsindex 50f59a903f..49bc423eee 100644--- a/web/packages/new/photos/services/ml/crop.ts+++ b/web/packages/new/photos/services/ml/crop.ts@@ -4,23 +4,7 @@ import { fetchRenderableEnteFileBlob } from "./blob";import type { Box, FaceIndex } from "./face";import { clamp } from "./math";-/**- * Regenerate and locally save face crops for faces in the given file.- *- * Face crops (the rectangular regions of the original image where a particular- * face was detected) are not stored on remote and are generated on demand. On- * the client where the indexing occurred, they get generated during the face- * indexing pipeline itself. But we need to regenerate them locally if the user- * views that item on any other client.- *- * @param file The {@link EnteFile} whose face crops we want to generate.- *- * @param faceIndex The {@link FaceIndex} containing information about the faces- * detected in the given image.- *- * The generated face crops are saved in a local cache and can subsequently be- * retrieved from the {@link BlobCache} named "face-crops".- */+// Face crops are local-only and must be regenerated on other clients.export const regenerateFaceCrops = async (file: EnteFile,faceIndex: FaceIndex,@@ -35,20 +19,7 @@ export const regenerateFaceCrops = async (}};-/**- * Locally save the face crops that the native ML pipeline generated while- * indexing an image.- *- * @param faceCrops JPEG blobs of the face crops, index-aligned with the faces- * in {@link faceIndex}. Faces whose crop the native side could not generate- * have a `null` in their slot, and are skipped.- *- * @param faceIndex The {@link FaceIndex} containing information about the- * faces detected in the given image.- *- * The face crops are saved in a local cache and can subsequently be retrieved- * from the {@link BlobCache} named "face-crops".- */+// Native crops are index-aligned with faces; null slots must be skipped.export const saveFaceCropBlobs = async (faceCrops: (Uint8Array<ArrayBuffer> | null)[],faceIndex: FaceIndex,@@ -65,18 +36,6 @@ export const saveFaceCropBlobs = async ();};-/**- * Extract and locally save the face crops (the rectangle of the original image- * that contain the detected face) for each of the faces detected in an image.- *- * @param imageBitmap The original image.- *- * @param faceIndex The {@link FaceIndex} containing information about the faces- * detected in the given image.- *- * The face crops are saved in a local cache and can subsequently be retrieved- * from the {@link BlobCache} named "face-crops".- */export const saveFaceCrops = async (imageBitmap: ImageBitmap,faceIndex: FaceIndex,@@ -92,28 +51,16 @@ export const saveFaceCrops = async ();};-/**- * Return the face crops corresponding to each of the given face detections.- *- * @param imageBitmap The original image.- *- * @param faceBox A box (a rectangle relative to the image size) marking the- * bounds of face in the given image.- *- * @returns a JPEG blob.- */export const extractFaceCrop = (imageBitmap: ImageBitmap, faceBox: Box) => {const { width: imageWidth, height: imageHeight } = imageBitmap;- // The faceBox coordinates are normalized 0-1 relative to the image size,- // and we need to convert them back to absolute values first.+ // Detection boxes use normalized 0β1 coordinates.const faceX = faceBox.x * imageWidth;const faceY = faceBox.y * imageHeight;const faceWidth = faceBox.width * imageWidth;const faceHeight = faceBox.height * imageHeight;- // Calculate the crop values by adding some padding around the face and- // making sure it's centered.+ // Reduce padding symmetrically when a face is near an image edge.const regularPadding = 0.4;const minimumPadding = 0.1;const xCrop = faceX - faceWidth * regularPadding;@@ -128,7 +75,6 @@ export const extractFaceCrop = (imageBitmap: ImageBitmap, faceBox: Box) => {faceHeight * (1 + 2 * regularPadding) -2 * Math.min(yOvershoot, regularPadding - minimumPadding) * faceHeight;- // Prevent the crop from going out of image bounds.const x = clamp(xCrop, 0, imageWidth);const y = clamp(yCrop, 0, imageHeight);const width = clamp(widthCrop, 0, imageWidth - x);diff --git a/web/packages/new/photos/services/ml/math.ts b/web/packages/new/photos/services/ml/math.tsindex 4f786f5944..e46466950e 100644--- a/web/packages/new/photos/services/ml/math.ts+++ b/web/packages/new/photos/services/ml/math.ts@@ -1,62 +1,8 @@-/**- * Clamp {@link value} to between {@link min} and {@link max}, inclusive.- */export const clamp = (value: number, min: number, max: number) =>Math.min(max, Math.max(min, value));-/**- * Return the dot-product of two vectors.- *- * Dot product is the component-wise product of the corresponding elements of- * the two given vectors.- *- * Precondition: The two vectors must be of the same length.- *- * ---- *- * [Note: Dot product is cosine similarity for normalized vectors]- *- * The cosine similarity of two vectors is defined as- *- * dotProduct(v1, v2) / (norm(v1) * norm(v2));- *- * In particular, when both the vectors are normalized, this is equal to the dot- * product. When we're computing dot products in a hot loop, skipping over that- * unnecessary renormalization matters.- *- * When comparing embeddings we usually want is the cosine similarity, but if- * both the embeddings involved are already normalized, we can save the norm- * calculations and directly do their `dotProduct`.- *- * Such code is often on the hot path, so these optimizations help.- *- * ---- *- * [Note: Cosine similarity and cosine distance]- *- * The cosine similarity of two vectors is [-1, 1] (inclusive), indicating how- * similar (1), orthogonal (0) and dissimilar (1) the two vectors are in- * direction. A related concept is cosine distance, which is defined as- *- * 1 - cosine similarity- *- * in an attempt to convert it into a (pseudo) distance metric.- *- * ---- *- * [Note: Dot product performance]- *- * In theory, Wasm SIMD instructions should give us a huge boost for computing- * dot products. In practice, we can get to roughly around the same performance- * by using Float32Arrays instead of number[], and letting the JS JIT do the- * optimizations for us (This assertion was made on Chrome on macOS on Sep 2023,- * and may not hold in the future).- *- * We can get a further 2x speedup over this by using some library that directly- * uses the SIMD intrinsics provided by the architecture instead of limiting- * itself to Wasm's set. But that'll require bundling native code, so as a- * tradeoff to avoid complexity we currently leave that 1x on the table.- */+// ML callers use normalized embeddings, so this is cosine similarity there.+// Keep Float32Array and the simple loop; this runs on hot paths.export const dotProduct = (v1: Float32Array, v2: Float32Array) => {if (v1.length != v2.length)throw new Error(`Length mismatch ${v1.length} ${v2.length}`);diff --git a/web/packages/new/photos/services/ml/ml-data.ts b/web/packages/new/photos/services/ml/ml-data.tsindex a2d1f40f03..48398c13c2 100644--- a/web/packages/new/photos/services/ml/ml-data.ts+++ b/web/packages/new/photos/services/ml/ml-data.ts@@ -8,55 +8,10 @@ import { gunzip, gzip } from "../../utils/gzip";import type { RemoteCLIPIndex } from "./clip";import type { RemoteFaceIndex } from "./face";-/**- * The decrypted payload of a {@link RemoteFileData} for the "mldata"- * {@link FileDataType}.- *- * [Note: "mldata" format]- *- * The file data of type "mldata" contains various embeddings and other metadata- * generated by the ML indexing for a given file.- *- * For example, the face indexing process generates multiple face embeddings per- * file (one for each face), each with an associated detection box. So instead- * of storing just a singular embedding, the data is an entire face index- * structure containing multiple embeddings and associated data.- *- * Similarly, the CLIP indexing process generates a CLIP embedding with some- * associated data.- *- * All such indexes are merge into a single object of the form:- *- * {- * "face": ... the face indexing result ...- * "clip": ... the CLIP indexing result ...- * ... more in the future ...- * }- *- * which is then gzipped to get the plaintext data to upload.- *- * [Note: Preserve unknown ML data fields]- *- * The (unzipped) remote mldata can contain arbitrary keys at the top level- * apart from the ones that the current client knows about. We need to preserve- * these verbatim when we use {@link putMLData}.- *- * Thus we return two separate results from {@link fetchMLData}:- *- * - {@link RawRemoteMLData}: The original, unmodified JSON.- *- * - {@link ParsedRemoteMLData}: The particular fields that the current client- * knows about, parsed according to their expected structure.- *- * When integrating this information into our local state, we use the parsed- * version. And if we need to update the state on remote (e.g. if the current- * client notices an particular type of index was missing), then we use the- * original JSON as the base.- */export interface RemoteMLData {+ // Keep raw data when updating so unknown top-level keys survive.raw: RawRemoteMLData;parsed: ParsedRemoteMLData | undefined;- // See: [Note: PUT "mldata" version check]updatedAt: number | undefined;}@@ -67,30 +22,6 @@ export type ParsedRemoteMLData = Partial<{clip: RemoteCLIPIndex;}>;-/**- * Zod schema for the {@link RemoteFaceIndex} type.- *- * [Note: Duplicated Zod schema and TypeScript type]- *- * Usually we define a Zod schema, and then infer the corresponding TypeScript- * type for it using `z.infer`. This works great except that the docstrings- * don't show up: Docstrings get added to the Zod schema, but usually the code- * using the parsed data will reference the TypeScript type, and the docstrings- * added to the fields in the Zod schema won't show up.- *- * We usually live with this infelicity since the alternative is code- * duplication: Defining a TypeScript type (putting the docstrings therein)- * _and_ also a corresponding Zod schema. The duplication is needed because it- * is not possible to go the other way (TypeScript type => Zod schema).- *- * However, in some cases having when the TypeScript type under consideration is- * used pervasively in code, having a standalone TypeScript type with attached- * docstrings is worth the code duplication.- *- * Note that this'll just be syntactic duplication - if the two definitions get- * out of sync in the shape of the types they represent, the TypeScript compiler- * will flag it for us.- */const RemoteFaceIndex = z.object({version: z.number(),client: z.string(),@@ -116,11 +47,6 @@ const RemoteFaceIndex = z.object({),});-/**- * Zod schema for the {@link RemoteCLIPIndex} type.- *- * See: [Note: Duplicated Zod schema and TypeScript type]- */const RemoteCLIPIndex = z.object({version: z.number(),client: z.string(),@@ -128,32 +54,13 @@ const RemoteCLIPIndex = z.object({embedding: z.array(z.number()),});-/**- * Zod schema for the {@link RawRemoteMLData} type.- */const RawRemoteMLData = z.looseObject({});-/**- * Zod schema for the {@link ParsedRemoteMLData} type.- */const ParsedRemoteMLData = z.object({face: RemoteFaceIndex.nullish().transform(nullToUndefined),clip: RemoteCLIPIndex.nullish().transform(nullToUndefined),});-/**- * Fetch ML data for the given files from remote.- *- * @param filesByID A map containing the files whose ML data we want to fetch.- * Each entry is keyed the the file's ID, and the value is the file.- *- * @returns a map containing the (decrypted) ML data for each file for which- * remote returned the corresponding ML data.- *- * Each entry in the map is keyed by file's ID, and each value is a- * {@link RemoteMLData} that contains both the original JSON, and parsed- * representation of ML data keys that we know about.- */export const fetchMLData = async (filesByID: Map<number, EnteFile>,): Promise<Map<number, RemoteMLData>> => {@@ -181,9 +88,7 @@ export const fetchMLData = async (remoteMLDataFromJSONString(jsonString, updatedAt),);} catch (e) {- // This shouldn't happen. Best guess is that some client has- // uploaded a corrupted ML index. Ignore it so that it gets- // reindexed and uploaded correctly again.+ // Omit corrupt remote data so indexing replaces it.log.warn(`Ignoring unparseable ML data for file id ${fileID}`, e);}}@@ -203,18 +108,6 @@ const remoteMLDataFromJSONString = (return { raw, parsed, updatedAt };};-/**- * Update the ML data stored for given {@link file} on remote.- *- * This allows other clients to directly pull the ML data instead of needing to- * re-index.- *- * The data on remote will be replaced unconditionally, and it is up to the- * client (us) to ensure that we preserve the parts of the pre-existing ML data- * (if any) that we did not understand or touch.- *- * See: [Note: Preserve unknown ML data fields].- */export const putMLData = async (file: EnteFile,mlData: RawRemoteMLData,diff --git a/web/packages/new/photos/services/ml/worker-types.ts b/web/packages/new/photos/services/ml/worker-types.tsindex 3aef8d2da8..6ec531b340 100644--- a/web/packages/new/photos/services/ml/worker-types.ts+++ b/web/packages/new/photos/services/ml/worker-types.ts@@ -1,46 +1,10 @@-/**- * @file Types for the objects shared between the main thread and the ML worker.- */--/**- * Callbacks invoked by the worker at various points in the indexing and- * clustering pipeline to notify the main thread of events it might be- * interested in.- */export interface MLWorkerDelegate {- /**- * Called whenever the worker does some action that might need the UI state- * indicating the indexing or clustering status to be updated.- */workerDidUpdateStatus: () => void;- /**- * Called when the worker indexes some files, but then notices that the main- * thread was not awaiting the indexing (e.g. it was not initiated by the- * main thread during a sync, but happened because of a live upload).- *- * In such cases, it uses this method to inform the main thread that some- * files were indexed, so that it can update any dependent state (e.g.- * clusters).- *- * It doesn't always call this because otherwise the main thread would need- * some extra code to avoid updating the dependent state twice.- */+ // Awaited callers update dependent state themselves.workerDidUnawaitedIndex: () => void;- /**- * Called when the port that the worker was using to communicate with the- * ML utility process closes, which happens if the utility process exits- * (e.g. if it crashes). The worker is unusable after this point.- */+ // Losing the utility-process port makes this worker unusable.workerDidLoseElectronPort: () => void;}-/**- * The result of file ids that should be considered as matches for a particular- * search phrase, each with their associated score.- *- * This is a map of file (IDs) that should be shown in the search results.- * They're returned as a map from fileIDs to the scores they got (higher is- * better). This map will only contains entries whose score was above our- * minimum threshold.- */+// File ID to score; higher is better, and entries are already thresholded.export type CLIPMatches = Map<number, number>;diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.tsindex 1a5d3aa3b3..d23b0f0da1 100644--- a/web/packages/new/photos/services/search/index.ts+++ b/web/packages/new/photos/services/search/index.ts@@ -16,29 +16,16 @@ import type {} from "./types";import type { SearchWorker } from "./worker";-/**- * Cached instance of the {@link ComlinkWorker} that wraps our web worker.- */let _comlinkWorker: ComlinkWorker<typeof SearchWorker> | undefined;-/**- * Lazily created, cached, instance of {@link SearchWorker}.- */const worker = () => (_comlinkWorker ??= createComlinkWorker()).remote;-/**- * Create a new instance of a comlink worker that wraps a {@link SearchWorker}- * web worker.- */const createComlinkWorker = () =>new ComlinkWorker<typeof SearchWorker>("search",new Worker(new URL("worker.ts", import.meta.url)),);-/**- * Perform any logout specific cleanup for the search subsystem.- */export const logoutSearch = () => {if (_comlinkWorker) {_comlinkWorker.terminate();@@ -47,15 +34,9 @@ export const logoutSearch = () => {_localizedSearchData = undefined;};-/**- * Fetch any data that would be needed if the user were to search.- */export const searchDataSync = () =>worker().then((w) => ensureMasterKeyFromSession().then((k) => w.sync(k)));-/**- * Update the collections and files over which we should search.- */export const updateSearchCollectionsAndFiles = (collections: Collection[],collectionFiles: EnteFile[],@@ -77,18 +58,9 @@ export const updateSearchCollectionsAndFiles = ();};-/**- * Set the (named) people that we should search across.- */export const setSearchPeople = (people: NamedPerson[]) =>void worker().then((w) => w.setPeople(people));-/**- * Convert a search string into (annotated) suggestions that can be shown in the- * search results dropdown.- *- * @param searchString The string we want to search for.- */export const searchOptionsForString = async (searchString: string) => {const t = Date.now();const suggestions = await suggestionsForString(searchString);@@ -101,13 +73,10 @@ export const searchOptionsForString = async (searchString: string) => {};const suggestionsForString = async (searchString: string) => {- // Normalize it by trimming whitespace and converting to lowercase.const s = searchString.trim().toLowerCase();if (s.length == 0) return [];- // The CLIP matching code already runs in the ML worker, so let that run- // separately, in parallel with the rest of the search query construction in- // the search worker, then combine the two.+ // CLIP uses the ML worker, so run it alongside the search worker.const [clip, [restPre, restPost]] = await Promise.all([clipSuggestion(s, searchString).then((s) => s ?? []),worker().then((w) =>@@ -141,43 +110,18 @@ const suggestionsToOptions = (suggestions: SearchSuggestion[]) =>})),);-/**- * Return the list of {@link EnteFile}s (from amongst the previously set- * {@link SearchCollectionsAndFiles}) that match the given search {@link suggestion}.- */export const filterSearchableFiles = async (suggestion: SearchSuggestion) =>worker().then((w) => w.filterSearchableFiles(suggestion));-/**- * A batched variant of {@link filterSearchableFiles}.- *- * This has drastically (10x) better performance when filtering files for a- * large number of suggestions (e.g. single letter searches that lead to a large- * number of city prefix matches), likely because of reduced worker IPC.- */+// Batching avoids per-suggestion worker IPC and is about 10Γ faster for broad searches.const filterSearchableFilesMulti = async (suggestions: SearchSuggestion[]) =>worker().then((w) => w.filterSearchableFilesMulti(suggestions));-/**- * Cached value of {@link localizedSearchData}.- */let _localizedSearchData: LocalizedSearchData | undefined;-/*- * For searching, the web worker needs a bunch of otherwise static data that has- * names and labels formed by localized strings.- *- * Since it would be tricky to get the t() function to work in a web worker, we- * instead pass this from the main thread (lazily initialized and cached).- *- * Note that these need to be evaluated at runtime, and cannot be static- * constants since t() depends on the user's locale.- *- * We currently clear the cached data on logout, but this is not necessary. The- * only point we necessarily need to clear this data is if the user changes their- * preferred locale, but currently we reload the page in such cases so any in- * memory state would be reset that way.- */+// Workers cannot use t(), so build localized labels on the main thread.+// Build them at runtime because the locale is user-selected.+// Locale changes reload the page; logout explicitly clears this cache.const localizedSearchData = () =>(_localizedSearchData ??= {locale: i18n.language,@@ -185,9 +129,6 @@ const localizedSearchData = () =>labelledFileTypes: labelledFileTypes(),});-/**- * A list of holidays - their yearly dates and localized names.- */const holidays = (): LabelledSearchDateComponents[] => [{ components: { month: 12, day: 25 }, label: t("christmas") },{ components: { month: 12, day: 24 }, label: t("christmas_eve") },@@ -195,9 +136,6 @@ const holidays = (): LabelledSearchDateComponents[] => [{ components: { month: 12, day: 31 }, label: t("new_year_eve") },];-/**- * A list of file types with their localized names.- */const labelledFileTypes = (): LabelledFileType[] => [{ fileType: FileType.image, label: t("image") },{ fileType: FileType.video, label: t("video") },diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.tsindex 81c3f2ac5e..a3b0ca19bc 100644--- a/web/packages/new/photos/services/search/types.ts+++ b/web/packages/new/photos/services/search/types.ts@@ -1,8 +1,3 @@-/**- * @file types shared between the main thread interface to search (`index.ts`)- * and the search worker that does the actual searching (`worker.ts`).- */-import type { Location } from "ente-base/types";import type { Collection } from "ente-media/collection";import type { EnteFile } from "ente-media/file";@@ -10,19 +5,6 @@ import { FileType } from "ente-media/file-type";import type { Person } from "ente-new/photos/services/ml/people";import type { LocationTag } from "../user-entity";-/**- * Represents the unique identifiers for various sidebar actions in the application.- *- * These IDs are organized into categories:- * - `shortcuts.*`: Quick access actions like uncategorized items, archive, hidden items, and trash- * - `utility.*`: General utility actions such as account management, folder watching, deduplication, preferences, help, export, and logout- * - `account.*`: Account-specific settings including recovery key, two-factor authentication, passkeys, password/email management, and account deletion- * - `preferences.*`: User preference options like language, theme, app lock, custom domains, map settings, advanced options, ML search, and streamable videos- * - `help.*`: Help-related actions including help center, blog, feature requests, support, log viewing, and test upload- *- * @remarks- * This type is used to ensure type safety when referencing sidebar actions throughout the application.- */export type SidebarActionID =| "shortcuts.uncategorized"| "shortcuts.archive"@@ -63,12 +45,6 @@ export type SidebarActionID =| "help.support"| "help.viewLogs";-/**- * A search suggestion.- *- * These (wrapped up in {@link SearchOption}s) are shown in the search results- * dropdown, and can also be used to filter the list of files that are shown.- */export type SearchSuggestion = { label: string } & (| { type: "collection"; collectionID: number }| { type: "fileType"; fileType: FileType }@@ -84,43 +60,17 @@ export type SearchSuggestion = { label: string } & (| { type: "sidebarAction"; actionID: SidebarActionID; path: string[] });-/**- * An option shown in the the search bar's select dropdown.- *- * The {@link SearchOption} wraps a {@link SearchSuggestion} with some metadata- * used when showing a corresponding entry in the dropdown.- *- * If the user selects the option, then we will re-run the search using the- * {@link suggestion} to filter the list of files shown to the user.- */export interface SearchOption {suggestion: SearchSuggestion;- /**- * The count of files that matched the search option when it was initially- * computed.- */fileCount: number;previewFiles: EnteFile[];}-/**- * The collections and files over which we should search.- */export interface SearchCollectionsAndFiles {collections: Collection[];- /**- * Unique files (by ID).- *- * @see {@link uniqueFilesByID}.- */+ // Unique by file ID.files: EnteFile[];- /**- * One entry per collection/file pair.- *- * Whenever the same file (ID) is in multiple collections, the- * {@link collectionFiles} will have multiple entries with the same file ID,- * one per collection in which that file (ID) occurs.- */+ // One entry per collection membership.collectionFiles: EnteFile[];}@@ -134,55 +84,23 @@ export interface LabelledFileType {label: string;}-/**- * Various bits of static but locale specific data that the search worker needs- * during searching.- */export interface LocalizedSearchData {locale: string;holidays: LabelledSearchDateComponents[];labelledFileTypes: LabelledFileType[];}-/**- * A parsed version of a potential natural language date time string.- *- * All attributes which were parsed will be set. The type doesn't enforce this,- * but it is guaranteed that at least one attribute will be present.- */+// At least one component is always present.+// The type cannot enforce this.export interface SearchDateComponents {- /**- * The year, if the search string specified one. e.g. `2024`.- */year?: number;- /**- * The month (1 to 12, with December being 12), if the search string- * specified one.- */+ // 1-12.month?: number;- /**- * The day of the month (1 to 31), if the search string specified one.- */day?: number;- /**- * The day of the week (0 to 6, with Sunday being 0), if the search string- * specified one.- */+ // 0-6, starting with Sunday.weekday?: number;- /**- * The hour of the day (0 to 23, with 0 as midnight), if the search string- * specified one.- */+ // 0-23.hour?: number;}-/**- * A city as identified by a static dataset.- *- * Each city is represented by its latitude and longitude. The dataset does not- * have information about the city's estimated radius.- */-export type City = Location & {- /** Name of the city. */- name: string;-};+export type City = Location & { name: string };diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.tsindex 3db73ccf4b..6fb31c0c1a 100644--- a/web/packages/new/photos/services/search/worker.ts+++ b/web/packages/new/photos/services/search/worker.ts@@ -31,10 +31,6 @@ import type {SearchSuggestion,} from "./types";-/**- * A web worker that runs the search asynchronously so that the main thread- * remains responsive.- */export class SearchWorker {private locationTags: LocationTag[] = [];private cities: City[] = [];@@ -45,16 +41,7 @@ export class SearchWorker {};private people: NamedPerson[] = [];- /**- * Fetch any state we might need when the actual search happens.- *- * @param masterKey The user's master key (as a base64 string). Web workers- * do not have access to session storage so this key needs to be passed to- * us explicitly.- */async sync(masterKey: string) {- // Let the cities fetch complete async. And do it only once per app- // startup (this list is static and doesn't change).if (this.cities.length == 0) {void fetchCities().then((cs) => (this.cities = cs));}@@ -64,33 +51,22 @@ export class SearchWorker {.then((ts) => (this.locationTags = ts));}- /**- * Set the collections and files that we should search across.- */setCollectionsAndFiles(cf: SearchCollectionsAndFiles) {this.collectionsAndFiles = cf;}- /**- * Set the (named) people that we should search across.- */setPeople(people: NamedPerson[]) {this.people = people;}- /**- * Convert a search string into a list of {@link SearchSuggestion}s.- */suggestionsForString(s: string,searchString: string,localizedSearchData: LocalizedSearchData,) {+ // \b does not handle Unicode word boundaries.return suggestionsForString(s,- // Case insensitive word prefix match. Note that \b doesn't work- // with unicode characters, so we use instead a set of common- // punctuation (and spaces) to discern the word boundary.new RegExp("(^|[\\s.,!?\"'-_])" + s, "i"),searchString,this.collectionsAndFiles,@@ -101,16 +77,10 @@ export class SearchWorker {);}- /**- * Return {@link EnteFile}s that satisfy the given {@link suggestion}.- */filterSearchableFiles(suggestion: SearchSuggestion) {return filterSearchableFiles(this.collectionsAndFiles, suggestion);}- /**- * Batched variant of {@link filterSearchableFiles}.- */filterSearchableFilesMulti(suggestions: SearchSuggestion[]) {const cf = this.collectionsAndFiles;return suggestions@@ -123,10 +93,7 @@ expose(SearchWorker);logUnhandledErrorsAndRejectionsInWorker();-/**- * @param s The normalized form of {@link searchString}.- * @param searchString The original search string.- */+// The caller inserts CLIP suggestions between these two groups.const suggestionsForString = (s: string,re: RegExp,@@ -138,7 +105,6 @@ const suggestionsForString = (cities: City[],): [SearchSuggestion[], SearchSuggestion[]] => [[peopleSuggestions(re, people)].flat(),- // . <-- clip suggestions will be inserted here by our caller.[fileTypeSuggestions(re, labelledFileTypes),dateSuggestions(s, re, locale, holidays),@@ -177,8 +143,6 @@ const fileNameSuggestion = (searchString: string,files: EnteFile[],): SearchSuggestion[] => {- // Convert the search string to a number. This allows searching a file by- // its exact (integral) ID.const sn = Number(s) || undefined;const fileIDs = files@@ -278,20 +242,6 @@ const dateSuggestions = (}),);-/**- * Try to parse an arbitrary search string into sets of date components.- *- * e.g. "December 2022" will be parsed into a- *- * [(year 2022, month 12, day undefined)]- *- * while "22 December 2022" will be parsed into- *- * [(year 2022, month 12, day 22)]- *- * In addition, also return a formatted representation of the "best" guess at- * the date that was intended by the search string.- */const parseDateComponents = (s: string,re: RegExp,@@ -308,23 +258,15 @@ const parseChrono = (s: string,locale: string,): LabelledSearchDateComponents[] => {- // Use the appropriate chrono parser based on locale- // For US locales, use the default parser (MM/DD/YYYY)- // For other locales, use the GB parser (DD/MM/YYYY)const isUSLocale =locale.toLowerCase().includes("en-us") || locale.toLowerCase() === "en";- // Select the appropriate chrono instance based on localelet chronoInstance;if (isUSLocale) {- // For US locale, use the default chrono parser (MM/DD/YYYY)chronoInstance = chrono;} else {- // For non-US locales, use GB parser (DD/MM/YYYY) and add DD.MM.YYYY supportchronoInstance = new chrono.Chrono(chrono.en.GB);- // Add parser for DD.MM.YYYY format (common in Germany, Switzerland, etc.)- // This format uses dots as separators instead of slasheschronoInstance.parsers.push({pattern: () => /\b(\d{1,2})\.(\d{1,2})\.(\d{2,4})\b/,extract: (_context, match) => {@@ -334,12 +276,10 @@ const parseChrono = (const month = parseInt(match[2]);let year = parseInt(match[3]);- // Handle 2-digit yearsif (year < 100) {year = year > 50 ? 1900 + year : 2000 + year;}- // Validate the dateif (day < 1 || day > 31 || month < 1 || month > 12) {return null;}@@ -382,9 +322,8 @@ const parseChrono = (.filter((x) => x !== undefined);};-/** chrono does not parse years like "2024", so do it manually. */+// chrono does not parse bare years such as "2024".const parseYearComponents = (s: string): LabelledSearchDateComponents[] => {- // s is already trimmed.if (s.length == 4) {const year = parseInt(s);if (year && year <= 9999) {@@ -395,11 +334,6 @@ const parseYearComponents = (s: string): LabelledSearchDateComponents[] => {return [];};-/**- * Zod schema describing world_cities.json.- *- * The entries also have a country field which we don't currently use.- */const RemoteWorldCities = z.object({data: z.array(z.object({ city: z.string(), lat: z.number(), lng: z.number() }),@@ -461,9 +395,6 @@ const filterSearchableFiles = ();};-/**- * Return true if file satisfies the given {@link query}.- */const isMatchingFile = (file: EnteFile, suggestion: SearchSuggestion) => {switch (suggestion.type) {case "collection":@@ -515,12 +446,9 @@ const isDateComponentsMatch = ({ year, month, day, weekday, hour }: SearchDateComponents,date: Date,) => {- // Components are guaranteed to have at least one attribute present, so- // start by assuming true.let match = true;if (year) match = date.getFullYear() == year;- // JS getMonth is 0-indexed.if (match && month) match = date.getMonth() + 1 == month;if (match && day) match = date.getDate() == day;if (match && weekday) match = date.getDay() == weekday;@@ -561,19 +489,11 @@ const isWithinRadius = (*/const radiusScaleFactor = (lat: number) => 1 / Math.cos(lat * (Math.PI / 180));-/**- * Sort the files if necessary.- *- * Currently, only the CLIP results are sorted (by their score), in the other- * cases the files are displayed chronologically (when displaying them in search- * results) or arbitrarily (when showing them in the search option preview).- */const sortMatchesIfNeeded = (files: EnteFile[],suggestion: SearchSuggestion,) => {if (suggestion.type != "clip") return files;- // Sort CLIP matches by their corresponding scores.const score = ({ id }: EnteFile) => suggestion.clipScoreForFileID.get(id)!;return files.sort((a, b) => score(b) - score(a));};diff --git a/web/packages/new/photos/services/settings.ts b/web/packages/new/photos/services/settings.tsindex afe3922da6..f96fb67439 100644--- a/web/packages/new/photos/services/settings.ts+++ b/web/packages/new/photos/services/settings.ts@@ -1,7 +1,3 @@-/**- * @file Storage (in-memory, local, remote) and update of various settings.- */-import log from "ente-base/log";import {updateChecksumProtectedUploadsEnabled,@@ -15,90 +11,13 @@ import {updateRemoteValue,} from "./remote-store";-/**- * In-memory flags that tracks various settings.- *- * Some of these are local only, some of these are synced with remote.- *- * [Note: Remote flag lifecycle]- *- * At a high level, this is how the app manages remote flags:- *- * 1. On app start, the initial are read from local storage in- * {@link initSettings}.- *- * 2. During the remote pull, remote flags are fetched and saved in local- * storage, and the in-memory state updated to reflect the latest values- * ({@link pullSettings}).- *- * 3. Updating a value also cause an unconditional fetch and update- * ({@link pullSettings}).- *- * 4. The individual getter functions for the flags (e.g.- * {@link isInternalUser}) return the in-memory values, and so are suitable- * for frequent use during UI rendering.- *- * 5. Everything gets reset to the default state on {@link logoutSettings}.- */export interface Settings {- /**- * `true` if the current user is an internal user.- */isInternalUser: boolean;-- /**- * `true` if maps are enabled.- */mapEnabled: boolean;-- /**- * `true` if the user has saved a preference to disable workers for uploads.- *- * Unlike {@link shouldDisableCFUploadProxy}, whose value reflects other- * factors that are taken into account to determine the effective value of- * this setting, this function returns only the saved user preference.- */cfUploadProxyDisabled: boolean;-- /**- * The URL we should ask the user to open should they wish to pair with the- * the cast app by manually entering a pairing code.- *- * Changing this only ever makes sense for self-hosters, who might want to- * point to their own self hosted cast app (See `apps.cast` in `local.yaml`- * in the museum code).- *- * Default: "https://cast.ente.com"- */castURL: string;-- /**- * The URL for the embed app used for embedded sharing.- *- * Changing this only ever makes sense for self-hosters, who might want to- * point to their own self hosted embed app (See `apps.embed-albums` in- * `local.yaml` in the museum code).- *- * Default: "https://embed.ente.com"- */embedURL: string;-- /**- * Set to the domain (host, e.g. "photos.example.org") that the user wishes- * to use for sharing their public albums.- *- * An empty string is treated as `undefined`.- */customDomain?: string;-- /**- * The URL we should ask the user to CNAME their {@link customDomain} to- * for wiring up their domain to the public albums app.- *- * See also `apps.custom-domain.cname` in `server/local.yaml`.- *- * Default: "my.ente.com"- */customDomainCNAME: string;}@@ -111,38 +30,17 @@ const createDefaultSettings = (): Settings => ({customDomainCNAME: "my.ente.com",});-/**- * Internal in-memory state shared by the functions in this module.- *- * This entire object will be reset on logout.- */class SettingsState {constructor() {this.settingsSnapshot = createDefaultSettings();}- /**- * Subscriptions to {@link Settings} updates attached using- * {@link settingsSubscribe}.- */settingsListeners: (() => void)[] = [];-- /**- * Snapshot of the {@link Settings} returned by the {@link settingsSnapshot}- * function.- */settingsSnapshot: Settings;}-/** State shared by the functions in this module. See {@link SettingsState}. */let _state = new SettingsState();-/**- * Read in the locally persisted settings into memory, but otherwise do not- * initiate any network requests to fetch the latest values.- *- * This assumes that the user is already logged in.- */export const initSettings = () => {void updateShouldDisableCFUploadProxy(savedCFProxyDisabled());syncSettingsSnapshotWithLocalStorage();@@ -153,13 +51,8 @@ export const logoutSettings = () => {updateChecksumProtectedUploadsEnabled(false);};-/**- * Fetch remote flags from remote and save them in local storage for subsequent- * lookup. Then use the results to update our in memory state if needed.- */export const pullSettings = async () => {const jsonString = await fetchFeatureFlags().then((res) => res.text());- // Do a parse as a sanity check before saving the string contents.FeatureFlags.parse(JSON.parse(jsonString));saveRemoteFeatureFlagsJSONString(jsonString);syncSettingsSnapshotWithLocalStorage();@@ -207,11 +100,6 @@ const syncSettingsSnapshotWithLocalStorage = () => {setSettingsSnapshot(settings);};-/**- * A function that can be used to subscribe to updates to {@link Settings}.- *- * See: [Note: Snapshots and useSyncExternalStore].- */export const settingsSubscribe = (onChange: () => void): (() => void) => {_state.settingsListeners.push(onChange);return () => {@@ -221,11 +109,6 @@ export const settingsSubscribe = (onChange: () => void): (() => void) => {};};-/**- * Return the last known, cached {@link Settings}.- *- * See also {@link settingsSubscribe}.- */export const settingsSnapshot = () => _state.settingsSnapshot;const setSettingsSnapshot = (snapshot: Settings) => {@@ -233,20 +116,11 @@ const setSettingsSnapshot = (snapshot: Settings) => {_state.settingsListeners.forEach((l) => l());};-/**- * Persist the user's custom domain preference both locally and on remote.- *- * Setting the value to a blank string is equivalent to deleting the custom- * domain value altogether.- */export const updateCustomDomain = async (customDomain: string) => {await updateRemoteValue("customDomain", customDomain);return pullSettings();};-/**- * Persist the user's map enabled preference both locally and on remote.- */export const updateMapEnabled = async (isEnabled: boolean) => {const previousSnapshot = _state.settingsSnapshot;@@ -274,8 +148,7 @@ const savedCFProxyDisabled = () => {if (!v) return false;if (v == "1") return true;- // Older versions of the app used to store this flag in a different- // format, so see if this is one of those, and if so, migrate it too.+ // Migrate the legacy { value: boolean } encoding.try {const value = z.object({ value: z.boolean() })@@ -289,10 +162,6 @@ const savedCFProxyDisabled = () => {}};-/**- * Save the user preference for disabling uploads via Cloudflare Workers, also- * notifying the upload subsystem of the change.- */export const updateCFProxyDisabledPreference = async (value: boolean) => {saveCFProxyDisabled(value);await updateShouldDisableCFUploadProxy(value);diff --git a/web/packages/new/photos/services/social.ts b/web/packages/new/photos/services/social.tsindex 2a61427e07..07eaec42de 100644--- a/web/packages/new/photos/services/social.ts+++ b/web/packages/new/photos/services/social.ts@@ -4,21 +4,15 @@ import { apiURL } from "ente-base/origins";import { z } from "zod";import type { Comment } from "./comment";-/**- * Remove null byte padding from a decrypted reaction type.- */const unpadReaction = (paddedReaction: string): string =>paddedReaction.replace(/\0+$/, "");-/**- * A decrypted reaction from the unified diff endpoint.- */export interface UnifiedReaction {id: string;collectionID: number;fileID?: number;commentID?: string;- /** True if this reaction is on a reply (only in feed responses). */+ // Only present in feed responses.isCommentReply?: boolean;reactionType: string;userID: number;@@ -28,9 +22,6 @@ export interface UnifiedReaction {updatedAt: number;}-/**- * Result from the unified social diff endpoint.- */export interface UnifiedSocialDiff {comments: Comment[];reactions: UnifiedReaction[];@@ -38,14 +29,6 @@ export interface UnifiedSocialDiff {hasMoreReactions: boolean;}-/**- * Get comments and reactions for a file in a single request.- *- * @param collectionID The ID of the collection containing the file.- * @param fileID The ID of the file to get social data for.- * @param collectionKey The decrypted collection key (base64 encoded).- * @returns Comments and reactions for the file.- */export const getUnifiedSocialDiff = async (collectionID: number,fileID: number,@@ -64,19 +47,8 @@ export const getUnifiedSocialDiff = async (return decryptSocialDiff(collectionKey, await res.json());};-/**- * Get album feed - comments and reactions relevant to the current user.- *- * This uses a server-side filtered endpoint that only returns:- * - Comments on files owned by the user (excluding user's own comments)- * - Replies to user's comments- * - Reactions on files owned by the user- * - Reactions on user's comments- *- * @param collectionID The ID of the collection.- * @param collectionKey The decrypted collection key (base64 encoded).- * @returns Filtered comments and reactions for the user's feed.- */+// Remote filters this feed to activity relevant to the current user.+// This includes replies or reactions to them and activity on files they own.export const getAlbumFeed = async (collectionID: number,collectionKey: string,@@ -93,16 +65,12 @@ export const getAlbumFeed = async (return decryptSocialDiff(collectionKey, await res.json());};-/**- * Decrypt comments and reactions from the unified diff endpoint response.- */const decryptSocialDiff = async (collectionKey: string,responseJson: unknown,): Promise<UnifiedSocialDiff> => {const data = UnifiedDiffResponse.parse(responseJson);- // Decrypt commentsconst comments: Comment[] = [];for (const comment of data.comments) {if (comment.isDeleted || !comment.cipher || !comment.nonce) {@@ -148,7 +116,6 @@ const decryptSocialDiff = async (}}- // Decrypt reactionsconst reactions: UnifiedReaction[] = [];for (const reaction of data.reactions) {if (reaction.isDeleted || !reaction.cipher || !reaction.nonce) continue;@@ -226,13 +193,6 @@ const UnifiedDiffResponse = z.object({hasMoreReactions: z.boolean(),});-/**- * Get anonymous user profiles for a collection.- *- * @param collectionID The ID of the collection.- * @param collectionKey The decrypted collection key (base64 encoded).- * @returns Map of anonUserID to decrypted userName.- */export const getAnonProfiles = async (collectionID: number,collectionKey: string,diff --git a/web/packages/new/photos/services/user-entity/index.ts b/web/packages/new/photos/services/user-entity/index.tsindex 6a4dea2ce0..0432867897 100644--- a/web/packages/new/photos/services/user-entity/index.ts+++ b/web/packages/new/photos/services/user-entity/index.ts@@ -26,44 +26,16 @@ import {userEntityDiff,} from "./remote";-/**- * User entities are predefined lists of otherwise arbitrary data that the user- * can store for their account.- *- * e.g. location tags, cluster groups.- */-export type EntityType =- /**- * A location tag.- *- * The entity data is base64(encrypt(json))- */- | "location"- /**- * A cluster group.- *- * The entity data is base64(encrypt(gzip(json)))- */- | "cgroup";+export type EntityType = "location" | "cgroup";-/**- * Zod schema for the fields of interest in the location tag that we get from- * remote.- */const RemoteLocationTagData = z.looseObject({name: z.string(),radius: z.number(),centerPoint: z.object({ latitude: z.number(), longitude: z.number() }),});-/**- * A view of the location tag data suitable for use by the rest of the app.- */export type LocationTag = z.infer<typeof RemoteLocationTagData>;-/**- * Return the list of locally available location tags.- */export const savedLocationTags = (): Promise<LocationTag[]> =>savedEntities("location").then((es) =>es.map((e) => RemoteLocationTagData.parse(e.data)),@@ -74,16 +46,8 @@ const RemoteFaceCluster = z.looseObject({faces: z.string().array(),});-/**- * Zod schema for the fields of interest in the cgroup that we get from remote.- *- * See also: {@link CGroupUserEntityData}.- *- * See: [Note: Use looseObject for metadata Zod schemas].- */const RemoteCGroupData = z.looseObject({name: z.string().nullish().transform(nullToUndefined),- // Accept nullish entries within the array and filter them out.assigned: z.array(RemoteFaceCluster.nullish()).nullish()@@ -100,39 +64,16 @@ const RemoteCGroupData = z.looseObject({hideFromMemories: z.boolean().nullish().transform(Boolean),});-/**- * A "cgroup" user entity.- */export type CGroup = Omit<LocalUserEntity, "data"> & {- // CGroupUserEntityData is meant to be a (documented) equivalent of- // `z.infer<typeof RemoteCGroup>`.+ // Keep this aligned with RemoteCGroupData.data: CGroupUserEntityData;};-/**- * Return the list of locally available cgroup user entities.- */export const savedCGroups = (): Promise<CGroup[]> =>savedEntities("cgroup").then((es) =>es.map((e) => ({ ...e, data: RemoteCGroupData.parse(e.data) })),);-/**- * Update our local entities of the given {@link type} by pulling the latest- * changes from remote.- *- * This fetches all the user entities corresponding to the given user entity- * type from remote that have been created, updated or deleted since the last- * time we checked.- *- * This diff is then applied to the data we have persisted locally.- *- * It uses local state to remember the latest entry the last time it did a pull,- * so each subsequent pull is a lightweight diff.- *- * @param masterKey The user's masterKey (as a base64 string), which is is used- * to encrypt and decrypt the entity key.- */export const pullUserEntities = async (type: EntityType, masterKey: string) => {const entityKey = await getOrCreateEntityKey(type, masterKey);@@ -162,21 +103,9 @@ export const pullUserEntities = async (type: EntityType, masterKey: string) => {}};+// Location encrypts JSON; cgroup encrypts gzipped JSON.const isGzipped = (type: EntityType) => type == "cgroup";-/**- * Create a new user entity of the given {@link type}.- *- * @param data Arbitrary data associated with the entity. The format of the data- * is specific to each entity type, but the provided data should be JSON- * serializable (Typescript does not have a native JSON type, so we need to- * specify this as an `unknown`).- *- * @param masterKey The user's masterKey, which is is used to encrypt and- * decrypt the entity key.- *- * @returns The ID of the newly created entity.- */export const addUserEntity = async (type: EntityType,data: unknown,@@ -201,13 +130,6 @@ const encryptedUserEntityData = async (return encryptBlob(bytes, entityKey);};-/**- * Update the given user entities (both on remote and locally), creating them if- * they don't exist.- *- * @param masterKey The user's masterKey (as a base64 string), which is is used- * to encrypt and decrypt the entity key.- */export const updateOrCreateUserEntities = async (type: EntityType,entities: LocalUserEntity[],@@ -221,40 +143,19 @@ export const updateOrCreateUserEntities = async (),);-/**- * Return the entity key (base64 string) that can be used to decrypt the- * encrypted contents of user entities of the given {@link type}.- *- * 1. See if we have the encrypted entity key present locally. If so, return the- * entity key by decrypting it using with the user's master key.- *- * 2. Otherwise fetch the encrypted entity key for that type from remote. If we- * get one, obtain the entity key by decrypt the encrypted one using the- * user's master key, save it locally for future use, and return it.- *- * 3. Otherwise generate a new entity key, encrypt it using the user's master- * key, putting the encrypted one to remote and also saving it locally, and- * return it.- *- * See also, [Note: User entity keys].- */const getOrCreateEntityKey = async (type: EntityType, masterKey: string) => {- // See if we already have it locally.const saved = await savedRemoteUserEntityKey(type);if (saved) return decryptEntityKey(saved, masterKey);- // See if remote already has it.const existing = await getUserEntityKey(type);if (existing) {- // Only save it if we can decrypt it to avoid corrupting our local state- // in unforeseen circumstances.+ // Decrypt before caching so malformed remote data cannot poison local+ // state.const result = await decryptEntityKey(existing, masterKey);await saveRemoteUserEntityKey(type, existing);return result;}- // Nada. Create a new one, put it to remote, save it locally, and return.-// As a sanity check, generate the key but immediately encrypt it as if it// were fetched from remote and then try to decrypt it before doing anything// with it.@@ -270,23 +171,15 @@ const generateEncryptedEntityKey = async (masterKey: string) => {await generateBlobOrStreamKey(),masterKey,);- // Remote calls it the header, but it really is the nonce.+ // Museum calls this nonce "header".return { encryptedKey: encryptedData, header: nonce };};-/**- * Decrypt an encrypted entity key (as a base64 string) using the provided- * user's {@link masterKey}.- */const decryptEntityKey = async (remote: RemoteUserEntityKey,masterKey: string,) =>decryptBox(- {- encryptedData: remote.encryptedKey,- // Remote calls it the header, but it really is the nonce.- nonce: remote.header,- },+ { encryptedData: remote.encryptedKey, nonce: remote.header },masterKey,);diff --git a/web/packages/new/photos/services/user.ts b/web/packages/new/photos/services/user.tsindex 48be703d0b..4d3fc0c362 100644--- a/web/packages/new/photos/services/user.ts+++ b/web/packages/new/photos/services/user.ts@@ -7,9 +7,6 @@ import { ensureMasterKeyFromSession } from "ente-base/session";import { nullToUndefined } from "ente-utils/transform";import { z } from "zod";-/**- * Return the public/private keypair of the currently logged in user.- */export const ensureUserKeyPair = async (): Promise<KeyPair> => {const { encryptedSecretKey, secretKeyDecryptionNonce, publicKey } =ensureSavedKeyAttributes();@@ -20,12 +17,6 @@ export const ensureUserKeyPair = async (): Promise<KeyPair> => {return { publicKey, privateKey };};-/**- * 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 res = await fetch(await apiURL("/users/public-key", { email }), {headers: await authenticatedRequestHeaders(),@@ -35,9 +26,6 @@ export const getPublicKey = async (email: string) => {.publicKey;};-/**- * Fetch the two-factor status (whether or not it is enabled) from remote.- */export const get2FAStatus = async () => {const res = await fetch(await apiURL("/users/two-factor/status"), {headers: await authenticatedRequestHeaders(),@@ -46,9 +34,6 @@ export const get2FAStatus = async () => {return z.object({ status: z.boolean() }).parse(await res.json()).status;};-/**- * Disable two-factor authentication for the current user on remote.- */export const disable2FA = async () =>ensureOk(await fetch(await apiURL("/users/two-factor/disable"), {@@ -58,28 +43,10 @@ export const disable2FA = async () =>);const DeleteChallengeResponse = z.object({- // allowDelete indicates whether the user is allowed to delete their account- // via app (some special-cased accounts might need to contact support).allowDelete: z.boolean(),- // An encrypted challenge that the client needs to decrypt and provide in- // the actual account deletion request.encryptedChallenge: z.string().nullish().transform(nullToUndefined),});-/**- * Initiate an account deletion by obtaining a delete challenge from remote.- *- * Account deletion is a three step process:- *- * 1. Client obtains a encrypted challenge from remote by using- * {@link getAccountDeleteChallenge}.- *- * 2. Client asks the user to reverify their password to solve the challenge and- * obtain the decrypted challenge ({@link decryptDeleteAccountChallenge}).- *- * 3. Client performs the account deletion using the solved challenge- * ({@link deleteAccount}).- */export const getAccountDeleteChallenge = async () => {const res = await fetch(await apiURL("/users/delete-challenge"), {headers: await authenticatedRequestHeaders(),@@ -88,12 +55,6 @@ export const getAccountDeleteChallenge = async () => {return DeleteChallengeResponse.parse(await res.json());};-/**- * Decrypt the {@link encryptedChallenge} sent by remote during the delete- * account flow ({@link getAccountDeleteChallenge}), returning a value that can- * then directly be passed to the actual delete account request- * ({@link deleteAccount}).- */export const decryptDeleteAccountChallenge = async (encryptedChallenge: string,) =>@@ -101,13 +62,6 @@ export const decryptDeleteAccountChallenge = async (await boxSealOpenBytes(encryptedChallenge, await ensureUserKeyPair()),);-/**- * Delete the logged in user's account on remote.- *- * @param challenge Decrypted value of the challenge previously obtained via- * {@link getAccountDeleteChallenge}. The decryption algorithm is implemented in- * {@link decryptDeleteAccountChallenge}.- */export const deleteAccount = async (challenge: string,reason: string,