Files
ente/web/packages/shared/network/api.ts
Manav Rathi 9edbdfdd49 File URL
2024-06-04 13:39:08 +05:30

122 lines
3.6 KiB
TypeScript

/**
* Return the origin (scheme, host, port triple) that should be used for making
* API requests to museum.
*
* This defaults to "https://api.ente.io", Ente's own servers, but can be
* overridden when self hosting by setting the `NEXT_PUBLIC_ENTE_ENDPOINT`
* environment variable.
*/
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) {
return endpoint;
}
return "https://api.ente.io";
};
/**
* Return the URL that should be used for fetching 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 fileURL = (id: number) => {
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
if (endpoint) {
return `${endpoint}/files/download/${id}`;
}
return `https://files.ente.io/?fileID=${id}`;
};
export const getPublicCollectionFileURL = (id: number) => {
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
if (endpoint) {
return `${endpoint}/public-collection/files/download/${id}`;
}
return `https://public-albums.ente.io/download/?fileID=${id}`;
};
export const getCastFileURL = (id: number) => {
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
if (endpoint) {
return `${endpoint}/cast/files/download/${id}`;
}
return `https://cast-albums.ente.io/download/?fileID=${id}`;
};
export const getCastThumbnailURL = (id: number) => {
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
if (endpoint) {
return `${endpoint}/cast/files/preview/${id}`;
}
return `https://cast-albums.ente.io/preview/?fileID=${id}`;
};
export const getThumbnailURL = (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 getPublicCollectionThumbnailURL = (id: number) => {
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
if (endpoint) {
return `${endpoint}/public-collection/files/preview/${id}`;
}
return `https://public-albums.ente.io/preview/?fileID=${id}`;
};
export const getUploadEndpoint = () => {
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
if (endpoint) {
return endpoint;
}
return `https://uploader.ente.io`;
};
export const getAccountsURL = () => {
const accountsURL = process.env.NEXT_PUBLIC_ENTE_ACCOUNTS_ENDPOINT;
if (accountsURL) {
return accountsURL;
}
return `https://accounts.ente.io`;
};
export const getAlbumsURL = () => {
const albumsURL = process.env.NEXT_PUBLIC_ENTE_ALBUMS_ENDPOINT;
if (albumsURL) {
return albumsURL;
}
return `https://albums.ente.io`;
};
/**
* Return the URL for the family dashboard which can be used to create or manage
* family plans.
*/
export const getFamilyPortalURL = () => {
const familyURL = process.env.NEXT_PUBLIC_ENTE_FAMILY_ENDPOINT;
if (familyURL) {
return familyURL;
}
return `https://family.ente.io`;
};
/**
* Return the URL for the host that handles payment related functionality.
*/
export const getPaymentsURL = () => {
const paymentsURL = process.env.NEXT_PUBLIC_ENTE_PAYMENTS_ENDPOINT;
if (paymentsURL) {
return paymentsURL;
}
return `https://payments.ente.io`;
};