Skip to content

Commit

Permalink
fix copy link
Browse files Browse the repository at this point in the history
  • Loading branch information
osorionicolas committed Dec 24, 2023
1 parent 6b4532c commit 1232d35
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
1 change: 1 addition & 0 deletions public/files/folder/dummy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy
9 changes: 2 additions & 7 deletions src/app/api/files/[file]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ import fs from "fs";
import { ReadableOptions } from "stream";
import path from "path";

const dirPath = process.env.FILES_PATH || "public/files";

export async function GET(request: NextRequest, { params }: { params: { file: string } }) {
const file = params.file;
let location = request.nextUrl.searchParams.get("path");
if (!location) location = `${dirPath}/${file}`;
export async function GET(request: NextRequest) {
const location = request.nextUrl.searchParams.get("path");
console.log("Looking for file " + location);
const stats = await fs.promises.stat(location); // Get the file size
const data: ReadableStream<Uint8Array> = streamFile(location); // Stream the file with a 1kb chunk
Expand All @@ -23,7 +19,6 @@ export async function GET(request: NextRequest, { params }: { params: { file: st
}),
})
return res
//download(path, file);
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/components/download-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ const DownloadDialog = ({
}
};

const handleToggle = (event, value: File) => {
event.preventDefault()
const handleToggle = (value: File) => {
const currentIndex = checked.indexOf(value);
const newChecked = [...checked];
if (currentIndex === -1) {
Expand Down Expand Up @@ -168,7 +167,7 @@ const DownloadDialog = ({
<li
key={child.name}
className="cursor-pointer flex justify-between hover:bg-zinc-500 py-1"
onClick={(event) => handleToggle(event, child)}
onClick={() => handleToggle(child)}
>
<div className="flex items-center gap-5 pl-5">
<Checkbox
Expand All @@ -178,7 +177,7 @@ const DownloadDialog = ({
{child.name}
</div>
<CopyButton
text={`${window.location.origin}/api/files/${child.name}?path=${file.path}`}
text={`${window.location.origin}/api/files/${child.name}?path=${child.path}`}
/>
</li>
))}
Expand All @@ -191,7 +190,7 @@ const DownloadDialog = ({
<li
className="cursor-pointer flex justify-between hover:bg-zinc-500 py-1"
key={filename}
onClick={(event) => handleToggle(event, file)}
onClick={() => handleToggle(file)}
>
<div className="flex items-center gap-5">
<Checkbox
Expand Down

0 comments on commit 1232d35

Please sign in to comment.