File URL
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { CustomError } from "@ente/shared/error";
|
||||
import HTTPService from "@ente/shared/network/HTTPService";
|
||||
import { getFileURL, getThumbnailURL } from "@ente/shared/network/api";
|
||||
import { fileURL, getThumbnailURL } from "@ente/shared/network/api";
|
||||
import { retryAsyncFunction } from "@ente/shared/utils";
|
||||
import { DownloadClient } from "services/download";
|
||||
import { EnteFile } from "types/file";
|
||||
@@ -45,7 +45,7 @@ export class PhotosDownloadClient implements DownloadClient {
|
||||
const params = new URLSearchParams({ token });
|
||||
const getFile = () =>
|
||||
HTTPService.get(
|
||||
`${getFileURL(file.id)}?${params.toString()}`,
|
||||
`${fileURL(file.id)}?${params.toString()}`,
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
@@ -101,8 +101,7 @@ export class PhotosDownloadClient implements DownloadClient {
|
||||
// signed URL and stream back the response.
|
||||
|
||||
const params = new URLSearchParams({ token });
|
||||
const getFile = () =>
|
||||
fetch(`${getFileURL(file.id)}?${params.toString()}`);
|
||||
const getFile = () => fetch(`${fileURL(file.id)}?${params.toString()}`);
|
||||
|
||||
return retryAsyncFunction(getFile);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
* overridden when self hosting by setting the `NEXT_PUBLIC_ENTE_ENDPOINT`
|
||||
* environment variable.
|
||||
*/
|
||||
export const apiOrigin = () => getEndpoint();
|
||||
export const apiOrigin = () =>
|
||||
process.env.NEXT_PUBLIC_ENTE_ENDPOINT || "https://api.ente.io";
|
||||
|
||||
/** Deprecated, use {@link apiOrigin} instead. */
|
||||
export const getEndpoint = () => {
|
||||
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
|
||||
if (endpoint) {
|
||||
@@ -17,16 +19,13 @@ export const getEndpoint = () => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the origin that should be used for fetching files.
|
||||
* Return the URL that should be used for fetching a file with the given
|
||||
* {@link id}.
|
||||
*
|
||||
* This defaults to "https://files.ente.io", Ente's own servers, but can be
|
||||
* overridden when self hosting by setting the `NEXT_PUBLIC_ENTE_ENDPOINT`
|
||||
* environment variable.
|
||||
* 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 filesOrigin = () =>
|
||||
process.env.NEXT_PUBLIC_ENTE_ENDPOINT || "https://files.ente.io"
|
||||
|
||||
export const getFileURL = (id: number) => {
|
||||
export const fileURL = (id: number) => {
|
||||
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
|
||||
if (endpoint) {
|
||||
return `${endpoint}/files/download/${id}`;
|
||||
|
||||
Reference in New Issue
Block a user