diff --git a/frontend/src/components/copylink.jsx b/frontend/src/components/copylink.jsx index 680b054..3d4cba6 100644 --- a/frontend/src/components/copylink.jsx +++ b/frontend/src/components/copylink.jsx @@ -39,9 +39,10 @@ const CopyLink = ({ filePath }) => { const [showToast, setShowToast] = useState(false); const copyWithAuth = async () => { - const target = new URLSearchParams(); - target.append("target", filePath); - const response = await fetch(`/api/single-use?${target.toString()}`, { + const encodedFilePath = encodeURI( + filePath.startsWith('/') ? filePath : `/${filePath}` + ); + const response = await fetch(`/api/single-use?target=${encodedFilePath}`, { headers: { Accept: "application/json", Authorization: `Bearer ${jwt}`, @@ -54,7 +55,7 @@ const CopyLink = ({ filePath }) => { await copyToClipboard( `${window.location.protocol}//${window.location.hostname}${ window.location.port == "" ? "" : `:${window.location.port}` - }/api/stream${filePath}?${auth.toString()}`, + }/api/stream${encodedFilePath}?${auth.toString()}`, ); setShowToast(true); setTimeout(() => setShowToast(false), 2000); diff --git a/frontend/src/components/download.jsx b/frontend/src/components/download.jsx index f1ae83c..ba5df0a 100644 --- a/frontend/src/components/download.jsx +++ b/frontend/src/components/download.jsx @@ -15,9 +15,10 @@ const Download = ({ filePath }) => { const { jwt } = useContext(AuthContext); const downloadWithAuth = async () => { - const target = new URLSearchParams(); - target.append("target", filePath); - const response = await fetch(`/api/single-use?${target.toString()}`, { + const encodedFilePath = encodeURI( + filePath.startsWith('/') ? filePath : `/${filePath}` + ); + const response = await fetch(`/api/single-use?target=${encodedFilePath}`, { headers: { Accept: "application/json", Authorization: `Bearer ${jwt}`, @@ -30,7 +31,7 @@ const Download = ({ filePath }) => { downloadFile( `${window.location.protocol}//${window.location.hostname}${ window.location.port == "" ? "" : `:${window.location.port}` - }/api/stream${filePath}?${auth.toString()}`, + }/api/stream${encodedFilePath}?${auth.toString()}`, filePath.split("/").at(-1), ); };