Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

feat: cast slideshow

httpjamesmee4b091f01ca
diff --git a/apps/cast/src/pages/_document.tsx b/apps/cast/src/pages/_document.tsx
index a2e69e3a65..27ce9e927c 100644
--- a/apps/cast/src/pages/_document.tsx
+++ b/apps/cast/src/pages/_document.tsx
@@ -4,7 +4,10 @@ export default function Document() {
return (
<Html lang="en">
<Head />
- <body>
+ <body
+ style={{
+ margin: 0,
+ }}>
<Main />
<NextScript />
</body>
diff --git a/apps/cast/src/pages/index.tsx b/apps/cast/src/pages/index.tsx
index 2168691ab6..486f357798 100644
--- a/apps/cast/src/pages/index.tsx
+++ b/apps/cast/src/pages/index.tsx
@@ -1,11 +1,19 @@
// import { Inter } from 'next/font/google';
-import { useEffect } from 'react';
+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';
// const inter = Inter({ subsets: ['latin'] });
export default function Home() {
+ const [collectionFiles, setCollectionFiles] = useState<EnteFile[]>([]);
+
+ const [currentFile, setCurrentFile] = useState<EnteFile | undefined>(
+ undefined
+ );
+
const init = async () => {
const collections = await syncCollections();
@@ -14,19 +22,75 @@ export default function Home() {
const files = await syncFiles('normal', collections, () => {});
- console.log(files);
-
if (requestedCollectionID) {
const collectionFiles = files.filter(
(file) => file.collectionID === Number(requestedCollectionID)
);
- console.log('collectionFiles', collectionFiles);
+ setCollectionFiles(collectionFiles);
}
};
useEffect(() => {
init();
}, []);
- return <></>;
+
+ useEffect(() => {
+ // create interval to change slide
+ const interval = setInterval(() => {
+ // set the currentFile to the next file in the collection for the slideshow
+ const currentIndex = collectionFiles.findIndex(
+ (file) => file.id === currentFile?.id
+ );
+
+ const nextIndex = (currentIndex + 1) % collectionFiles.length;
+
+ const nextFile = collectionFiles[nextIndex];
+
+ setCurrentFile(nextFile);
+ }, 5000);
+
+ return () => {
+ clearInterval(interval);
+ };
+ }, [collectionFiles, currentFile]);
+
+ const [renderableFileURL, setRenderableFileURL] = useState<string>('');
+
+ const getRenderableFileURL = async () => {
+ const blob = await downloadFileAsBlob(currentFile as EnteFile);
+
+ const url = URL.createObjectURL(blob);
+
+ setRenderableFileURL(url);
+ };
+
+ useEffect(() => {
+ if (currentFile) {
+ console.log(currentFile);
+ getRenderableFileURL();
+ }
+ }, [currentFile]);
+
+ return (
+ <>
+ <div
+ style={{
+ width: '100vw',
+ height: '100vh',
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'center',
+ backgroundColor: 'black',
+ }}>
+ <img
+ src={renderableFileURL}
+ style={{
+ maxWidth: '100%',
+ maxHeight: '100%',
+ }}
+ />
+ </div>
+ </>
+ );
}
diff --git a/apps/cast/src/utils/file/index.ts b/apps/cast/src/utils/file/index.ts
index 824158edf9..bf01b921be 100644
--- a/apps/cast/src/utils/file/index.ts
+++ b/apps/cast/src/utils/file/index.ts
@@ -925,6 +925,28 @@ const deleteFileHelper = async (
}
};
+export const downloadFileAsBlob = async (file: EnteFile): Promise<Blob> => {
+ try {
+ let fileBlob: Blob;
+ // const fileReader = new FileReader();
+ const fileURL = await DownloadManager.getCachedOriginalFile(file)[0];
+ if (!fileURL) {
+ fileBlob = await new Response(
+ await DownloadManager.downloadFile(file)
+ ).blob();
+ } else {
+ fileBlob = await (await fetch(fileURL)).blob();
+ }
+ const fileType = await getFileType(
+ new File([fileBlob], file.metadata.title)
+ );
+ fileBlob = new Blob([fileBlob], { type: fileType.mimeType });
+ return fileBlob;
+ } catch (e) {
+ logError(e, 'failed to download file');
+ }
+};
+
const hideFilesHelper = async (
selectedFiles: EnteFile[],
setHiddenFileIds: (