Skip to content

armgit / ente

Public Imported from GitHub
0

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

Merge branch 'main' into accounts-passkeys

Neeraj Gupta5d7d16697610
diff --cc apps/cast/src/pages/slideshow.tsx
index 0000000000,f38fef6fef..e8363cb767
mode 000000,100644..100644
--- a/apps/cast/src/pages/slideshow.tsx
+++ b/apps/cast/src/pages/slideshow.tsx
@@@ -1,0 -1,186 +1,186 @@@
+ import { logError } from '@ente/shared/sentry';
+ import PairedSuccessfullyOverlay from 'components/PairedSuccessfullyOverlay';
+ import Theatre from 'components/Theatre';
+ import { FILE_TYPE } from 'constants/file';
+ import { useRouter } from 'next/router';
+ import { createContext, useEffect, useState } from 'react';
+ import {
+ getCastCollection,
+ getLocalFiles,
+ syncPublicFiles,
+ } from 'services/cast/castService';
+ import { Collection } from 'types/collection';
+ import { EnteFile } from 'types/file';
+ import { getPreviewableImage, isRawFileFromFileName } from 'utils/file';
+
+ export const SlideshowContext = createContext<{
+ showNextSlide: () => void;
+ }>(null);
+
+ const renderableFileURLCache = new Map<number, string>();
+
+ export default function Slideshow() {
+ const [collectionFiles, setCollectionFiles] = useState<EnteFile[]>([]);
+
+ const [currentFile, setCurrentFile] = useState<EnteFile | undefined>(
+ undefined
+ );
+ const [nextFile, setNextFile] = useState<EnteFile | undefined>(undefined);
+
+ const [loading, setLoading] = useState(true);
+ const [castToken, setCastToken] = useState<string>('');
+ const [castCollection, setCastCollection] = useState<
+ Collection | undefined
+ >(undefined);
+
+ const syncCastFiles = async (token: string) => {
+ try {
+ const castToken = window.localStorage.getItem('castToken');
+ const requestedCollectionKey =
+ window.localStorage.getItem('collectionKey');
+ const collection = await getCastCollection(
+ castToken,
+ requestedCollectionKey
+ );
+ if (
+ castCollection === undefined ||
+ castCollection.updationTime !== collection.updationTime
+ ) {
+ setCastCollection(collection);
- await syncPublicFiles(token, 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('/');
+ }
+ };
+
+ const init = async () => {
+ try {
+ const castToken = window.localStorage.getItem('castToken');
+ setCastToken(castToken);
+ } catch (e) {
+ logError(e, 'error during sync');
+ router.push('/');
+ }
+ };
+
+ useEffect(() => {
+ if (castToken) {
+ const intervalId = setInterval(() => {
+ syncCastFiles(castToken);
+ }, 5000);
+
+ return () => clearInterval(intervalId);
+ }
+ }, [castToken]);
+
+ const isFileEligibleForCast = (file: EnteFile) => {
+ const fileType = file.metadata.fileType;
+ if (fileType !== FILE_TYPE.IMAGE && fileType !== FILE_TYPE.LIVE_PHOTO) {
+ return false;
+ }
+
+ const fileSizeLimit = 100 * 1024 * 1024;
+
+ if (file.info.fileSize > fileSizeLimit) {
+ return false;
+ }
+
+ const name = file.metadata.title;
+
+ if (fileType === FILE_TYPE.IMAGE) {
+ if (isRawFileFromFileName(name)) {
+ return false;
+ }
+ }
+
+ return true;
+ };
+
+ const router = useRouter();
+
+ useEffect(() => {
+ init();
+ }, []);
+
+ useEffect(() => {
+ if (collectionFiles.length < 1) return;
+ showNextSlide();
+ }, [collectionFiles]);
+
+ const showNextSlide = () => {
+ const currentIndex = collectionFiles.findIndex(
+ (file) => file.id === currentFile?.id
+ );
+
+ const nextIndex = (currentIndex + 1) % collectionFiles.length;
+ const nextNextIndex = (nextIndex + 1) % collectionFiles.length;
+
+ const nextFile = collectionFiles[nextIndex];
+ const nextNextFile = collectionFiles[nextNextIndex];
+
+ setCurrentFile(nextFile);
+ setNextFile(nextNextFile);
+ };
+
+ const [renderableFileURL, setRenderableFileURL] = useState<string>('');
+
+ const getRenderableFileURL = async () => {
+ if (!currentFile) return;
+
+ const cacheValue = renderableFileURLCache.get(currentFile.id);
+ if (cacheValue) {
+ setRenderableFileURL(cacheValue);
+ setLoading(false);
+ return;
+ }
+
+ try {
+ const blob = await getPreviewableImage(
+ currentFile as EnteFile,
+ castToken
+ );
+
+ const url = URL.createObjectURL(blob);
+
+ renderableFileURLCache.set(currentFile?.id, url);
+
+ setRenderableFileURL(url);
+ } catch (e) {
+ return;
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ useEffect(() => {
+ if (currentFile) {
+ getRenderableFileURL();
+ }
+ }, [currentFile]);
+
+ return (
+ <>
+ <SlideshowContext.Provider value={{ showNextSlide }}>
+ <Theatre
+ file1={{
+ fileName: currentFile?.metadata.title,
+ fileURL: renderableFileURL,
+ type: currentFile?.metadata.fileType,
+ }}
+ file2={{
+ fileName: nextFile?.metadata.title,
+ fileURL: renderableFileURL,
+ type: nextFile?.metadata.fileType,
+ }}
+ />
+ </SlideshowContext.Provider>
+ {loading && <PairedSuccessfullyOverlay />}
+ </>
+ );
+ }
diff --cc apps/photos/public/locales/en/translation.json
index ffd68f7da2,a6f46405df..6870df3194
--- a/apps/photos/public/locales/en/translation.json
+++ b/apps/photos/public/locales/en/translation.json
@@@ -625,8 -625,18 +625,19 @@@
"FASTER_UPLOAD_DESCRIPTION": "Route uploads through nearby servers",
"MAGIC_SEARCH_STATUS": "Magic Search Status",
"INDEXED_ITEMS": "Indexed items",
+ "CAST_ALBUM_TO_TV": "Play album on TV",
+ "ENTER_CAST_PIN_CODE": "Enter the code you see on the TV below to pair this device.",
+ "PAIR_DEVICE_TO_TV": "Pair devices",
+ "TV_NOT_FOUND": "TV not found. Did you enter the PIN correctly?",
+ "AUTO_CAST_PAIR": "Auto Pair",
+ "AUTO_CAST_PAIR_REQUIRES_CONNECTION_TO_GOOGLE": "Auto Pair requires connecting to Google servers and only works with Chromecast supported devices. Google will not receive sensitive data, such as your photos.",
+ "PAIR_WITH_PIN": "Pair with PIN",
+ "CHOOSE_DEVICE_FROM_BROWSER": "Choose a cast-compatible device from the browser popup.",
+ "PAIR_WITH_PIN_WORKS_FOR_ANY_LARGE_SCREEN_DEVICE": "Pair with PIN works for any large screen device you want to play your album on.",
+ "VISIT_CAST_ENTE_IO": "Visit cast.ente.io on the device you want to pair.",
+ "CAST_AUTO_PAIR_FAILED": "Chromecast Auto Pair failed. Please try again.",
"CACHE_DIRECTORY": "Cache folder",
+ "PASSKEYS": "Passkeys",
"FREEHAND": "Freehand",
"APPLY_CROP": "Apply Crop",
"PHOTO_EDIT_REQUIRED_TO_SAVE": "At least one transformation or color adjustment must be performed before saving."
diff --cc apps/photos/src/services/userService.ts
index 5a5a85f09f,265dc27ef6..063208beb2
--- a/apps/photos/src/services/userService.ts
+++ b/apps/photos/src/services/userService.ts
@@@ -1,28 -1,22 +1,24 @@@
-import { getEndpoint, getFamilyPortalURL } from '@ente/shared/network/api';
-import { getData, LS_KEYS } from '@ente/shared/storage/localStorage';
-import localForage from '@ente/shared/storage/localForage';
-import { getToken } from '@ente/shared/storage/localStorage/helpers';
-import HTTPService from '@ente/shared/network/HTTPService';
+import { putAttributes } from '@ente/accounts/api/user';
+import { logoutUser } from '@ente/accounts/services/user';
import { getRecoveryKey } from '@ente/shared/crypto/helpers';
+import { ApiError } from '@ente/shared/error';
+import HTTPService from '@ente/shared/network/HTTPService';
- import {
- getEndpoint,
- getFamilyPortalURL,
- isDevDeployment,
- } from '@ente/shared/network/api';
++import { getEndpoint, getFamilyPortalURL } from '@ente/shared/network/api';
import { logError } from '@ente/shared/sentry';
+import localForage from '@ente/shared/storage/localForage';
- import { LS_KEYS, getData } from '@ente/shared/storage/localStorage';
++import { getData, LS_KEYS } from '@ente/shared/storage/localStorage';
+import {
+ getToken,
+ setLocalMapEnabled,
+} from '@ente/shared/storage/localStorage/helpers';
+import { AxiosResponse, HttpStatusCode } from 'axios';
import {
- UserDetails,
DeleteChallengeResponse,
- GetRemoteStoreValueResponse,
GetFeatureFlagResponse,
+ GetRemoteStoreValueResponse,
+ UserDetails,
} from 'types/user';
-import { ApiError } from '@ente/shared/error';
import { getLocalFamilyData, isPartOfFamily } from 'utils/user/family';
-import { AxiosResponse, HttpStatusCode } from 'axios';
-import { setLocalMapEnabled } from '@ente/shared/storage/localStorage/helpers';
-import { putAttributes } from '@ente/accounts/api/user';
-import { logoutUser } from '@ente/accounts/services/user';
const ENDPOINT = getEndpoint();
diff --cc package.json
index 31c8030175,ba6aad353d..6230d75358
--- a/package.json
+++ b/package.json
@@@ -9,12 -9,13 +9,15 @@@
"scripts": {
"build:photos": "turbo run build --filter=photos",
"build:auth": "turbo run build --filter=auth",
+ "build:cast": "turbo run build --filter=cast",
"dev:auth": "turbo run dev --filter=auth",
"dev:photos": "turbo run dev --filter=photos",
+ "dev:accounts": "turbo run dev --filter=accounts",
+ "dev:cast": "turbo run dev --filter=cast",
"export:photos": "turbo run export --filter=photos",
"export:auth": "turbo run export --filter=auth",
+ "export:cast": "turbo run export --filter=cast",
+ "export:accounts": "turbo run export --filter=accounts",
"lint": "turbo run lint",
"albums": "turbo run albums",
"prepare": "husky install"
diff --cc packages/shared/apps/constants.ts
index 4d54608fd4,30c1b55940..3e3ecbf87b
--- a/packages/shared/apps/constants.ts
+++ b/packages/shared/apps/constants.ts
@@@ -4,15 -4,8 +4,9 @@@ export enum APPS
PHOTOS = 'PHOTOS',
AUTH = 'AUTH',
ALBUMS = 'ALBUMS',
+ ACCOUNTS = 'ACCOUNTS',
}
- export enum APP_ENV {
- DEVELOPMENT = 'development',
- PRODUCTION = 'production',
- TEST = 'test',
- }
-
export const CLIENT_PACKAGE_NAMES = new Map([
[APPS.ALBUMS, 'io.ente.albums.web'],
[APPS.PHOTOS, 'io.ente.photos.web'],
diff --cc packages/shared/network/api.ts
index 012dbfa3c5,d0c16ac459..87d3f2e49c
--- a/packages/shared/network/api.ts
+++ b/packages/shared/network/api.ts
@@@ -72,44 -90,15 +90,56 @@@ export const getFamilyPortalURL = () =
return `https://family.ente.io`;
};
+// getAuthenticatorURL returns the endpoint for the authenticator which can be used to
+// view authenticator codes.
+export const getAuthURL = () => {
+ const authURL = process.env.NEXT_PUBLIC_ENTE_AUTH_ENDPOINT;
+ if (isDevDeployment() && authURL) {
+ return authURL;
+ }
+ return `https://auth.ente.io`;
+};
+
+export const getAccountsURL = () => {
+ const accountsURL = process.env.NEXT_PUBLIC_ENTE_ACCOUNTS_ENDPOINT;
+ if (isDevDeployment() && accountsURL) {
+ return accountsURL;
+ }
+ return `https://accounts.ente.io`;
+};
+
+export const getSentryTunnelURL = () => {
+ return `https://sentry-reporter.ente.io`;
+};
+
+/*
+It's a dev deployment (and should use the environment override for endpoints ) in three cases:
+1. when the URL opened is that of the staging web app, or
+2. when the URL opened is that of the staging album app, or
+3. if the app is running locally (hence node_env is development)
+4. if the app is running in test mode
+*/
+export const isDevDeployment = () => {
+ if (globalThis?.location) {
+ return (
+ process.env.NEXT_PUBLIC_ENTE_WEB_ENDPOINT ===
- globalThis.location.origin ||
++ globalThis.location.origin ||
+ process.env.NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT ===
- globalThis.location.origin ||
++ globalThis.location.origin ||
+ process.env.NEXT_PUBLIC_IS_TEST_APP === 'true' ||
+ process.env.NODE_ENV === 'development'
+ );
+ }
+};
+ /**
+ * A build is considered as a development build if either the NODE_ENV is
+ * environment variable is set to 'development'.
+ *
+ * NODE_ENV is automatically set to 'development' when we run `yarn dev`. From
+ * Next.js docs:
+ *
+ * > If the environment variable NODE_ENV is unassigned, Next.js automatically
+ * assigns development when running the `next dev` command, or production for
+ * all other commands.
+ */
+ export const isDevBuild = process.env.NODE_ENV === 'development';