From b4ac991986fcca6084d5bbb8fd131f39e8d90e23 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Wed, 6 Mar 2024 09:51:19 +0530 Subject: [PATCH] [web] Disable the Cloudflare upload proxy when connecting to a custom endpoint This simplifies use cases like https://github.com/ente-io/ente/discussions/685#discussioncomment-8682588. There is one less thing for folks to do if they want to run locally or self-host. Starting a local museum, then connecting to it from the web app NEXT_PUBLIC_ENTE_ENDPOINT=http://localhost:8080 yarn dev And uploading a photo. --- web/apps/photos/.env.development | 13 +------------ web/apps/photos/.env.localhost | 5 ++--- web/apps/photos/src/services/userService.ts | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/web/apps/photos/.env.development b/web/apps/photos/.env.development index 0c5a6eacd..045fffaee 100644 --- a/web/apps/photos/.env.development +++ b/web/apps/photos/.env.development @@ -10,7 +10,7 @@ # # Alternatively, these variables can be provided as environment variables, say: # -# NEXT_PUBLIC_ENTE_ENDPOINT=http://localhost:8080 NEXT_PUBLIC_ENTE_DIRECT_UPLOAD=true yarn dev:photos +# NEXT_PUBLIC_ENTE_ENDPOINT=http://localhost:8080 yarn dev:photos # # Variables prefixed with NEXT_PUBLIC_ are made available when Next.js runs our # code in the browser (Behind the scenes, Next.js just hardcodes occurrences of @@ -69,17 +69,6 @@ # # NEXT_PUBLIC_ENTE_FAMILY_PORTAL_ENDPOINT = http://localhost:3003 -# Set this to "true" to disable the upload of files via Cloudflare Workers. -# -# These workers were introduced as a way of make file uploads faster: -# https://ente.io/blog/tech/making-uploads-faster/ -# -# By default, that's the route we take. However, during development it can be -# convenient to turn this flag on to directly upload to the S3-compatible URLs -# returned by the ente API. -# -# NEXT_PUBLIC_ENTE_DIRECT_UPLOAD = true - # The path of the JSON file which contains the expected results of our # integration tests. See `upload.test.ts` for more details. # diff --git a/web/apps/photos/.env.localhost b/web/apps/photos/.env.localhost index ef1bf679d..136d0118b 100644 --- a/web/apps/photos/.env.localhost +++ b/web/apps/photos/.env.localhost @@ -7,15 +7,14 @@ # # Equivalent CLI command using environment variables would be # -# NEXT_PUBLIC_ENTE_ENDPOINT=http://localhost:8080 NEXT_PUBLIC_ENTE_DIRECT_UPLOAD=true yarn dev:photos +# NEXT_PUBLIC_ENTE_ENDPOINT=http://localhost:8080 yarn dev:photos # NEXT_PUBLIC_ENTE_ENDPOINT = http://localhost:8080 -NEXT_PUBLIC_ENTE_DIRECT_UPLOAD = true # If you wish to preview how the shared albums work, you can use `yarn # dev:albums`. The equivalent CLI command using env vars would be # -# NEXT_PUBLIC_ENTE_ENDPOINT=http://localhost:8080 NEXT_PUBLIC_ENTE_ALBUMS_ENDPOINT=http://localhost:3002 NEXT_PUBLIC_ENTE_DIRECT_UPLOAD=true yarn dev:albums +# NEXT_PUBLIC_ENTE_ENDPOINT=http://localhost:8080 NEXT_PUBLIC_ENTE_ALBUMS_ENDPOINT=http://localhost:3002 yarn dev:albums NEXT_PUBLIC_ENTE_ALBUMS_ENDPOINT = http://localhost:3002 diff --git a/web/apps/photos/src/services/userService.ts b/web/apps/photos/src/services/userService.ts index 4a2c6a9d4..6fbbaa1bd 100644 --- a/web/apps/photos/src/services/userService.ts +++ b/web/apps/photos/src/services/userService.ts @@ -338,8 +338,24 @@ export const updateMapEnabledStatus = async (newStatus: boolean) => { } }; +/** + * Return true to disable the upload of files via Cloudflare Workers. + * + * These workers were introduced as a way of make file uploads faster: + * https://ente.io/blog/tech/making-uploads-faster/ + * + * By default, that's the route we take. However, during development or when + * self-hosting it can be convenient to turn this flag on to directly upload to + * the S3-compatible URLs returned by the ente API. + * + * Note the double negative (Enhancement: maybe remove the double negative, + * rename this to say getUseDirectUpload). + */ export async function getDisableCFUploadProxyFlag(): Promise { - if (process.env.NEXT_PUBLIC_ENTE_DIRECT_UPLOAD === "true") return true; + // 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; try { const featureFlags = (