From f1b44f87fa64d3b21ca92c9068cb352d0ad51bc0 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Wed, 11 Jan 2023 13:06:38 +0100 Subject: [PATCH] fix: shareUrl uses wrong origin --- .../src/components/account/showShareLinkModal.tsx | 4 ++-- .../upload/modals/showCompletedUploadModal.tsx | 13 +++++++++---- .../upload/modals/showCreateUploadModal.tsx | 4 +++- frontend/src/pages/account/shares.tsx | 11 +++++++++-- frontend/src/pages/upload.tsx | 3 ++- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/account/showShareLinkModal.tsx b/frontend/src/components/account/showShareLinkModal.tsx index e4dc9404..cfa3b1b8 100644 --- a/frontend/src/components/account/showShareLinkModal.tsx +++ b/frontend/src/components/account/showShareLinkModal.tsx @@ -1,8 +1,8 @@ import { Stack, TextInput } from "@mantine/core"; import { ModalsContextProps } from "@mantine/modals/lib/context"; -const showShareLinkModal = (modals: ModalsContextProps, shareId: string) => { - const link = `${window.location.origin}/share/${shareId}`; +const showShareLinkModal = (modals: ModalsContextProps, shareId: string, appUrl : string) => { + const link = `${appUrl}/share/${shareId}`; return modals.openModal({ title: "Share link", children: ( diff --git a/frontend/src/components/upload/modals/showCompletedUploadModal.tsx b/frontend/src/components/upload/modals/showCompletedUploadModal.tsx index b422281f..a03ed9ea 100644 --- a/frontend/src/components/upload/modals/showCompletedUploadModal.tsx +++ b/frontend/src/components/upload/modals/showCompletedUploadModal.tsx @@ -15,7 +15,11 @@ import { TbCopy } from "react-icons/tb"; import { Share } from "../../../types/share.type"; import toast from "../../../utils/toast.util"; -const showCompletedUploadModal = (modals: ModalsContextProps, share: Share) => { +const showCompletedUploadModal = ( + modals: ModalsContextProps, + share: Share, + appUrl: string +) => { return modals.openModal({ closeOnClickOutside: false, withCloseButton: false, @@ -25,15 +29,16 @@ const showCompletedUploadModal = (modals: ModalsContextProps, share: Share) => { Share ready ), - children: , + children: , }); }; -const Body = ({ share }: { share: Share }) => { +const Body = ({ share, appUrl }: { share: Share; appUrl: string }) => { const clipboard = useClipboard({ timeout: 500 }); const modals = useModals(); const router = useRouter(); - const link = `${window.location.origin}/share/${share.id}`; + + const link = `${appUrl}/share/${share.id}`; return ( void; options: { isUserSignedIn: boolean; + appUrl: string; allowUnauthenticatedShares: boolean; enableEmailRecepients: boolean; }; @@ -156,7 +158,7 @@ const CreateUploadModalBody = ({ color: theme.colors.gray[6], })} > - {window.location.origin}/share/ + {options.appUrl}/share/ {form.values.link == "" ? "myAwesomeShare" : form.values.link} diff --git a/frontend/src/pages/account/shares.tsx b/frontend/src/pages/account/shares.tsx index c9972dfb..2e27ace1 100644 --- a/frontend/src/pages/account/shares.tsx +++ b/frontend/src/pages/account/shares.tsx @@ -19,6 +19,7 @@ import { useEffect, useState } from "react"; import { TbLink, TbTrash } from "react-icons/tb"; import showShareLinkModal from "../../components/account/showShareLinkModal"; import Meta from "../../components/Meta"; +import useConfig from "../../hooks/config.hook"; import useUser from "../../hooks/user.hook"; import shareService from "../../services/share.service"; import { MyShare } from "../../types/share.type"; @@ -28,6 +29,8 @@ const MyShares = () => { const modals = useModals(); const clipboard = useClipboard(); const router = useRouter(); + const config = useConfig(); + const { user } = useUser(); const [shares, setShares] = useState(); @@ -86,13 +89,17 @@ const MyShares = () => { onClick={() => { if (window.isSecureContext) { clipboard.copy( - `${window.location.origin}/share/${share.id}` + `${config.get("APP_URL")}/share/${share.id}` ); toast.success( "Your link was copied to the keyboard." ); } else { - showShareLinkModal(modals, share.id); + showShareLinkModal( + modals, + share.id, + config.get("APP_URL") + ); } }} > diff --git a/frontend/src/pages/upload.tsx b/frontend/src/pages/upload.tsx index de25fe39..ee3ac30a 100644 --- a/frontend/src/pages/upload.tsx +++ b/frontend/src/pages/upload.tsx @@ -140,7 +140,7 @@ const Upload = () => { .completeShare(createdShare.id) .then(() => { setisUploading(false); - showCompletedUploadModal(modals, createdShare); + showCompletedUploadModal(modals, createdShare, config.get("APP_URL")); setFiles([]); }) .catch(() => @@ -164,6 +164,7 @@ const Upload = () => { modals, { isUserSignedIn: user ? true : false, + appUrl: config.get("APP_URL"), allowUnauthenticatedShares: config.get( "ALLOW_UNAUTHENTICATED_SHARES" ),