π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Prune comments in the cast app
Manav Rathi6ba1dd53d3f6
diff --git a/web/apps/cast/src/components/PairingCode.tsx b/web/apps/cast/src/components/PairingCode.tsxindex 89f91fab8a..fd8cf92b83 100644--- a/web/apps/cast/src/components/PairingCode.tsx+++ b/web/apps/cast/src/components/PairingCode.tsx@@ -2,26 +2,26 @@ import { styled } from "@mui/material";import React from "react";const colors = [- "#87CEFA", // Light Blue- "#90EE90", // Light Green- "#F08080", // Light Coral- "#FFFFE0", // Light Yellow- "#FFB6C1", // Light Pink- "#E0FFFF", // Light Cyan- "#FAFAD2", // Light Goldenrod- "#87CEFA", // Light Sky Blue- "#D3D3D3", // Light Gray- "#B0C4DE", // Light Steel Blue- "#FFA07A", // Light Salmon- "#20B2AA", // Light Sea Green- "#778899", // Light Slate Gray- "#AFEEEE", // Light Turquoise- "#7A58C1", // Light Violet- "#FFA500", // Light Orange- "#A0522D", // Light Brown- "#9370DB", // Light Purple- "#008080", // Light Teal- "#808000", // Light Olive+ "#87CEFA",+ "#90EE90",+ "#F08080",+ "#FFFFE0",+ "#FFB6C1",+ "#E0FFFF",+ "#FAFAD2",+ "#87CEFA",+ "#D3D3D3",+ "#B0C4DE",+ "#FFA07A",+ "#20B2AA",+ "#778899",+ "#AFEEEE",+ "#7A58C1",+ "#FFA500",+ "#A0522D",+ "#9370DB",+ "#008080",+ "#808000",];interface PairingCodeProps {@@ -35,9 +35,7 @@ export const PairingCode: React.FC<PairingCodeProps> = ({ code }) => {<spankey={i}style={{- // Alternating background.backgroundColor: i % 2 === 0 ? "#2e2e2e" : "#5e5e5e",- // Varying colors.color: colors[i % colors.length],}}>@@ -58,14 +56,8 @@ const PairingCode_ = styled("div")`line-height: 1.2;- /*- * - We want them to be spans so that when the text is copy pasted, there- * is no extra whitespace inserted.- *- * - But we also want them to have a block level padding.- *- * To achieve both these goals, make them inline-blocks- */+ /* inline-block: no extra whitespace when the code is copy pasted, while+ * still getting block level padding. */span {display: inline-block;padding: 0.5rem;diff --git a/web/apps/cast/src/pages/_app.tsx b/web/apps/cast/src/pages/_app.tsxindex 506fb7b033..2ffde8619d 100644--- a/web/apps/cast/src/pages/_app.tsx+++ b/web/apps/cast/src/pages/_app.tsx@@ -10,8 +10,6 @@ import React from "react";const App: React.FC<AppProps> = ({ Component, pageProps }) => {useSetupLogs({ disableDiskLogs: true });- // We don't provide BaseContext. Nothing in the cast app needs it yet.-return (<ThemeProvider theme={castTheme}><CustomHead title={staticAppTitle} />diff --git a/web/apps/cast/src/pages/index.tsx b/web/apps/cast/src/pages/index.tsxindex 81eb4212db..0add3ba4f2 100644--- a/web/apps/cast/src/pages/index.tsx+++ b/web/apps/cast/src/pages/index.tsx@@ -46,18 +46,11 @@ const Page: React.FC = () => {privateKey,pairingCode,});- if (!data) {- // No one has connected yet.- return;- }+ if (!data) return;storeCastData(data);await router.push("/slideshow");} catch (e) {- // The pairing code becomes invalid after an hour, which will cause- // `getCastData` to fail. There might be other reasons this might- // fail too, but in all such cases, it is a reasonable idea to start- // again from the beginning.log.warn("Failed to get cast data", e);setPairingCode(undefined);}diff --git a/web/apps/cast/src/pages/slideshow.tsx b/web/apps/cast/src/pages/slideshow.tsxindex 48f9e80dc5..7d09db026f 100644--- a/web/apps/cast/src/pages/slideshow.tsx+++ b/web/apps/cast/src/pages/slideshow.tsx@@ -14,7 +14,6 @@ const Page: React.FC = () => {const router = useRouter();useEffect(() => {- /** Go back to pairing page */const pair = () => void router.push("/");let stop = false;@@ -25,9 +24,7 @@ const Page: React.FC = () => {while (!stop) {const { value: url, done } = await urlGenerator.next();if (done == true || !url) {- // No items in this callection can be shown.setIsEmpty(true);- // Go back to pairing screen after 5 seconds.setTimeout(pair, 5000);return;}@@ -97,7 +94,6 @@ const NoItems: React.FC = () => {};interface SlideViewProps {- /** The URL of the image to show. */url: string;}@@ -118,20 +114,9 @@ const SlideView_ = styled("div")`background-blend-mode: multiply;background-color: rgba(0, 0, 0, 0.5);- /* Smooth out the transition a bit.- *- * For the img itself, we set decoding="sync" to have it switch seamlessly.- * But there does not seem to be a way of setting decoding sync for the- * background image, and for large (multi-MB) images the background image- * switch is still visually non-atomic.- *- * As a workaround, add a long transition so that the background image- * transitions in a more "fade-to" manner. This effect might or might not be- * visually the best though.- *- * Does not work in Firefox, but that's fine, this is only a slight tweak,- * not a functional requirement.- */+ /* The img gets decoding="sync" to switch seamlessly, but there is no+ * equivalent for the background image, so for large images its switch is+ * visibly non-atomic. The long transition masks this. */transition: all 2s;img {@@ -142,15 +127,8 @@ const SlideView_ = styled("div")`}`;-/**- * Variant of {@link SlideView} for use when we're running on Chromecast.- *- * Chromecast devices have trouble with- *- * backdrop-filter: blur(10px);- *- * So emulate a cheaper approximation for use on Chromecast.- */+// Chromecast devices have trouble with backdrop-filter blur; this variant+// approximates it more cheaply.const SlideViewChromecast: React.FC<SlideViewProps> = ({ url }) => {return (<SlideViewChromecast_>@@ -163,7 +141,6 @@ const SlideViewChromecast: React.FC<SlideViewProps> = ({ url }) => {const SlideViewChromecast_ = styled("div")`height: 100vh;- /* We can't set opacity of background-image, so use a wrapper */position: relative;overflow: hidden;diff --git a/web/apps/cast/src/services/cast-data.ts b/web/apps/cast/src/services/cast-data.tsindex 4ae1cca11e..c90beca516 100644--- a/web/apps/cast/src/services/cast-data.ts+++ b/web/apps/cast/src/services/cast-data.ts@@ -1,11 +1,8 @@import type { CastPayload } from "./pair";export interface CastData {- /** The ID of the callection we are casting. */collectionID: string;- /** A key to decrypt the collection we are casting. */collectionKey: string;- /** A credential to use for fetching media files for this cast session. */castToken: string;}@@ -14,18 +11,10 @@ export const clearCastData = () => {localStorage.removeItem(key);};-/**- * Save the data received after pairing with a sender into local storage.- *- * We will read in back when we start the slideshow.- */export const storeCastData = (payload: CastPayload | undefined) => {if (!payload || typeof payload != "object")throw new Error("Unexpected cast data");- // Iterate through all the keys of the payload object and save them to- // localStorage. We don't validate here, we'll validate when we read these- // values back in `readCastData`.for (const [key, value] of Object.entries(payload)) {if (typeof value == "string" || typeof value == "number") {localStorage.setItem(key, value.toString());@@ -35,12 +24,6 @@ export const storeCastData = (payload: CastPayload | undefined) => {}};-/**- * Read back the cast data we got after pairing.- *- * Sibling of {@link storeCastData}. It returns undefined if the expected data- * is not present in localStorage.- */export const readCastData = (): CastData | undefined => {const collectionID = localStorage.getItem("collectionID");const collectionKey = localStorage.getItem("collectionKey");diff --git a/web/apps/cast/src/services/chromecast-receiver.ts b/web/apps/cast/src/services/chromecast-receiver.tsindex 20fba84020..f8d1d55b94 100644--- a/web/apps/cast/src/services/chromecast-receiver.ts+++ b/web/apps/cast/src/services/chromecast-receiver.ts@@ -4,91 +4,31 @@ import log from "ente-base/log";export type Cast = typeof cast;-/**- * A holder for the "cast" global object exposed by the Chromecast SDK,- * alongwith auxiliary state we need around it.- */class CastReceiver {- /**- * A reference to the `cast` global object that the Chromecast Web Receiver- * SDK attaches to the window.- *- * https://developers.google.com/cast/docs/web_receiver/basic- */cast: Cast | undefined;- /**- * A promise that allows us to ensure multiple requests to load are funneled- * through the same reified load.- */loader: Promise<Cast> | undefined;- /**- * True if we have already attached listeners (i.e. if we have "started" the- * Chromecast SDK).- *- * Note that "stopping" the Chromecast SDK causes the Chromecast device to- * reload our tab, so this is a one way flag. The stop is something that'll- * only get triggered when we're actually running on a Chromecast since it- * always happens in response to a message handler.- */+ // One way flag: stopping the Chromecast SDK makes the device reload our+ // tab, so there is no way to unset this.haveStarted = false;- /**- * Cached result of the isChromecast test.- */isChromecast: boolean | undefined;- /**- * A callback to invoke to get the pairing code when we get a new incoming- * pairing request.- */pairingCode: (() => string | undefined) | undefined;- /**- * A callback to invoke to get the ID of the collection that is currently- * being shown (if any).- */collectionID: (() => string | undefined) | undefined;}-/** Singleton instance of {@link CastReceiver}. */const castReceiver = new CastReceiver();-/**- * Listen for incoming messages on the given {@link cast} receiver, replying to- * each of them with a pairing code obtained using the given {@link pairingCode}- * callback. Phase 2 of the pairing protocol.- *- * Calling this function multiple times is fine. The first time around, the- * Chromecast SDK will be loaded and will start listening. Subsequently, each- * time this is call, we'll update the callbacks, but otherwise just return- * immediately (letting the already attached listeners do their thing).- *- * @param pairingCode A callback to invoke to get the pairing code when we get a- * new incoming pairing request.- *- * @param collectionID A callback to invoke to get the ID of the collection that- * is currently being shown (if any).- *- * See: [Note: Pairing protocol].- */export const advertiseOnChromecast = (pairingCode: () => string | undefined,collectionID: () => string | undefined,) => {- // Always update the callbacks.castReceiver.pairingCode = pairingCode;castReceiver.collectionID = collectionID;- // No-op if we're already running.if (castReceiver.haveStarted) return;void loadingChromecastSDKIfNeeded().then((cast) => advertiseCode(cast));};-/**- * Load the Chromecast Web Receiver SDK and return a reference to the `cast`- * global object that the SDK attaches to the window.- *- * Calling this function multiple times is fine, once the Chromecast SDK is- * loaded it'll thereafter return the reference to the same object always.- */const loadingChromecastSDKIfNeeded = async (): Promise<Cast> => {if (castReceiver.cast) return castReceiver.cast;if (castReceiver.loader) return await castReceiver.loader;@@ -108,23 +48,15 @@ const loadingChromecastSDKIfNeeded = async (): Promise<Cast> => {};const advertiseCode = (cast: Cast) => {- if (castReceiver.haveStarted) {- // Multiple attempts raced to completion, ignore all but the first.- return;- }+ if (castReceiver.haveStarted) return;castReceiver.haveStarted = true;- // Prepare the Chromecast "context".const context = cast.framework.CastReceiverContext.getInstance();const namespace = "urn:x-cast:pair-request";const options = new cast.framework.CastReceiverOptions();- // We don't use the media features of the Cast SDK.options.skipPlayersLoad = true;- // Do not stop the casting if the receiver is unreachable. A user should be- // able to start a cast on their phone and then put it away, leaving the- // cast running on their big screen.options.disableIdleTimeout = true;interface ListenerProps {@@ -132,13 +64,9 @@ const advertiseCode = (cast: Cast) => {data: unknown;}- // Reply with the code that we have if anyone asks over Chromecast.const incomingMessageListener = ({ senderId, data }: ListenerProps) => {- // The collection ID with is currently paired (if any).const pairedCollectionID = castReceiver.collectionID?.();- // The collection ID in the request (if any).-let collectionID: string | null = null;if (typeof data == "object" &&@@ -150,39 +78,18 @@ const advertiseCode = (cast: Cast) => {collectionID = data.collectionID.toString();}- // If the request does not have a collectionID (or if we're not showing- // anything currently), forego this check.-if (collectionID && pairedCollectionID) {- // If we get another connection request for a _different_ collection- // ID, stop the app to allow the second device to reconnect using a- // freshly generated pairing code.if (pairedCollectionID != collectionID) {log.info(`request for a new collection ${collectionID}`);context.stop();- } else {- // Duplicate request for same collection that we're already- // showing. Ignore.}return;}const code = castReceiver.pairingCode?.();if (!code) {- // No code, but if we're already showing a collection, then ignore.if (pairedCollectionID) return;- // Our caller waits until it has a pairing code before it calls- // `advertiseCode`, but there is still an edge case where we can- // find ourselves without a pairing code:- //- // 1. The current pairing code expires. We start the process to get- // a new one.- //- // 2. But before that happens, someone connects.- //- // The window where this can happen is short, so if we do find- // ourselves in this scenario, just shutdown.log.error("got pairing request when refreshing pairing codes");context.stop();return;@@ -193,30 +100,16 @@ const advertiseCode = (cast: Cast) => {context.addCustomMessageListener(namespace, incomingMessageListener);- // Close the (chromecast) tab if the sender disconnects.- //- // Chromecast does a "shutdown" of our cast app when we call `context.stop`.- // This translates into it closing the tab where it is showing our app.context.addEventListener("senderdisconnected" as Parameters<typeof context.addEventListener>[0],() => context.stop(),);- // Start listening for Chromecast connections.context.start(options);};-/**- * Return true if we're running on a Chromecast device.- *- * This allows changing our app's behaviour when we're running on Chromecast.- * Such checks are needed because during our testing we found that in practice,- * some processing is too heavy for Chromecast hardware (we tested with a 2nd- * gen device, this might not be true for newer variants).- *- * This variable is lazily updated when we enter {@link renderableImageURLs}. It- * is kept at the top level to avoid passing it around.- */+// Some processing is too heavy for Chromecast hardware (as tested on a 2nd+// gen device; newer variants may do better).export const isChromecast = () => {let isCast = castReceiver.isChromecast;if (isCast === undefined) {diff --git a/web/apps/cast/src/services/detect-type.ts b/web/apps/cast/src/services/detect-type.tsindex bb8a7f1124..efcd2c945e 100644--- a/web/apps/cast/src/services/detect-type.ts+++ b/web/apps/cast/src/services/detect-type.ts@@ -2,17 +2,6 @@ import { lowercaseExtension } from "ente-base/file-name";import { KnownFileTypeInfos } from "ente-media/file-type";import { fileTypeFromBuffer } from "file-type";-/**- * Try to deduce the MIME type for the given {@link file}. Return the MIME type- * string if successful _and_ if it is an image or a video, otherwise return- * `undefined`.- *- * It first peeks into the file's initial contents to detect the MIME type. If- * that doesn't give any results, it tries to deduce it from the file's name.- *- * For the list of returned extensions, see (for our installed version):- * https://github.com/sindresorhus/file-type/blob/main/core.d.ts- */export const detectMediaMIMEType = async (file: File) => {const chunkSizeForTypeDetection = 4100;const fileChunk = file.slice(0, chunkSizeForTypeDetection);diff --git a/web/apps/cast/src/services/pair.ts b/web/apps/cast/src/services/pair.tsindex db521ccb95..ee7026e8cb 100644--- a/web/apps/cast/src/services/pair.ts+++ b/web/apps/cast/src/services/pair.ts@@ -7,85 +7,14 @@ import { nullToUndefined } from "ente-utils/transform";import { z } from "zod";export interface Registration {- /** A pairing code shown on the screen. A client can use this to connect. */pairingCode: string;- /**- * A base64 string representation of the public part of the keypair we- * registered with the server.- */publicKey: string;- /**- * A base64 string representation of the private part of the keypair we- * registered with the server.- */privateKey: string;}-/**- * Register a keypair with the server and return a pairing code that can be used- * to connect to us. Phase 1 of the pairing protocol.- *- * [Note: Pairing protocol]- *- * The Chromecast Framework (represented here by our handle to the Chromecast- * Web SDK, {@link cast}) itself is used for only the initial handshake, none of- * the data, even encrypted passes over it thereafter.- *- * The pairing happens in two phases:- *- * Phase 1 - {@link register}- *- * 1. We (the receiver) generate a public/private keypair. and register the- * public part of it with museum.- *- * 2. Museum gives us a pairing "code" in lieu. Show this on the screen.- *- * Phase 2 - {@link advertiseCode}- *- * There are two ways the client can connect - either by sending us a blank- * message over the Chromecast protocol (to which we'll reply with the pairing- * code), or by the user manually entering the pairing code on their screen.- *- * 3. Listen for incoming messages over the Chromecast connection.- *- * 4. The client (our Web or mobile app) will connect using the "sender"- * Chromecast SDK. This will result in a bi-directional channel between us- * ("receiver") and the Ente client app ("sender").- *- * 5. Thereafter, if at any time the sender disconnects, close the Chromecast- * context. This effectively shuts us down, causing the entire page to get- * reloaded.- *- * 6. After connecting, the sender sends an (empty) message. We reply by sending- * them a message containing the pairing code. This exchange is the only data- * that traverses over the Chromecast connection.- *- * Once the client gets the pairing code (via Chromecast or manual entry),- * they'll let museum know. So in parallel with Phase 2, we perform Phase 3.- *- * Phase 3 - {@link getCastPayload} in a setInterval.- *- * 7. Keep polling museum to ask it if anyone has claimed that code we vended- * out and used that to send us an payload encrypted using our public key.- *- * 8. When that happens, decrypt that data with our private key, and return this- * payload. It is a JSON object that contains the data we need to initiate a- * slideshow for a particular Ente collection.- *- * Phase 1 (Steps 1 and 2) are done by the {@link register} function, which- * returns a {@link Registration}.- *- * At this time we start showing the pairing code on the UI, and start phase 2,- * {@link advertiseCode} to vend out the pairing code to Chromecast connections.- *- * In parallel, we start Phase 3, calling {@link getCastPayload} in a loop. Once we- * get a response, we decrypt it to get the data we need to start the slideshow.- */export const register = async (): Promise<Registration> => {- // Generate keypair.const { publicKey, privateKey } = await generateKeyPair();- // Register keypair with museum to get a pairing code.let pairingCode: string | undefined;while (true) {try {@@ -94,18 +23,12 @@ export const register = async (): Promise<Registration> => {log.error("Failed to register public key with server", e);}if (pairingCode) break;- // Schedule retry after 10 seconds.await wait(10000);}return { pairingCode, publicKey, privateKey };};-/**- * Register the given {@link publicKey} with remote.- *- * @returns A device code that can be used to pair with us.- */const registerDevice = async (publicKey: string) => {const res = await fetch(await apiURL("/cast/device-info"), {method: "POST",@@ -117,10 +40,6 @@ const registerDevice = async (publicKey: string) => {.deviceCode;};-/**- * The structure of the (decrypted) payload that is published (e.g.) by- * `publishCastPayload` on the photos web/desktop app.- */const CastPayload = z.object({castToken: z.string(),collectionID: z.number(),@@ -129,38 +48,20 @@ const CastPayload = z.object({export type CastPayload = z.infer<typeof CastPayload>;-/**- * Ask museum if anyone has sent a (encrypted) payload corresponding to the- * given pairing code. If so, decrypt it using our private key and return the- * JSON payload. Phase 3 of the pairing protocol.- *- * Returns `undefined` if there hasn't been any data obtained yet.- *- * See: [Note: Pairing protocol].- */export const getCastPayload = async (registration: Registration,): Promise<CastPayload | undefined> => {const { pairingCode, publicKey, privateKey } = registration;- // The client will send us the encrypted payload using our public key that- // we registered with museum.const encryptedCastData = await getEncryptedCastData(pairingCode);if (!encryptedCastData) return undefined;- // Decrypt it using the private key of the pair and return the plaintext- // payload, which'll be a JSON object containing the data we need to start a- // slideshow for some collection.const jsonString = new TextDecoder().decode(await boxSealOpenBytes(encryptedCastData, { publicKey, privateKey }),);return CastPayload.parse(JSON.parse(jsonString));};-/**- * Fetch encrypted cast data corresponding to the given {@link code} from remote- * if a client has already paired using it.- */const getEncryptedCastData = async (code: string) => {const res = await fetch(await apiURL(`/cast/cast-data/${code}`), {headers: publicRequestHeaders(),@@ -168,8 +69,6 @@ const getEncryptedCastData = async (code: string) => {ensureOk(res);return z.object({- // encCastData will be null if pairing hasn't happened yet for the- // given code.encCastData: z.string().nullish().transform(nullToUndefined),}).parse(await res.json()).encCastData;diff --git a/web/apps/cast/src/services/render.ts b/web/apps/cast/src/services/render.tsindex ca8b46b084..d6d53744ac 100644--- a/web/apps/cast/src/services/render.ts+++ b/web/apps/cast/src/services/render.ts@@ -21,64 +21,19 @@ import { shuffled } from "ente-utils/array";import { wait } from "ente-utils/promise";import { isChromecast } from "./chromecast-receiver";-/**- * An async generator function that loops through all the files in the- * collection, returning renderable image URLs to each that can be displayed in- * a slideshow.- *- * Each time it resolves with a (data) URL for the slideshow image to show next.- *- * If there are no renderable image in the collection, the sequence ends by- * yielding `{done: true}`.- *- * Otherwise when the generator reaches the end of the collection, it starts- * from the beginning again. So the sequence will continue indefinitely for- * non-empty collections.- *- * The generator ignores errors in the fetching and decoding of individual- * images in the collection, skipping the erroneous ones and moving onward to- * the next one.- *- * - It will however throw if there are errors when getting the collection- * itself. This can happen both the first time, or when we are about to loop- * around to the start of the collection.- *- * - It will also throw if three consecutive image fail.- *- * @param castData The collection to show and credentials to fetch the files- * within it.- */export const imageURLGenerator = async function* (castData: CastData) {const { collectionKey, castToken } = castData;- /**- * Keep a FIFO queue of the URLs that we've vended out recently so that we- * can revoke those that are not being shown anymore.- */const previousURLs: string[] = [];- /** Number of milliseconds to keep the slide on the screen. */- const slideDuration = 12000; /* 12 s */+ const slideDuration = 12000;- /**- * Time when we last yielded.- *- * We use this to keep an roughly periodic spacing between yields that- * accounts for the time we spend fetching and processing the images.- */let lastYieldTime = Date.now();- // The first time around regress the lastYieldTime into the past so that- // we don't wait around too long for the first slide (we do want to wait a- // bit, for the user to see the checkmark animation as reassurance).- lastYieldTime -= slideDuration - 2500; /* wait at most 2.5 s */-- /**- * Number of time we have caught an exception while trying to generate an- * image URL for individual files.- *- * When this happens three times consecutively, we throw.- */+ // Wait at most 2.5 s for the first slide, enough for the user to see the+ // checkmark animation as reassurance.+ lastYieldTime -= slideDuration - 2500;+let consecutiveFailures = 0;while (true) {@@ -100,30 +55,17 @@ export const imageURLGenerator = async function* (castData: CastData) {haveEligibleFiles = true;} catch (e) {consecutiveFailures += 1;- // 1, 2, bang!if (consecutiveFailures == 3) throw e;- if (isHTTP401Error(e)) {- // The token has expired. This can happen, e.g., if the user- // opens the dialog to cast again, causing the client to- // invalidate existing tokens.- //- // Rethrow the error, which will bring us back to the- // pairing page.- throw e;- }-- // On all other errors (including temporary network issues),+ if (isHTTP401Error(e)) throw e;+log.error("Skipping unrenderable file", e);- await wait(100); /* Breathe */+ await wait(100);continue;}- // The last element of previousURLs is the URL that is currently- // being shown on screen.- //- // The last to last element is the one that was shown prior to that,- // and now can be safely revoked.+ // The last entry is the URL currently on screen; only revoke the+ // ones before it.if (previousURLs.length > 1)URL.revokeObjectURL(previousURLs.shift()!);@@ -137,24 +79,10 @@ export const imageURLGenerator = async function* (castData: CastData) {yield url;}- // This collection does not have any files that we can show.if (!haveEligibleFiles) return;}};-/**- * Fetch all the {@link RemoteEnteFile}s present in the collection corresponding- * to the given {@link castToken}.- *- * The remote files are not decrypted or otherwise used at this point, we will- * decrypt and use them on demand when they need to be displayed.- *- * @param castToken A token used both for authentication, and also identifying- * the collection corresponding to the cast session.- *- * @returns All the files in the collection in an arbitrary order. Since we are- * anyways going to be shuffling these files, the order has no bearing.- */export const getRemoteCastCollectionFiles = async (castToken: string,): Promise<RemoteEnteFile[]> => {@@ -183,13 +111,10 @@ const isFileEligible = (file: EnteFile) => {if ((file.info?.fileSize ?? 0) > 100 * 1024 * 1024) return false;- // This check is fast but potentially incorrect because in practice we do- // encounter files that are incorrectly named and have a misleading- // extension. To detect the actual type, we need to sniff the MIME type, but- // that requires downloading and decrypting the file first.+ // The extension is a fast but unreliable check (files can be misnamed);+ // the accurate MIME sniff needs a download and decrypt first.const [, extension] = nameAndExtension(fileFileName(file));if (extension && needsJPEGConversion(extension)) {- // On the web, we only support HEIC conversion.return isHEICExtension(extension);}@@ -200,13 +125,6 @@ const isImageOrLivePhoto = (file: EnteFile) =>file.metadata.fileType == FileType.image ||file.metadata.fileType == FileType.livePhoto;-/**- * Create and return a new data URL that can be used to show the given- * {@link file} in our slideshow image viewer.- *- * Once we're done showing the file, the URL should be revoked using- * {@link URL.revokeObjectURL} to free up browser resources.- */const createRenderableURL = async (castToken: string, file: EnteFile) => {const imageBlob = await renderableImageBlob(castToken, file);return URL.createObjectURL(imageBlob);@@ -227,9 +145,6 @@ const renderableImageBlob = async (castToken: string, file: EnteFile) => {blob = new Blob([imageData]);}- // We cannot rely on the file's extension to detect the file type, some- // files are incorrectly named. So use a MIME type sniffer first, but if- // that fails than fallback to the extension.const mimeType = await detectMediaMIMEType(new File([blob], fileName));if (!mimeType)throw new Error(`Could not detect MIME type for file ${fileName}`);