diff --git a/docker-compose.yml b/docker-compose.yml index 2ce202d..d2aa78b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/src/app/_components/FileGrid.tsx b/src/app/_components/FileGrid.tsx index 491161c..50e7c21 100644 --- a/src/app/_components/FileGrid.tsx +++ b/src/app/_components/FileGrid.tsx @@ -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" > -
diff --git a/src/app/api/upload/route.ts b/src/app/api/upload/route.ts index 5391fa9..19da931 100644 --- a/src/app/api/upload/route.ts +++ b/src/app/api/upload/route.ts @@ -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), diff --git a/src/env.js b/src/env.js index ecf0679..e95a84e 100644 --- a/src/env.js +++ b/src/env.js @@ -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