|
@@ -9,6 +9,7 @@ import {
|
|
getLocalFiles,
|
|
getLocalFiles,
|
|
syncPublicFiles,
|
|
syncPublicFiles,
|
|
} from 'services/cast/castService';
|
|
} from 'services/cast/castService';
|
|
|
|
+import { Collection } from 'types/collection';
|
|
import { EnteFile } from 'types/file';
|
|
import { EnteFile } from 'types/file';
|
|
import { downloadFileAsBlob, isRawFileFromFileName } from 'utils/file';
|
|
import { downloadFileAsBlob, isRawFileFromFileName } from 'utils/file';
|
|
|
|
|
|
@@ -26,35 +27,60 @@ export default function Slideshow() {
|
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
const [loading, setLoading] = useState(true);
|
|
const [castToken, setCastToken] = useState<string>('');
|
|
const [castToken, setCastToken] = useState<string>('');
|
|
|
|
+ const [castCollection, setCastCollection] = useState<
|
|
|
|
+ Collection | undefined
|
|
|
|
+ >(undefined);
|
|
|
|
|
|
const [renderableFileURLCache, setRenderableFileURLCache] = useState<
|
|
const [renderableFileURLCache, setRenderableFileURLCache] = useState<
|
|
Record<string, string>
|
|
Record<string, string>
|
|
>({});
|
|
>({});
|
|
|
|
|
|
- const init = async () => {
|
|
|
|
|
|
+ const syncCastFiles = async (token: string) => {
|
|
try {
|
|
try {
|
|
|
|
+ const castToken = window.localStorage.getItem('castToken');
|
|
const requestedCollectionKey =
|
|
const requestedCollectionKey =
|
|
window.localStorage.getItem('collectionKey');
|
|
window.localStorage.getItem('collectionKey');
|
|
- const castToken = window.localStorage.getItem('castToken');
|
|
|
|
- setCastToken(castToken);
|
|
|
|
-
|
|
|
|
const collection = await getCastCollection(
|
|
const collection = await getCastCollection(
|
|
castToken,
|
|
castToken,
|
|
requestedCollectionKey
|
|
requestedCollectionKey
|
|
);
|
|
);
|
|
|
|
+ if (
|
|
|
|
+ castCollection === undefined ||
|
|
|
|
+ castCollection.updationTime !== collection.updationTime
|
|
|
|
+ ) {
|
|
|
|
+ setCastCollection(collection);
|
|
|
|
+ await syncPublicFiles(token, collection, () => {});
|
|
|
|
+ const files = await getLocalFiles(String(collection.id));
|
|
|
|
+ setCollectionFiles(
|
|
|
|
+ files.filter((file) => isFileEligibleForCast(file))
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ } catch (e) {
|
|
|
|
+ logError(e, 'error during sync');
|
|
|
|
+ router.push('/');
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
|
|
- await syncPublicFiles(castToken, collection, () => {});
|
|
|
|
- const files = await getLocalFiles(String(collection.id));
|
|
|
|
- setCollectionFiles(
|
|
|
|
- files.filter((file) => isFileEligibleForCast(file))
|
|
|
|
- );
|
|
|
|
|
|
+ const init = async () => {
|
|
|
|
+ try {
|
|
|
|
+ const castToken = window.localStorage.getItem('castToken');
|
|
|
|
+ setCastToken(castToken);
|
|
} catch (e) {
|
|
} catch (e) {
|
|
logError(e, 'error during sync');
|
|
logError(e, 'error during sync');
|
|
- alert('error, redirect to home' + e);
|
|
|
|
router.push('/');
|
|
router.push('/');
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (castToken) {
|
|
|
|
+ const intervalId = setInterval(() => {
|
|
|
|
+ syncCastFiles(castToken);
|
|
|
|
+ }, 5000);
|
|
|
|
+
|
|
|
|
+ return () => clearInterval(intervalId);
|
|
|
|
+ }
|
|
|
|
+ }, [castToken]);
|
|
|
|
+
|
|
const isFileEligibleForCast = (file: EnteFile) => {
|
|
const isFileEligibleForCast = (file: EnteFile) => {
|
|
const fileType = file.metadata.fileType;
|
|
const fileType = file.metadata.fileType;
|
|
if (
|
|
if (
|