From dbbcd2b6bbc0d04f06ed07ac35a8d1f3cbc90a20 Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Thu, 23 Nov 2023 17:58:15 -0500 Subject: [PATCH] feat: check if files are eligible for cast --- apps/cast/src/pages/slideshow.tsx | 40 +++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/apps/cast/src/pages/slideshow.tsx b/apps/cast/src/pages/slideshow.tsx index 6c30cf818..becf4ad2d 100644 --- a/apps/cast/src/pages/slideshow.tsx +++ b/apps/cast/src/pages/slideshow.tsx @@ -1,11 +1,12 @@ // import { Inter } from 'next/font/google'; import PairedSuccessfullyOverlay from 'components/PairedSuccessfullyOverlay'; +import { FILE_TYPE } from 'constants/file'; import { useRouter } from 'next/router'; import { useEffect, useState } from 'react'; import { syncCollections } from 'services/collectionService'; import { syncFiles } from 'services/fileService'; import { EnteFile } from 'types/file'; -import { downloadFileAsBlob } from 'utils/file'; +import { downloadFileAsBlob, isRawFileFromFileName } from 'utils/file'; export default function Slideshow() { const [collectionFiles, setCollectionFiles] = useState([]); @@ -32,13 +33,34 @@ export default function Slideshow() { file.collectionID === Number(requestedCollectionID) ); - setCollectionFiles(collectionFiles); + setCollectionFiles( + collectionFiles.filter((file) => + isFileEligibleForCast(file) + ) + ); } } catch { router.push('/'); } }; + const isFileEligibleForCast = (file: EnteFile) => { + const fileType = file.metadata.fileType; + if (fileType !== FILE_TYPE.IMAGE && fileType !== FILE_TYPE.VIDEO) { + return false; + } + + const name = file.metadata.title; + + if (fileType === FILE_TYPE.IMAGE) { + if (isRawFileFromFileName(name)) { + return false; + } + } + + return true; + }; + const router = useRouter(); useEffect(() => { @@ -73,13 +95,17 @@ export default function Slideshow() { const [renderableFileURL, setRenderableFileURL] = useState(''); const getRenderableFileURL = async () => { - const blob = await downloadFileAsBlob(currentFile as EnteFile); + try { + const blob = await downloadFileAsBlob(currentFile as EnteFile); - const url = URL.createObjectURL(blob); + const url = URL.createObjectURL(blob); - setRenderableFileURL(url); - - setLoading(false); + setRenderableFileURL(url); + } catch (e) { + return; + } finally { + setLoading(false); + } }; useEffect(() => {