fixed oauth and uploading and file details
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { env } from "~/env.js";
|
||||
|
||||
interface File {
|
||||
id: string;
|
||||
@@ -97,7 +98,7 @@ export default function FileGrid({ session }: FileGridProps) {
|
||||
|
||||
const handleCopyUrl = (url: string) => {
|
||||
navigator.clipboard
|
||||
.writeText(url)
|
||||
.writeText(env.PAGE_URL + url)
|
||||
.then(() => toast.success("File URL copied to clipboard!"))
|
||||
.catch(() => toast.error("Failed to copy URL."));
|
||||
};
|
||||
@@ -136,7 +137,7 @@ export default function FileGrid({ session }: FileGridProps) {
|
||||
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 hover:bg-white/20"
|
||||
>
|
||||
|
||||
<button onClick={() => router.push(file.url)}>
|
||||
<button onClick={() => router.push(env.PAGE_URL + file.url)}>
|
||||
<h3 className="text-2xl font-bold">{file.name}</h3>
|
||||
</button>
|
||||
<div className="flex gap-2">
|
||||
|
||||
@@ -61,14 +61,11 @@ export async function POST(req: Request) {
|
||||
try {
|
||||
const filePath = path.join(uploadDir, fileName);
|
||||
await fs.writeFile(filePath, fileBuffer);
|
||||
const pageurl = new URL(req.url);
|
||||
//get root path of the url
|
||||
const pagePath = `${pageurl.protocol}//${pageurl.host}`;
|
||||
|
||||
// Save file metadata to the database
|
||||
const newFile = await db.file.create({
|
||||
data: {
|
||||
url: `${pagePath}/share?id=${fileName}`,
|
||||
url: `/share?id=${fileName}`,
|
||||
name: fileName,
|
||||
size: fileBuffer.length,
|
||||
extension: path.extname(fileName),
|
||||
|
||||
Reference in New Issue
Block a user