Deal with worker urls
This commit is contained in:
@@ -2,13 +2,12 @@ import log from "@/next/log";
|
||||
import { wait } from "@/utils/promise";
|
||||
import { CustomError, handleUploadError } from "@ente/shared/error";
|
||||
import HTTPService from "@ente/shared/network/HTTPService";
|
||||
import { getEndpoint, getUploadEndpoint } from "@ente/shared/network/api";
|
||||
import { getEndpoint, uploaderOrigin } from "@ente/shared/network/api";
|
||||
import { getToken } from "@ente/shared/storage/localStorage/helpers";
|
||||
import { EnteFile } from "types/file";
|
||||
import { MultipartUploadURLs, UploadFile, UploadURL } from "./uploadService";
|
||||
|
||||
const ENDPOINT = getEndpoint();
|
||||
const UPLOAD_ENDPOINT = getUploadEndpoint();
|
||||
|
||||
const MAX_URL_REQUESTS = 50;
|
||||
|
||||
@@ -122,7 +121,7 @@ class UploadHttpClient {
|
||||
try {
|
||||
await retryHTTPCall(() =>
|
||||
HTTPService.put(
|
||||
`${UPLOAD_ENDPOINT}/file-upload`,
|
||||
`${uploaderOrigin()}/file-upload`,
|
||||
file,
|
||||
null,
|
||||
{
|
||||
@@ -178,7 +177,7 @@ class UploadHttpClient {
|
||||
try {
|
||||
const response = await retryHTTPCall(async () => {
|
||||
const resp = await HTTPService.put(
|
||||
`${UPLOAD_ENDPOINT}/multipart-upload`,
|
||||
`${uploaderOrigin()}/multipart-upload`,
|
||||
filePart,
|
||||
null,
|
||||
{
|
||||
@@ -219,7 +218,7 @@ class UploadHttpClient {
|
||||
try {
|
||||
await retryHTTPCall(() =>
|
||||
HTTPService.post(
|
||||
`${UPLOAD_ENDPOINT}/multipart-complete`,
|
||||
`${uploaderOrigin()}/multipart-complete`,
|
||||
reqBody,
|
||||
null,
|
||||
{
|
||||
|
||||
@@ -2,7 +2,11 @@ import log from "@/next/log";
|
||||
import { putAttributes } from "@ente/accounts/api/user";
|
||||
import { ApiError } from "@ente/shared/error";
|
||||
import HTTPService from "@ente/shared/network/HTTPService";
|
||||
import { getEndpoint, getFamilyPortalURL } from "@ente/shared/network/api";
|
||||
import {
|
||||
customAPIOrigin,
|
||||
getEndpoint,
|
||||
getFamilyPortalURL,
|
||||
} from "@ente/shared/network/api";
|
||||
import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";
|
||||
import {
|
||||
getToken,
|
||||
@@ -314,10 +318,13 @@ export const updateMapEnabledStatus = async (newStatus: boolean) => {
|
||||
* rename this to say getUseDirectUpload).
|
||||
*/
|
||||
export async function getDisableCFUploadProxyFlag(): Promise<boolean> {
|
||||
// If NEXT_PUBLIC_ENTE_ENDPOINT is set, that means we're not running a
|
||||
// production deployment. Disable the Cloudflare upload proxy, and instead
|
||||
// just directly use the upload URLs that museum gives us.
|
||||
if (process.env.NEXT_PUBLIC_ENTE_ENDPOINT) return true;
|
||||
// If a custom origin is set, that means we're not running a production
|
||||
// deployment (maybe we're running locally, or being self-hosted).
|
||||
//
|
||||
// In such cases, disable the Cloudflare upload proxy (which won't work for
|
||||
// self-hosters), and instead just directly use the upload URLs that museum
|
||||
// gives us.
|
||||
if (customAPIOrigin()) return true;
|
||||
|
||||
try {
|
||||
const featureFlags = (
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { apiOrigin } from "@ente/shared/network/api";
|
||||
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
||||
import {
|
||||
Dialog,
|
||||
|
||||
@@ -1,32 +1,50 @@
|
||||
import { nullToUndefined } from "@/utils/transform";
|
||||
|
||||
/**
|
||||
* 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 or developing by setting the
|
||||
* `NEXT_PUBLIC_ENTE_ENDPOINT` environment variable.
|
||||
* This defaults to {@link defaultAPIOrigin}, but can be overridden when self
|
||||
* hosting or developing by setting the `NEXT_PUBLIC_ENTE_ENDPOINT` environment
|
||||
* variable.
|
||||
*/
|
||||
export const apiOrigin = () => customAPIOrigin() ?? "https://api.ente.io";
|
||||
export const apiOrigin = () => customAPIOrigin() ?? defaultAPIOrigin;
|
||||
|
||||
/**
|
||||
* Return the overridden API origin, if one is defined by setting the
|
||||
* `NEXT_PUBLIC_ENTE_ENDPOINT` environment variable.
|
||||
* Return the overridden API origin, if one is defined by either (in priority
|
||||
* order):
|
||||
*
|
||||
* - Setting the custom server on the landing page (See: [Note: Configuring
|
||||
* custom server]); or by
|
||||
*
|
||||
* - Setting the `NEXT_PUBLIC_ENTE_ENDPOINT` environment variable.
|
||||
*
|
||||
* Otherwise return undefined.
|
||||
*/
|
||||
export const customAPIOrigin = () =>
|
||||
process.env.NEXT_PUBLIC_ENTE_ENDPOINT ?? undefined;
|
||||
nullToUndefined(localStorage.getItem("apiOrigin")) ??
|
||||
process.env.NEXT_PUBLIC_ENTE_ENDPOINT ??
|
||||
undefined;
|
||||
|
||||
/**
|
||||
* Default value of {@link apiOrigin}: "https://api.ente.io", Ente's production
|
||||
* API servers.
|
||||
*/
|
||||
export const defaultAPIOrigin = "https://api.ente.io";
|
||||
|
||||
/** Deprecated, use {@link apiOrigin} instead. */
|
||||
export const getEndpoint = apiOrigin;
|
||||
|
||||
export const getUploadEndpoint = () => {
|
||||
const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
|
||||
if (endpoint) {
|
||||
return endpoint;
|
||||
}
|
||||
return `https://uploader.ente.io`;
|
||||
};
|
||||
/**
|
||||
* Return the origin that should be used for uploading files.
|
||||
*
|
||||
* This defaults to `https://uploader.ente.io`, serviced by a Cloudflare worker
|
||||
* (see infra/workers/uploader). But if a {@link customAPIOrigin} is set then
|
||||
* this value is set to the {@link customAPIOrigin} itself, effectively
|
||||
* bypassing the Cloudflare worker for non-Ente deployments.
|
||||
*/
|
||||
export const uploaderOrigin = () =>
|
||||
customAPIOrigin() ?? "https://uploader.ente.io";
|
||||
|
||||
/**
|
||||
* Return the URL of the Ente Accounts app.
|
||||
|
||||
Reference in New Issue
Block a user