fixed oauth and uploading and file details

This commit is contained in:
ZareMate 2025-04-14 11:59:54 +02:00
parent 799c7d7cec
commit fbf1c95b1b
Signed by: zaremate
GPG Key ID: 369A0E45E03A81C3
4 changed files with 8 additions and 6 deletions

View File

@ -14,6 +14,8 @@ services:
AUTH_DISCORD_SECRET: "lIrkEwb2PpMpLZM7Yb9pGVeT7YLgIC_C"
AUTH_TRUST_HOST: "true"
SKIP_ENV_VALIDATION: "true"
PAGE_URL: "https://file-hosting.example.com"
NEXTAUTH_URL: "https://file-hosting.example.com"
volumes:
- type: bind
source: /mnt/0TB/DATA/AppData/file-hosting/uploads

View File

@ -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">

View File

@ -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),

View File

@ -19,6 +19,7 @@ export const env = createEnv({
NODE_ENV: z
.enum(["development", "test", "production"])
.default("development"),
PAGE_URL: z.string().url(),
},
/**
@ -40,6 +41,7 @@ export const env = createEnv({
AUTH_DISCORD_SECRET: process.env.AUTH_DISCORD_SECRET,
DATABASE_URL: process.env.DATABASE_URL,
NODE_ENV: process.env.NODE_ENV,
PAGE_URL: process.env.PAGE_URL,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially