diff --git a/web/apps/photos/src/services/download/clients/photos.ts b/web/apps/photos/src/services/download/clients/photos.ts index 9ca92ddf53..9f4ecc6079 100644 --- a/web/apps/photos/src/services/download/clients/photos.ts +++ b/web/apps/photos/src/services/download/clients/photos.ts @@ -1,6 +1,6 @@ import { CustomError } from "@ente/shared/error"; import HTTPService from "@ente/shared/network/HTTPService"; -import { customAPIOrigin, thumbnailURL } from "@ente/shared/network/api"; +import { customAPIOrigin } from "@ente/shared/network/api"; import { retryAsyncFunction } from "@ente/shared/utils"; import { DownloadClient } from "services/download"; import { EnteFile } from "types/file"; @@ -20,14 +20,26 @@ export class PhotosDownloadClient implements DownloadClient { if (!token) throw Error(CustomError.TOKEN_MISSING); // See: [Note: Passing credentials for self-hosted file fetches] - const params = new URLSearchParams({ token }); - const getThumbnail = () => - HTTPService.get( - `${thumbnailURL(file.id)}?${params.toString()}`, - undefined, - undefined, - { responseType: "arraybuffer", timeout: this.timeout }, - ); + const getThumbnail = () => { + const opts = { responseType: "arraybuffer", timeout: this.timeout }; + const customOrigin = customAPIOrigin(); + if (customOrigin) { + const params = new URLSearchParams({ token }); + return HTTPService.get( + `${customOrigin}/files/preview/${file.id}?${params.toString()}`, + undefined, + undefined, + opts, + ); + } else { + return HTTPService.get( + `https://thumbnails.ente.io/?fileID=${file.id}`, + undefined, + { "X-Auth-Token": token }, + opts, + ); + } + }; const resp = await retryAsyncFunction(getThumbnail); if (resp.data === undefined) throw Error(CustomError.REQUEST_FAILED); diff --git a/web/packages/shared/network/api.ts b/web/packages/shared/network/api.ts index 88afee86de..c13e4da4fa 100644 --- a/web/packages/shared/network/api.ts +++ b/web/packages/shared/network/api.ts @@ -26,21 +26,6 @@ export const getEndpoint = () => { return "https://api.ente.io"; }; -/** - * Return the URL that should be used for fetching the thumbnail for a file with - * the given {@link id}. - * - * This defaults to a URL on Ente's own servers, but can be overridden when self - * hosting by setting the `NEXT_PUBLIC_ENTE_ENDPOINT` environment variable. - */ -export const thumbnailURL = (id: number) => { - const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT; - if (endpoint) { - return `${endpoint}/files/preview/${id}`; - } - return `https://thumbnails.ente.io/?fileID=${id}`; -}; - export const getPublicCollectionFileURL = (id: number) => { const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT; if (endpoint) {