π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Conv
Manav Rathic391190664ff
diff --git a/web/packages/new/photos/services/download.ts b/web/packages/new/photos/services/download.tsindex 23f4433e6d..2d2bf72eba 100644--- a/web/packages/new/photos/services/download.ts+++ b/web/packages/new/photos/services/download.ts@@ -22,7 +22,6 @@ import { retryAsyncOperation } from "@/gallery/utils/retry-async";import type { EnteFile } from "@/media/file";import { FileType } from "@/media/file-type";import { decodeLivePhoto } from "@/media/live-photo";-import { CustomError } from "@ente/shared/error";import HTTPService from "@ente/shared/network/HTTPService";export interface LivePhotoSourceURL {@@ -113,7 +112,6 @@ class DownloadManagerImpl {private fileDownloadProgressListeners: (() => void)[] = [];async init(token?: string) {- this.token = token;await this.initThumbnailCacheIfNeeded();}@@ -132,7 +130,6 @@ class DownloadManagerImpl {}logout() {- this.token = undefined;this.publicAlbumsCredentials = undefined;this.thumbnailURLPromises.clear();this.fileURLPromises.clear();@@ -470,7 +467,7 @@ class DownloadManagerImpl {onDownloadProgress,);} else {- return photos_downloadFile(file, this.token, onDownloadProgress);+ return photos_downloadFile(file);}}@@ -481,7 +478,7 @@ class DownloadManagerImpl {this.publicAlbumsCredentials,);} else {- return photos_downloadFileStream(file, this.token);+ return photos_downloadFileStream(file);}}@@ -687,12 +684,7 @@ const photos_downloadFile = async (file: EnteFile): Promise<Uint8Array> => {return new Uint8Array(await res.arrayBuffer());};-const photos_downloadFileStream = async (- file: EnteFile,- token: string | undefined,-): Promise<Response> => {- if (!token) throw Error(CustomError.TOKEN_MISSING);-+const photos_downloadFileStream = async (file: EnteFile): Promise<Response> => {const customOrigin = await customAPIOrigin();// [Note: Passing credentials for self-hosted file fetches]@@ -701,52 +693,53 @@ const photos_downloadFileStream = async (// configuration involves a redirection://// 1. The browser makes a HTTP GET to a museum with credentials. Museum- // inspects the credentials, in this case the auth token, and if- // they're valid, returns a HTTP 307 redirect to the pre-signed S3- // URL that to the file in the configured S3 bucket.+ // inspects the credentials, in this case the auth token, and if they're+ // valid, returns a HTTP 307 redirect to the pre-signed S3 URL that to+ // the file in the configured S3 bucket.//- // 2. The browser follows the redirect to get the actual file. The URL- // is pre-signed, i.e. already has all credentials needed to prove to- // the S3 object storage that it should serve this response.+ // 2. The browser follows the redirect to get the actual file. The URL is+ // pre-signed, i.e. already has all credentials needed to prove to the S3+ // object storage that it should serve this response.//// For the first step normally we'd pass the auth the token via the// "X-Auth-Token" HTTP header. In this case though, that would be// problematic because the browser preserves the request headers when it- // follows the HTTP 307 redirect, and the "X-Auth-Token" header also- // gets sent to the redirected S3 request made in second step.+ // follows the HTTP 307 redirect, and the "X-Auth-Token" header also gets+ // sent to the redirected S3 request made in second step.//- // To avoid this, we pass the token as a query parameter. Generally this- // is not a good idea, but in this case (a) the URL is not a user- // visible one and (b) even if it gets logged, it'll be in the- // self-hosters own service.+ // To avoid this, we pass the token as a query parameter. Generally this is+ // not a good idea, but in this case (a) the URL is not a user visible one+ // and (b) even if it gets logged, it'll be in the self-hosters own service.//- // Note that Ente's own servers don't have these concerns because we use- // a slightly different flow involving a proxy instead of directly- // connecting to the S3 storage.+ // Note that Ente's own servers don't have these concerns because we use a+ // slightly different flow involving a proxy instead of directly connecting+ // to the S3 storage.//// 1. The web browser makes a HTTP GET request to a proxy passing it the// credentials in the "X-Auth-Token".//- // 2. The proxy then does both the original steps: (a). Use the- // credentials to get the pre signed URL, and (b) fetch that pre- // signed URL and stream back the response.+ // 2. The proxy then does both the original steps: (a). Use the credentials+ // to get the pre signed URL, and (b) fetch that pre signed URL and+ // stream back the response.- const getFile = () => {+ const getFile = async () => {if (customOrigin) {+ const token = await ensureAuthToken();const params = new URLSearchParams({ token });return fetch(`${customOrigin}/files/download/${file.id}?${params.toString()}`,+ {+ headers: clientPackageHeader(),+ },);} else {return fetch(`https://files.ente.io/?fileID=${file.id}`, {- headers: {- "X-Auth-Token": token,- },+ headers: await authenticatedRequestHeaders(),});}};- return retryAsyncOperation(getFile);+ return retryEnsuringHTTPOk(getFile);};interface PublicAlbumsCredentials {