fix: use current window url instead of app url in frontend

This commit is contained in:
Elias Schneider
2024-11-14 19:10:11 +01:00
parent ff2dd81055
commit 6f45c3b1fb
12 changed files with 24 additions and 56 deletions

View File

@@ -5,10 +5,9 @@ import { translateOutsideContext } from "../../hooks/useTranslate.hook";
const showReverseShareLinkModal = ( const showReverseShareLinkModal = (
modals: ModalsContextProps, modals: ModalsContextProps,
reverseShareToken: string, reverseShareToken: string,
appUrl: string,
) => { ) => {
const t = translateOutsideContext(); const t = translateOutsideContext();
const link = `${appUrl}/upload/${reverseShareToken}`; const link = `${window.location.origin}/upload/${reverseShareToken}`;
return modals.openModal({ return modals.openModal({
title: t("account.reverseShares.modal.reverse-share-link"), title: t("account.reverseShares.modal.reverse-share-link"),
children: ( children: (

View File

@@ -11,11 +11,10 @@ import CopyTextField from "../upload/CopyTextField";
const showShareInformationsModal = ( const showShareInformationsModal = (
modals: ModalsContextProps, modals: ModalsContextProps,
share: MyShare, share: MyShare,
appUrl: string,
maxShareSize: number, maxShareSize: number,
) => { ) => {
const t = translateOutsideContext(); const t = translateOutsideContext();
const link = `${appUrl}/s/${share.id}`; const link = `${window.location.origin}/s/${share.id}`;
const formattedShareSize = byteToHumanSizeString(share.size); const formattedShareSize = byteToHumanSizeString(share.size);
const formattedMaxShareSize = byteToHumanSizeString(maxShareSize); const formattedMaxShareSize = byteToHumanSizeString(maxShareSize);

View File

@@ -2,13 +2,9 @@ import { Stack, TextInput } from "@mantine/core";
import { ModalsContextProps } from "@mantine/modals/lib/context"; import { ModalsContextProps } from "@mantine/modals/lib/context";
import { translateOutsideContext } from "../../hooks/useTranslate.hook"; import { translateOutsideContext } from "../../hooks/useTranslate.hook";
const showShareLinkModal = ( const showShareLinkModal = (modals: ModalsContextProps, shareId: string) => {
modals: ModalsContextProps,
shareId: string,
appUrl: string,
) => {
const t = translateOutsideContext(); const t = translateOutsideContext();
const link = `${appUrl}/s/${shareId}`; const link = `${window.location.origin}/s/${shareId}`;
return modals.openModal({ return modals.openModal({
title: t("account.shares.modal.share-link"), title: t("account.shares.modal.share-link"),
children: ( children: (

View File

@@ -89,15 +89,11 @@ const ManageShareTable = ({
onClick={() => { onClick={() => {
if (window.isSecureContext) { if (window.isSecureContext) {
clipboard.copy( clipboard.copy(
`${config.get("general.appUrl")}/s/${share.id}`, `${window.location.origin}/s/${share.id}`,
); );
toast.success(t("common.notify.copied")); toast.success(t("common.notify.copied"));
} else { } else {
showShareLinkModal( showShareLinkModal(modals, share.id);
modals,
share.id,
config.get("general.appUrl"),
);
} }
}} }}
> >

View File

@@ -128,9 +128,7 @@ const SignInForm = ({ redirectPath }: { redirectPath: string }) => {
config.get("oauth.disablePassword") config.get("oauth.disablePassword")
) { ) {
setIsRedirectingToOauthProvider(true); setIsRedirectingToOauthProvider(true);
router.push( router.push(getOAuthUrl(window.location.origin, providers.data[0]));
getOAuthUrl(config.get("general.appUrl"), providers.data[0]),
);
} }
}) })
.catch(toast.axiosError); .catch(toast.axiosError);
@@ -208,7 +206,7 @@ const SignInForm = ({ redirectPath }: { redirectPath: string }) => {
key={provider} key={provider}
component="a" component="a"
title={t(`signIn.oauth.${provider}`)} title={t(`signIn.oauth.${provider}`)}
href={getOAuthUrl(config.get("general.appUrl"), provider)} href={getOAuthUrl(window.location.origin, provider)}
variant="light" variant="light"
fullWidth fullWidth
> >

View File

@@ -65,7 +65,7 @@ const FileList = ({
}; };
const copyFileLink = (file: FileMetaData) => { const copyFileLink = (file: FileMetaData) => {
const link = `${config.get("general.appUrl")}/api/shares/${ const link = `${window.location.origin}/api/shares/${
share.id share.id
}/files/${file.id}`; }/files/${file.id}`;

View File

@@ -13,7 +13,6 @@ import CopyTextField from "../CopyTextField";
const showCompletedUploadModal = ( const showCompletedUploadModal = (
modals: ModalsContextProps, modals: ModalsContextProps,
share: CompletedShare, share: CompletedShare,
appUrl: string,
) => { ) => {
const t = translateOutsideContext(); const t = translateOutsideContext();
return modals.openModal({ return modals.openModal({
@@ -21,18 +20,18 @@ const showCompletedUploadModal = (
withCloseButton: false, withCloseButton: false,
closeOnEscape: false, closeOnEscape: false,
title: t("upload.modal.completed.share-ready"), title: t("upload.modal.completed.share-ready"),
children: <Body share={share} appUrl={appUrl} />, children: <Body share={share} />,
}); });
}; };
const Body = ({ share, appUrl }: { share: CompletedShare; appUrl: string }) => { const Body = ({ share }: { share: CompletedShare }) => {
const modals = useModals(); const modals = useModals();
const router = useRouter(); const router = useRouter();
const t = useTranslate(); const t = useTranslate();
const isReverseShare = !!router.query["reverseShareToken"]; const isReverseShare = !!router.query["reverseShareToken"];
const link = `${appUrl}/s/${share.id}`; const link = `${window.location.origin}/s/${share.id}`;
return ( return (
<Stack align="stretch"> <Stack align="stretch">

View File

@@ -19,7 +19,7 @@ import { useForm, yupResolver } from "@mantine/form";
import { useModals } from "@mantine/modals"; import { useModals } from "@mantine/modals";
import { ModalsContextProps } from "@mantine/modals/lib/context"; import { ModalsContextProps } from "@mantine/modals/lib/context";
import moment from "moment"; import moment from "moment";
import { useState } from "react"; import React, { useState } from "react";
import { TbAlertCircle } from "react-icons/tb"; import { TbAlertCircle } from "react-icons/tb";
import { FormattedMessage } from "react-intl"; import { FormattedMessage } from "react-intl";
import * as yup from "yup"; import * as yup from "yup";
@@ -30,7 +30,6 @@ import shareService from "../../../services/share.service";
import { FileUpload } from "../../../types/File.type"; import { FileUpload } from "../../../types/File.type";
import { CreateShare } from "../../../types/share.type"; import { CreateShare } from "../../../types/share.type";
import { getExpirationPreview } from "../../../utils/date.util"; import { getExpirationPreview } from "../../../utils/date.util";
import React from "react";
import toast from "../../../utils/toast.util"; import toast from "../../../utils/toast.util";
const showCreateUploadModal = ( const showCreateUploadModal = (
@@ -38,7 +37,6 @@ const showCreateUploadModal = (
options: { options: {
isUserSignedIn: boolean; isUserSignedIn: boolean;
isReverseShare: boolean; isReverseShare: boolean;
appUrl: string;
allowUnauthenticatedShares: boolean; allowUnauthenticatedShares: boolean;
enableEmailRecepients: boolean; enableEmailRecepients: boolean;
maxExpirationInHours: number; maxExpirationInHours: number;
@@ -101,7 +99,6 @@ const CreateUploadModalBody = ({
options: { options: {
isUserSignedIn: boolean; isUserSignedIn: boolean;
isReverseShare: boolean; isReverseShare: boolean;
appUrl: string;
allowUnauthenticatedShares: boolean; allowUnauthenticatedShares: boolean;
enableEmailRecepients: boolean; enableEmailRecepients: boolean;
maxExpirationInHours: number; maxExpirationInHours: number;
@@ -245,7 +242,7 @@ const CreateUploadModalBody = ({
color: theme.colors.gray[6], color: theme.colors.gray[6],
})} })}
> >
{`${options.appUrl}/s/${form.values.link}`} {`${window.location.origin}/s/${form.values.link}`}
</Text> </Text>
{!options.isReverseShare && ( {!options.isReverseShare && (
<> <>
@@ -461,7 +458,6 @@ const SimplifiedCreateUploadModalModal = ({
options: { options: {
isUserSignedIn: boolean; isUserSignedIn: boolean;
isReverseShare: boolean; isReverseShare: boolean;
appUrl: string;
allowUnauthenticatedShares: boolean; allowUnauthenticatedShares: boolean;
enableEmailRecepients: boolean; enableEmailRecepients: boolean;
maxExpirationInHours: number; maxExpirationInHours: number;

View File

@@ -279,10 +279,7 @@ const Account = () => {
) : ( ) : (
<Button <Button
component="a" component="a"
href={getOAuthUrl( href={getOAuthUrl(window.location.origin, provider)}
config.get("general.appUrl"),
provider,
)}
> >
{t("account.card.oauth.link")} {t("account.card.oauth.link")}
</Button> </Button>

View File

@@ -37,8 +37,6 @@ const MyShares = () => {
const config = useConfig(); const config = useConfig();
const appUrl = config.get("general.appUrl");
const [reverseShares, setReverseShares] = useState<MyReverseShare[]>(); const [reverseShares, setReverseShares] = useState<MyReverseShare[]>();
const getReverseShares = () => { const getReverseShares = () => {
@@ -146,7 +144,7 @@ const MyShares = () => {
{reverseShare.shares.map((share) => ( {reverseShare.shares.map((share) => (
<Group key={share.id} mb={4}> <Group key={share.id} mb={4}>
<Anchor <Anchor
href={`${appUrl}/share/${share.id}`} href={`${window.location.origin}/share/${share.id}`}
target="_blank" target="_blank"
> >
<Text maw={120} truncate> <Text maw={120} truncate>
@@ -159,14 +157,12 @@ const MyShares = () => {
size={25} size={25}
onClick={() => { onClick={() => {
if (window.isSecureContext) { if (window.isSecureContext) {
clipboard.copy(`${appUrl}/s/${share.id}`); clipboard.copy(
`${window.location.origin}/s/${share.id}`,
);
toast.success(t("common.notify.copied")); toast.success(t("common.notify.copied"));
} else { } else {
showShareLinkModal( showShareLinkModal(modals, share.id);
modals,
share.id,
config.get("general.appUrl"),
);
} }
}} }}
> >
@@ -197,7 +193,7 @@ const MyShares = () => {
onClick={() => { onClick={() => {
if (window.isSecureContext) { if (window.isSecureContext) {
clipboard.copy( clipboard.copy(
`${config.get("general.appUrl")}/upload/${ `${window.location.origin}/upload/${
reverseShare.token reverseShare.token
}`, }`,
); );
@@ -206,7 +202,6 @@ const MyShares = () => {
showReverseShareLinkModal( showReverseShareLinkModal(
modals, modals,
reverseShare.token, reverseShare.token,
config.get("general.appUrl"),
); );
} }
}} }}

View File

@@ -4,7 +4,6 @@ import {
Button, Button,
Center, Center,
Group, Group,
MediaQuery,
Space, Space,
Stack, Stack,
Table, Table,
@@ -109,7 +108,6 @@ const MyShares = () => {
showShareInformationsModal( showShareInformationsModal(
modals, modals,
share, share,
config.get("general.appUrl"),
parseInt(config.get("share.maxSize")), parseInt(config.get("share.maxSize")),
); );
}} }}
@@ -123,15 +121,11 @@ const MyShares = () => {
onClick={() => { onClick={() => {
if (window.isSecureContext) { if (window.isSecureContext) {
clipboard.copy( clipboard.copy(
`${config.get("general.appUrl")}/s/${share.id}`, `${window.location.origin}/s/${share.id}`,
); );
toast.success(t("common.notify.copied")); toast.success(t("common.notify.copied"));
} else { } else {
showShareLinkModal( showShareLinkModal(modals, share.id);
modals,
share.id,
config.get("general.appUrl"),
);
} }
}} }}
> >

View File

@@ -135,7 +135,6 @@ const Upload = ({
{ {
isUserSignedIn: user ? true : false, isUserSignedIn: user ? true : false,
isReverseShare, isReverseShare,
appUrl: config.get("general.appUrl"),
allowUnauthenticatedShares: config.get( allowUnauthenticatedShares: config.get(
"share.allowUnauthenticatedShares", "share.allowUnauthenticatedShares",
), ),
@@ -189,7 +188,7 @@ const Upload = ({
.completeShare(createdShare.id) .completeShare(createdShare.id)
.then((share) => { .then((share) => {
setisUploading(false); setisUploading(false);
showCompletedUploadModal(modals, share, config.get("general.appUrl")); showCompletedUploadModal(modals, share);
setFiles([]); setFiles([]);
}) })
.catch(() => toast.error(t("upload.notify.generic-error"))); .catch(() => toast.error(t("upload.notify.generic-error")));