Thumbs
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user