π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Support custom share app origins with conditional head rendering
Anand Baburajanb47ac6ecefa3
diff --git a/web/apps/share/src/pages/404.tsx b/web/apps/share/src/pages/404.tsxindex 9a136d05a4..129b7fb660 100644--- a/web/apps/share/src/pages/404.tsx+++ b/web/apps/share/src/pages/404.tsx@@ -17,7 +17,7 @@ import { FileShareView } from "../components/file-share/FileShareView";const NotFoundPage: React.FC = () => {return (<>- <CustomHeadShare />+ <CustomHeadShare title="Ente Locker" /><FileShareView /></>);diff --git a/web/packages/base/components/Head.tsx b/web/packages/base/components/Head.tsxindex 142dd1efbd..2113dc19d5 100644--- a/web/packages/base/components/Head.tsx+++ b/web/packages/base/components/Head.tsx@@ -1,7 +1,12 @@import Head from "next/head";import React from "react";import { haveWindow } from "../env";-import { albumsAppOrigin, isCustomAlbumsAppOrigin } from "../origins";+import {+ albumsAppOrigin,+ isCustomAlbumsAppOrigin,+ isCustomShareAppOrigin,+ shareAppOrigin,+} from "../origins";interface CustomHeadProps {title: string;@@ -97,7 +102,7 @@ export const CustomHeadPhotosOrAlbums: React.FC<CustomHeadProps> = ({* Similar to {@link CustomHeadAlbums}, this includes Open Graph meta tags with* absolute URLs for social media preview images.*/-export const CustomHeadShare: React.FC = () => (+export const CustomHeadShareStatic: React.FC = () => (<Head><title>Ente Locker</title><link rel="icon" href="/images/favicon.png" type="image/png" />@@ -117,3 +122,19 @@ export const CustomHeadShare: React.FC = () => (<meta name="referrer" content="strict-origin-when-cross-origin" /></Head>);++/**+ * A convenience fan out to conditionally show one of {@link CustomHead} or+ * {@link CustomHeadShareStatic}.+ *+ * This component defaults to {@link CustomHeadShareStatic} during SSR unless a+ * custom endpoint is defined, and then does a client side update when it+ * detects that the origin it is being served on is not the share origin.+ */+export const CustomHeadShare: React.FC<CustomHeadProps> = ({ title }) =>+ isCustomShareAppOrigin ||+ (haveWindow() && new URL(window.location.href).origin != shareAppOrigin()) ? (+ <CustomHead {...{ title }} />+ ) : (+ <CustomHeadShareStatic />+ );diff --git a/web/packages/base/origins.ts b/web/packages/base/origins.tsindex e6c8b89ebd..cff4f18ae7 100644--- a/web/packages/base/origins.ts+++ b/web/packages/base/origins.ts@@ -103,3 +103,20 @@ export const albumsAppOrigin = () =>*/export const shouldOnlyServeAlbumsApp =!!process.env.NEXT_PUBLIC_ENTE_ONLY_SERVE_ALBUMS_APP;++/**+ * A static build time constant that is `true` if {@link shareAppOrigin} has+ * been customized.+ */+export const isCustomShareAppOrigin =+ !!process.env.NEXT_PUBLIC_ENTE_SHARE_ENDPOINT;++/**+ * Return the origin that serves public locker (share app).+ *+ * Defaults to our production instance, "https://share.ente.io", but can be+ * overridden by setting the `NEXT_PUBLIC_ENTE_SHARE_ENDPOINT` environment+ * variable.+ */+export const shareAppOrigin = (): string =>+ process.env.NEXT_PUBLIC_ENTE_SHARE_ENDPOINT ?? "https://share.ente.io";