π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add a convenience function to avoid code duplication
Manav Rathi2db166bcf764
diff --git a/web/packages/accounts/components/Login.tsx b/web/packages/accounts/components/Login.tsxindex 7e79d4e377..69775957b8 100644--- a/web/packages/accounts/components/Login.tsx+++ b/web/packages/accounts/components/Login.tsx@@ -1,5 +1,5 @@import log from "@/next/log";-import { customAPIOrigin } from "@/next/origins";+import { customAPIHost } from "@/next/origins";import type { AppName } from "@/next/types/app";import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer";import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title";@@ -8,7 +8,7 @@ import SingleInputForm, {type SingleInputFormProps,} from "@ente/shared/components/SingleInputForm";import { LS_KEYS, setData } from "@ente/shared/storage/localStorage";-import { Input, Typography, Stack } from "@mui/material";+import { Input, Stack, Typography } from "@mui/material";import { t } from "i18next";import { useRouter } from "next/router";import { getSRPAttributes } from "../api/srp";@@ -23,8 +23,7 @@ interface LoginProps {export function Login({ appName, signUp }: LoginProps) {const router = useRouter();- const origin = customAPIOrigin();- const host = origin ? new URL(origin).host : undefined;+ const host = customAPIHost();const loginUser: SingleInputFormProps["callback"] = async (email,diff --git a/web/packages/accounts/components/SignUp.tsx b/web/packages/accounts/components/SignUp.tsxindex 0ab61ddc00..24b0fef334 100644--- a/web/packages/accounts/components/SignUp.tsx+++ b/web/packages/accounts/components/SignUp.tsx@@ -1,5 +1,5 @@import log from "@/next/log";-import { customAPIOrigin } from "@/next/origins";+import { customAPIHost } from "@/next/origins";import type { AppName } from "@/next/types/app";import { sendOtt } from "@ente/accounts/api/user";import { PasswordStrengthHint } from "@ente/accounts/components/PasswordStrength";@@ -62,8 +62,7 @@ export function SignUp({ router, appName, login }: SignUpProps) {const [loading, setLoading] = useState(false);const [showPassword, setShowPassword] = useState(false);- const origin = customAPIOrigin();- const host = origin ? new URL(origin).host : undefined;+ const host = customAPIHost();const handleClickShowPassword = () => {setShowPassword(!showPassword);diff --git a/web/packages/next/origins.ts b/web/packages/next/origins.tsindex 13b44fc5ed..66e6a9aefa 100644--- a/web/packages/next/origins.ts+++ b/web/packages/next/origins.ts@@ -25,6 +25,17 @@ export const customAPIOrigin = () =>process.env.NEXT_PUBLIC_ENTE_ENDPOINT ??undefined;+/**+ * A convenience wrapper over {@link customAPIOrigin} that returns the only the+ * host part of the custom origin (if any).+ *+ * This is useful in places where we indicate the custom origin in the UI.+ */+export const customAPIHost = () => {+ const origin = customAPIOrigin();+ return origin ? new URL(origin).host : undefined;+};+/*** Return the origin that should be used for uploading files.*