This commit is contained in:
Manav Rathi
2024-06-04 14:04:25 +05:30
parent d44b951f0d
commit 895ab1764e
2 changed files with 21 additions and 24 deletions

View File

@@ -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);

View File

@@ -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) {