π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Deduplicate shared web helpers
Anand Baburajan6e94a5fc51c1
diff --git a/web/apps/albums/src/app/hooks/useNotification.ts b/web/apps/albums/src/app/hooks/useNotification.tsdeleted file mode 100644index 8d8cc56646..0000000000--- a/web/apps/albums/src/app/hooks/useNotification.ts+++ /dev/null@@ -1,30 +0,0 @@-import type { NotificationAttributes } from "ente-base/components/Notification";-import { useCallback, useState } from "react";--/**- * A React hook for simplifying the provisioning of a {@link showMiniDialog}- * function to inject in app contexts, and of the other props that are needed to- * be passed to the {@link AttributedMiniDialog}.- */-export const useNotification = () => {- const [attributes, setAttributes] = useState<- NotificationAttributes | undefined- >(undefined);-- const [open, setOpen] = useState(false);-- const showNotification = useCallback(- (attributes: NotificationAttributes) => {- setAttributes(attributes);- setOpen(true);- },- [],- );-- const handleClose = useCallback(() => setOpen(false), []);-- return {- showNotification,- notificationProps: { open, onClose: handleClose, attributes },- };-};diff --git a/web/apps/albums/src/app/providers/AlbumsAppProviders.tsx b/web/apps/albums/src/app/providers/AlbumsAppProviders.tsxindex ca44cf6307..7ca86731b0 100644--- a/web/apps/albums/src/app/providers/AlbumsAppProviders.tsx+++ b/web/apps/albums/src/app/providers/AlbumsAppProviders.tsx@@ -1,17 +1,19 @@import { AlbumsAppContext } from "@/app/context/albums-app-context";-import { useNotification } from "@/app/hooks/useNotification";import {LazyAttributedMiniDialog,LazyNotification,} from "@/app/lazy/global-ui";-import { ThemedLoadingBar } from "@/shared/ui/feedback/ThemedLoadingBar";import { CssBaseline } from "@mui/material";import { ThemeProvider } from "@mui/material/styles";import { staticAppTitle } from "ente-base/app";import { CustomHeadAlbums } from "ente-base/components/Head";import { LoadingIndicator } from "ente-base/components/loaders";+import { ThemedLoadingBar } from "ente-base/components/ThemedLoadingBar";import { useAttributedMiniDialog } from "ente-base/components/utils/dialog";-import { useSetupI18n } from "ente-base/components/utils/hooks-app";+import {+ useNotification,+ useSetupI18n,+} from "ente-base/components/utils/hooks-app";import { photosTheme } from "ente-base/components/utils/theme";import { useLoadingBar } from "ente-base/components/utils/use-loading-bar";import { BaseContext, deriveBaseContext } from "ente-base/context";diff --git a/web/apps/albums/src/public-album/data/utils/quick-link.ts b/web/apps/albums/src/public-album/data/utils/quick-link.tsdeleted file mode 100644index 15128ac288..0000000000--- a/web/apps/albums/src/public-album/data/utils/quick-link.ts+++ /dev/null@@ -1,54 +0,0 @@-import type { EnteFile } from "ente-media/file";-import { fileCreationTime } from "ente-media/file-metadata";--const shortMonths = [- "",- "Jan",- "Feb",- "Mar",- "Apr",- "May",- "Jun",- "Jul",- "Aug",- "Sep",- "Oct",- "Nov",- "Dec",-];--/**- * Date-range formatting used by quick-link naming (kept in mobile parity).- */-const quickLinkDateRangeForCreationTimes = (- firstCreationTime: number,- secondCreationTime: number,-) => {- const startTime = new Date(firstCreationTime / 1000);- const endTime = new Date(secondCreationTime / 1000);-- if (startTime.getFullYear() != endTime.getFullYear()) {- return `${shortMonths[startTime.getMonth() + 1]} ${startTime.getDate()}, ${startTime.getFullYear()} - ${shortMonths[endTime.getMonth() + 1]} ${endTime.getDate()}, ${endTime.getFullYear()}`;- }- if (startTime.getMonth() != endTime.getMonth()) {- return `${shortMonths[startTime.getMonth() + 1]} ${startTime.getDate()} - ${shortMonths[endTime.getMonth() + 1]} ${endTime.getDate()}, ${endTime.getFullYear()}`;- }- if (startTime.getDate() != endTime.getDate()) {- return `${shortMonths[startTime.getMonth() + 1]} ${startTime.getDate()} - ${shortMonths[endTime.getMonth() + 1]} ${endTime.getDate()}, ${endTime.getFullYear()}`;- }- return `${shortMonths[endTime.getMonth() + 1]} ${endTime.getDate()}, ${endTime.getFullYear()}`;-};--export const quickLinkDateRangeForFiles = (files: EnteFile[]) => {- if (!files.length) return undefined;-- let minCreationTime = Number.POSITIVE_INFINITY;- let maxCreationTime = Number.NEGATIVE_INFINITY;- for (const file of files) {- const creationTime = fileCreationTime(file);- if (creationTime < minCreationTime) minCreationTime = creationTime;- if (creationTime > maxCreationTime) maxCreationTime = creationTime;- }-- return quickLinkDateRangeForCreationTimes(minCreationTime, maxCreationTime);-};diff --git a/web/apps/albums/src/public-album/media/processing/convert.ts b/web/apps/albums/src/public-album/media/processing/convert.tsindex 45fefe7512..5e28e92a50 100644--- a/web/apps/albums/src/public-album/media/processing/convert.ts+++ b/web/apps/albums/src/public-album/media/processing/convert.ts@@ -3,7 +3,6 @@ import {renderableImageBlobWeb,} from "ente-gallery/services/convert-core";import type { EnteFile } from "ente-media/file";-import { convertToMP4 } from "./ffmpeg";export const renderableImageBlob = async (imageBlob: Blob,@@ -15,4 +14,9 @@ export const playableVideoURL = async (videoFileName: string,videoBlob: Blob,): Promise<string> =>- playableVideoURLWeb(videoFileName, videoBlob, { convertToMP4 });+ playableVideoURLWeb(videoFileName, videoBlob, {+ convertToMP4: async (blob) => {+ const ffmpeg = await import("ente-gallery/services/ffmpeg");+ return ffmpeg.convertToMP4(blob);+ },+ });diff --git a/web/apps/albums/src/public-album/media/processing/ffmpeg/constants.ts b/web/apps/albums/src/public-album/media/processing/ffmpeg/constants.tsdeleted file mode 100644index fb0d762e5b..0000000000--- a/web/apps/albums/src/public-album/media/processing/ffmpeg/constants.ts+++ /dev/null@@ -1,3 +0,0 @@-export const ffmpegPathPlaceholder = "FFMPEG";-export const inputPathPlaceholder = "INPUT";-export const outputPathPlaceholder = "OUTPUT";diff --git a/web/apps/albums/src/public-album/media/processing/ffmpeg/index.ts b/web/apps/albums/src/public-album/media/processing/ffmpeg/index.tsdeleted file mode 100644index 98ef4cabb3..0000000000--- a/web/apps/albums/src/public-album/media/processing/ffmpeg/index.ts+++ /dev/null@@ -1,156 +0,0 @@-import log from "ente-base/log";-import {- parseMetadataDate,- type ParsedMetadata,-} from "ente-media/file-metadata";-import {- ffmpegPathPlaceholder,- inputPathPlaceholder,- outputPathPlaceholder,-} from "./constants";-import { determineVideoDurationWeb, ffmpegExecWeb } from "./web";--/**- * Generate a thumbnail for the given video using the web FFmpeg worker.- */-export const generateVideoThumbnailWeb = async (blob: Blob) =>- _generateVideoThumbnail((seekTime: number) =>- ffmpegExecWeb(makeGenThumbnailCommand(seekTime), blob, "jpeg"),- );--const _generateVideoThumbnail = async (- thumbnailAtTime: (seekTime: number) => Promise<Uint8Array<ArrayBuffer>>,-): Promise<Uint8Array<ArrayBuffer>> => {- try {- return await thumbnailAtTime(1);- } catch {- return await thumbnailAtTime(0);- }-};--const makeGenThumbnailCommand = (seekTime: number) => ({- default: _makeGenThumbnailCommand(seekTime, false),- hdr: _makeGenThumbnailCommand(seekTime, true),-});--const _makeGenThumbnailCommand = (seekTime: number, forHDR: boolean) => [- ffmpegPathPlaceholder,- "-i",- inputPathPlaceholder,- "-ss",- `00:00:0${seekTime}`,- "-vframes",- "1",- "-vf",- [- "scale=-2:720",- forHDR- ? [- "zscale=transfer=linear",- "tonemap=tonemap=hable:desat=0",- "zscale=primaries=709:transfer=709:matrix=709",- ]- : [],- ]- .flat()- .join(","),- outputPathPlaceholder,-];--/**- * Extract ffmetadata from an uploaded video using the web FFmpeg worker.- */-export const extractVideoMetadata = async (- uploadItem: File,-): Promise<ParsedMetadata> =>- parseFFmpegExtractedMetadata(- await ffmpegExecWeb(extractVideoMetadataCommand, uploadItem, "txt"),- );--const extractVideoMetadataCommand = [- ffmpegPathPlaceholder,- "-i",- inputPathPlaceholder,- "-c",- "copy",- "-map_metadata",- "0",- "-f",- "ffmetadata",- outputPathPlaceholder,-];--const parseFFmpegExtractedMetadata = (ffmpegOutput: Uint8Array) => {- 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);-- const kv = new Map(kvPairs);- const result: ParsedMetadata = {};-- const creationDate =- parseFFMetadataDate(kv.get("com.apple.quicktime.creationdate")) ??- parseFFMetadataDate(kv.get("creation_time"));- if (creationDate) result.creationDate = creationDate;-- const location =- parseFFMetadataLocation(- kv.get("com.apple.quicktime.location.ISO6709"),- ) ?? parseFFMetadataLocation(kv.get("location"));- if (location) result.location = location;-- return result;-};--const parseFFMetadataLocation = (s: string | undefined) => {- if (!s) return undefined;-- const m = s.match(/(\+|-)\d+\.*\d+/g);- if (!m) {- log.warn(`Ignoring unparseable location string "${s}"`);- return undefined;- }-- const [latitude, longitude] = m.map(parseFloat);- if (!latitude || !longitude) {- log.warn(`Ignoring unparseable video metadata location string "${s}"`);- return undefined;- }-- return { latitude, longitude };-};--const parseFFMetadataDate = (s: string | undefined) => {- if (!s) return undefined;-- const d = parseMetadataDate(s);- if (!d) {- log.warn(`Ignoring unparseable video metadata date string "${s}"`);- return undefined;- }-- if (!d.timestamp) {- log.warn(`Ignoring zero video metadata date string "${s}"`);- return undefined;- }-- return d;-};--export const determineVideoDuration = async (- uploadItem: File,-): Promise<number> => determineVideoDurationWeb(uploadItem);--export const convertToMP4 = async (- blob: Blob,-): Promise<Blob | Uint8Array<ArrayBuffer>> => {- const command = [- ffmpegPathPlaceholder,- "-i",- inputPathPlaceholder,- "-preset",- "ultrafast",- outputPathPlaceholder,- ];- return ffmpegExecWeb(command, blob, "mp4");-};diff --git a/web/apps/albums/src/public-album/media/processing/ffmpeg/web.ts b/web/apps/albums/src/public-album/media/processing/ffmpeg/web.tsdeleted file mode 100644index 965aa2d931..0000000000--- a/web/apps/albums/src/public-album/media/processing/ffmpeg/web.ts+++ /dev/null@@ -1,339 +0,0 @@-import { FFFSType, FFmpeg } from "@ffmpeg/ffmpeg";-import { ensureArrayBufferBacked } from "ente-base/bytes";-import { joinPath } from "ente-base/file-name";-import { newID } from "ente-base/id";-import log from "ente-base/log";-import { PromiseQueue } from "ente-utils/promise";-import { z } from "zod";-import {- ffmpegPathPlaceholder,- inputPathPlaceholder,- outputPathPlaceholder,-} from "./constants";--type FFmpegCommand = string[] | { default: string[]; hdr: string[] };--/** Lazily initialized and loaded FFmpeg instance. */-let _ffmpeg: Promise<FFmpeg> | undefined;--/** Queue of in-flight requests. */-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 () => {- const ffmpeg = new FFmpeg();- await ffmpeg.load({- 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.- *- * @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> => {- const ffmpeg = await ffmpegLazy();- return _ffmpegTaskQueue.add(() =>- ffprobeExecVideoDuration(ffmpeg, blob),- ) as Promise<number>;-};--const ffmpegExec = async (- ffmpeg: FFmpeg,- command: FFmpegCommand,- outputFileExtension: string,- blob: Blob,-): Promise<Uint8Array<ArrayBuffer>> => {- 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) => {- try {- const startTime = Date.now();-- let resolvedCommand: string[];- if (Array.isArray(command)) {- resolvedCommand = command;- } else {- const isHDR = await isHDRVideo(ffmpeg, inputPath);- resolvedCommand = isHDR ? command.hdr : command.default;- }-- const cmd = substitutePlaceholders(- resolvedCommand,- inputPath,- outputPath,- );-- status = await ffmpeg.exec(cmd);- if (status !== 0) {- log.info(- `[wasm] ffmpeg command failed with exit code ${status}: ${cmd.join(" ")}`,- );- throw new Error(- `ffmpeg command failed with exit code ${status}`,- );- }-- const result = await ffmpeg.readFile(outputPath);- if (typeof result == "string")- throw new Error("Expected binary data");-- const ms = Date.now() - startTime;- log.debug(() => `[wasm] ffmpeg ${cmd.join(" ")} (${ms} ms)`);- return ensureArrayBufferBacked(result);- } finally {- try {- await ffmpeg.deleteFile(outputPath);- } catch (e) {- // Output file might not even exist if the command did not succeed,- // so only log on success.- if (status === 0) {- log.error(`Failed to remove output ${outputPath}`, e);- }- }- }- });-};--const withInputMount = async <T>(- ffmpeg: FFmpeg,- blob: Blob,- f: (inputPath: string) => Promise<T>,-): Promise<T> => {- const mountDir = "/mount";- const inputFileName = newID("in_");- const inputPath = joinPath(mountDir, inputFileName);-- const inputFile = new File([blob], inputFileName);-- try {- await ffmpeg.createDir(mountDir);- await ffmpeg.mount(FFFSType.WORKERFS, { files: [inputFile] }, mountDir);-- return await f(inputPath);- } finally {- try {- await ffmpeg.unmount(mountDir);- } catch (e) {- log.error(`Failed to remove mount ${mountDir}`, e);- }- try {- await ffmpeg.deleteDir(mountDir);- } catch (e) {- log.error(`Failed to delete mount directory ${mountDir}`, e);- }- }-};--const substitutePlaceholders = (- command: string[],- inputFilePath: string,- outputFilePath: string,-) =>- command- .map((segment) => {- if (segment == ffmpegPathPlaceholder) {- return undefined;- } else if (segment == inputPathPlaceholder) {- return inputFilePath;- } else if (segment == outputPathPlaceholder) {- return outputFilePath;- } else {- return segment;- }- })- .filter((s) => s !== undefined);--const FFProbeOutputIsHDR = z.object({- streams: z.array(z.object({ color_transfer: z.string().optional() })),-});--/**- * Determine whether the mounted video likely contains HDR transfer metadata.- *- * 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 {- jsonString = await ffprobeOutput(- 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.- ["-select_streams", "v:0"],- // Output JSON- ["-of", "json"],- ["-o", "output.json"],- ].flat(),- "output.json",- );-- const output = FFProbeOutputIsHDR.parse(JSON.parse(jsonString));- switch (output.streams[0]?.color_transfer) {- case "smpte2084":- case "arib-std-b67":- return true;- default:- return false;- }- } catch (e) {- log.warn("Could not detect HDR status", e);- if (jsonString) log.debug(() => ["ffprobe-output", jsonString]);- return false;- }-};--/**- * 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- if (status !== 0 && status != -1) {- log.info(- `[wasm] ffprobe command failed with exit code ${status}: ${cmd.join(" ")}`,- );- throw new Error(`ffprobe command failed with exit code ${status}`);- }-- const result = await ffmpeg.readFile(outputPath, "utf8");- if (typeof result != "string") throw new Error("Expected text data");-- return result;- } finally {- try {- await ffmpeg.deleteFile(outputPath);- } catch (e) {- // Output file might not even exist if the command did not succeed,- // so only log on success.- if (status !== 0 && status != -1) {- log.error(`Failed to remove output ${outputPath}`, e);- }- }- }-};--const FFProbeOutputDuration = z.object({- format: z.object({ duration: z.string() }),-});--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.-- const jsonString = await ffprobeOutput(- ffmpeg,- [- ["-i", inputPath],- ["-v", "error"],- ["-show_entries", "format=duration"],- ["-of", "json"],- ["-o", "output.json"],- ].flat(),- "output.json",- );-- const durationString = FFProbeOutputDuration.parse(- JSON.parse(jsonString),- ).format.duration;-- const duration = parseFloat(durationString);- if (isNaN(duration)) {- const msg = "Could not parse video duration";- log.warn(msg, durationString);- throw new Error(msg);- }- return duration;- });diff --git a/web/apps/albums/src/public-album/page/PublicAlbumPage.tsx b/web/apps/albums/src/public-album/page/PublicAlbumPage.tsxindex 252451a3ef..0d87f7b8a1 100644--- a/web/apps/albums/src/public-album/page/PublicAlbumPage.tsx+++ b/web/apps/albums/src/public-album/page/PublicAlbumPage.tsx@@ -17,7 +17,6 @@ import type { FileListHeaderOrFooter } from "@/public-album/components/FileList"import { FileListWithViewer } from "@/public-album/components/FileListWithViewer";import type { TripLayoutProps } from "@/public-album/components/TripLayout";import { setPublicAlbumsCredentials } from "@/public-album/data/auth/public-link-credentials";-import { quickLinkDateRangeForFiles } from "@/public-album/data/utils/quick-link";import { ActiveDownloadStatusNotifications } from "@/public-album/download/components/ActiveDownloadStatusNotifications";import { downloadManager } from "@/public-album/download/services/download-manager";import { thumbnailManager } from "@/public-album/media/thumbnails/thumbnail-manager";@@ -66,6 +65,7 @@ import {useSaveGroupsActions,type AddSaveGroup,} from "ente-gallery/components/utils/save-groups";+import { quickLinkDateRangeForFiles } from "ente-gallery/utils/quick-link";import type { Collection } from "ente-media/collection";import type { EnteFile } from "ente-media/file";import { fileFileName } from "ente-media/file-metadata";diff --git a/web/apps/albums/src/public-album/upload/pipeline/thumbnail.ts b/web/apps/albums/src/public-album/upload/pipeline/thumbnail.tsindex 7386de5f51..20787300eb 100644--- a/web/apps/albums/src/public-album/upload/pipeline/thumbnail.ts+++ b/web/apps/albums/src/public-album/upload/pipeline/thumbnail.ts@@ -1,5 +1,5 @@-import * as ffmpeg from "@/public-album/media/processing/ffmpeg";import log from "ente-base/log";+import * as ffmpeg from "ente-gallery/services/ffmpeg";import { FileType, type FileTypeInfo } from "ente-media/file-type";import { isHEICExtension } from "ente-media/formats";import { heicToJPEG } from "ente-media/heic-convert";diff --git a/web/apps/albums/src/public-album/upload/pipeline/upload-service.ts b/web/apps/albums/src/public-album/upload/pipeline/upload-service.tsindex 725902dd72..f27d546957 100644--- a/web/apps/albums/src/public-album/upload/pipeline/upload-service.ts+++ b/web/apps/albums/src/public-album/upload/pipeline/upload-service.ts@@ -1,10 +1,6 @@// TODO: Audit this file/* eslint-disable @typescript-eslint/ban-ts-comment */-import {- determineVideoDuration,- extractVideoMetadata,-} from "@/public-album/media/processing/ffmpeg";import type { BytesOrB64 } from "ente-base/crypto/types";import { streamEncryptionChunkSize } from "ente-base/crypto/types";import type { CryptoWorker } from "ente-base/crypto/worker";@@ -18,6 +14,10 @@ import {} from "ente-base/http";import log from "ente-base/log";import { extractExif } from "ente-gallery/services/exif";+import {+ determineVideoDuration,+ extractVideoMetadata,+} from "ente-gallery/services/ffmpeg";import { tryParseEpochMicrosecondsFromFileName } from "ente-gallery/services/upload/date";import { computeMd5Base64 } from "ente-gallery/services/upload/md5";import {diff --git a/web/apps/embed/src/pages/_app.tsx b/web/apps/embed/src/pages/_app.tsxindex f42b6921f6..fc0d1887e5 100644--- a/web/apps/embed/src/pages/_app.tsx+++ b/web/apps/embed/src/pages/_app.tsx@@ -2,6 +2,7 @@ import "@fontsource-variable/inter";import { CssBaseline } from "@mui/material";import { ThemeProvider } from "@mui/material/styles";import { CustomHead } from "ente-base/components/Head";+import { ThemedLoadingBar } from "ente-base/components/ThemedLoadingBar";import {useIsRouteChangeInProgress,useSetupI18n,@@ -11,7 +12,6 @@ import { photosTheme } from "ente-base/components/utils/theme";import { useLoadingBar } from "ente-base/components/utils/use-loading-bar";import { BaseContext, deriveBaseContext } from "ente-base/context";import { logStartupBanner } from "ente-base/log-web";-import { ThemedLoadingBar } from "ente-new/photos/components/ThemedLoadingBar";import { PhotosAppContext } from "ente-new/photos/types/context";import type { AppProps } from "next/app";import "photoswipe/dist/photoswipe.css";diff --git a/web/apps/photos/src/components/utils/hooks-app.ts b/web/apps/photos/src/components/utils/hooks-app.tsdeleted file mode 100644index 8d8cc56646..0000000000--- a/web/apps/photos/src/components/utils/hooks-app.ts+++ /dev/null@@ -1,30 +0,0 @@-import type { NotificationAttributes } from "ente-base/components/Notification";-import { useCallback, useState } from "react";--/**- * A React hook for simplifying the provisioning of a {@link showMiniDialog}- * function to inject in app contexts, and of the other props that are needed to- * be passed to the {@link AttributedMiniDialog}.- */-export const useNotification = () => {- const [attributes, setAttributes] = useState<- NotificationAttributes | undefined- >(undefined);-- const [open, setOpen] = useState(false);-- const showNotification = useCallback(- (attributes: NotificationAttributes) => {- setAttributes(attributes);- setOpen(true);- },- [],- );-- const handleClose = useCallback(() => setOpen(false), []);-- return {- showNotification,- notificationProps: { open, onClose: handleClose, attributes },- };-};diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsxindex 4cf092e519..41d87adc37 100644--- a/web/apps/photos/src/pages/_app.tsx+++ b/web/apps/photos/src/pages/_app.tsx@@ -1,4 +1,3 @@-import { useNotification } from "@/components/utils/hooks-app";import { useDesktopAppLockRoute } from "@/components/utils/use-app-lock-route";import { photosLogout } from "@/services/logout";import "@fontsource-variable/inter";@@ -19,9 +18,11 @@ import {} from "ente-base/components/loaders";import { AttributedMiniDialog } from "ente-base/components/MiniDialog";import { Notification } from "ente-base/components/Notification";+import { ThemedLoadingBar } from "ente-base/components/ThemedLoadingBar";import { useAttributedMiniDialog } from "ente-base/components/utils/dialog";import {useIsRouteChangeInProgress,+ useNotification,useSetupI18n,useSetupLogs,} from "ente-base/components/utils/hooks-app";@@ -36,7 +37,6 @@ import {isHLSGenerationSupported,} from "ente-gallery/services/video";import { AppLockReauthenticationDialog } from "ente-new/photos/components/app-lock/AppLockReauthenticationDialog";-import { ThemedLoadingBar } from "ente-new/photos/components/ThemedLoadingBar";import {updateAvailableForDownloadDialogAttributes,updateReadyToInstallDialogAttributes,diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex cb642fac95..bc4b4cd89d 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -136,7 +136,10 @@ import {performFileOp,type SelectedState,} from "@/utils/file";-import { quickLinkNameForFiles, resolveQuickLinkURL } from "@/utils/quick-link";+import {+ quickLinkNameForFiles,+ resolveQuickLinkURL,+} from "ente-gallery/utils/quick-link";import {savedCollectionFiles,savedCollections,diff --git a/web/package-lock.json b/web/package-lock.jsonindex 3f9f46d9be..1caf2de5fe 100644--- a/web/package-lock.json+++ b/web/package-lock.json@@ -11156,6 +11156,7 @@"react": "19.2.7","react-dom": "19.2.7","react-i18next": "16.6.6",+ "react-top-loading-bar": "3.0.2","zod": "4.4.3"},"devDependencies": {diff --git a/web/apps/albums/src/shared/ui/feedback/ThemedLoadingBar.tsx b/web/packages/base/components/ThemedLoadingBar.tsxsimilarity index 100%rename from web/apps/albums/src/shared/ui/feedback/ThemedLoadingBar.tsxrename to web/packages/base/components/ThemedLoadingBar.tsxdiff --git a/web/packages/base/components/utils/hooks-app.ts b/web/packages/base/components/utils/hooks-app.tsindex 3c738a1781..34f7b93f39 100644--- a/web/packages/base/components/utils/hooks-app.ts+++ b/web/packages/base/components/utils/hooks-app.ts@@ -1,8 +1,9 @@+import type { NotificationAttributes } from "ente-base/components/Notification";import { setupI18n } from "ente-base/i18n";import { disableDiskLogs } from "ente-base/log";import { logUnhandledErrorsAndRejections } from "ente-base/log-web";import { useRouter } from "next/router";-import { useEffect, useState } from "react";+import { useCallback, useEffect, useState } from "react";/*** A hook that initializes the localization library that we use.@@ -77,3 +78,31 @@ export const useIsRouteChangeInProgress = () => {return loading;};++/**+ * A React hook for simplifying the provisioning of a {@link showNotification}+ * function to inject in app contexts, and of the other props that are needed to+ * be passed to the {@link Notification}.+ */+export const useNotification = () => {+ const [attributes, setAttributes] = useState<+ NotificationAttributes | undefined+ >(undefined);++ const [open, setOpen] = useState(false);++ const showNotification = useCallback(+ (attributes: NotificationAttributes) => {+ setAttributes(attributes);+ setOpen(true);+ },+ [],+ );++ const handleClose = useCallback(() => setOpen(false), []);++ return {+ showNotification,+ notificationProps: { open, onClose: handleClose, attributes },+ };+};diff --git a/web/packages/base/package.json b/web/packages/base/package.jsonindex 8a2451cb06..2b592ffe3f 100644--- a/web/packages/base/package.json+++ b/web/packages/base/package.json@@ -21,6 +21,7 @@"react": "19.2.7","react-dom": "19.2.7","react-i18next": "16.6.6",+ "react-top-loading-bar": "3.0.2","zod": "4.4.3"},"devDependencies": {diff --git a/web/apps/photos/src/utils/quick-link.ts b/web/packages/gallery/utils/quick-link.tssimilarity index 100%rename from web/apps/photos/src/utils/quick-link.tsrename to web/packages/gallery/utils/quick-link.tsdiff --git a/web/packages/new/photos/components/ThemedLoadingBar.tsx b/web/packages/new/photos/components/ThemedLoadingBar.tsxdeleted file mode 100644index 315428b248..0000000000--- a/web/packages/new/photos/components/ThemedLoadingBar.tsx+++ /dev/null@@ -1,22 +0,0 @@-import { useTheme } from "@mui/material";-import type { LoadingBarController } from "ente-base/components/utils/use-loading-bar";-import React from "react";-import LoadingBar, { type LoadingBarRef } from "react-top-loading-bar";--interface ThemedLoadingBarProps {- ref: React.Ref<LoadingBarController>;-}-/**- * A wrapper over the {@link LoadingBar} library component that sets it to use- * the main accent color from the theme.- */-export const ThemedLoadingBar: React.FC<ThemedLoadingBarProps> = ({ ref }) => {- const theme = useTheme();-- return (- <LoadingBar- color={theme.vars.palette.accent.main}- ref={ref as React.Ref<LoadingBarRef>}- />- );-};