Skip to content

Commit

Permalink
Fix path encoding in copylink/download
Browse files Browse the repository at this point in the history
  • Loading branch information
zer0tonin committed Feb 14, 2024
1 parent c268a99 commit 682d5c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions frontend/src/components/copylink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/components/download.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -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),
);
};
Expand Down

0 comments on commit 682d5c7

Please sign in to comment.