Skip to content

Commit

Permalink
cleanup + start work on file page
Browse files Browse the repository at this point in the history
  • Loading branch information
RealFascinated committed Feb 28, 2025
1 parent fbff144 commit 0f5a0eb
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@
"tsx": "^4.19.3",
"typescript": "^5.7.3"
}
}
}
File renamed without changes.
68 changes: 68 additions & 0 deletions src/app/(pages)/(app)/(files)/file/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import FileVideoPlayer from "@/components/file/video-player";
import { env } from "@/lib/env";
import { getFileById } from "@/lib/helpers/file";
import { getFileName } from "@/lib/utils/file";
import { Metadata } from "next";
import { notFound } from "next/navigation";

type FilePageProps = {
params: Promise<{
id: string;
}>;
};

export async function generateMetadata({
params,
}: FilePageProps): Promise<Metadata> {
const { id } = await params;
const fileMeta = await getFileById(id);
if (!fileMeta) {
return notFound();
}

const fileName = getFileName(fileMeta);

return {
description: undefined, // remove it for now
openGraph: {
title: fileName,
images: {
url: `${env.NEXT_PUBLIC_WEBSITE_URL}/${fileName}`,
},
},
twitter: {
// Large image
card: "summary_large_image",
},
};
}

export default async function FilePage({ params }: FilePageProps) {
const { id } = await params;
const fileMeta = await getFileById(id);
if (!fileMeta) {
return notFound();
}

const url = `/${getFileName(fileMeta)}`;
const isImage = fileMeta.mimeType.startsWith("image");
const isVideo = fileMeta.mimeType.startsWith("video");

return (
<div className="flex w-full text-center justify-center">
<div className="bg-secondary/70 p-2 w-full md:w-4xl rounded-md flex flex-col items-center">
<span className="text-xl font-semibold">{getFileName(fileMeta)}</span>

{isImage && (
<img
src={url}
alt={`Image for ${getFileName(fileMeta)}`}
className="max-h-[70vh]"
/>
)}

{isVideo && <FileVideoPlayer url={url} className="max-h-[70vh]" />}
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { notFound } from "@/lib/api-commons";
import { getFileByThumbnailId } from "@/lib/helpers/file";
import { getUserById } from "@/lib/helpers/user";
import { getFileThumbnailPath } from "@/lib/utils/paths";
import { storage } from "@/storage/create-storage";
import { NextRequest, NextResponse } from "next/server";
Expand Down
2 changes: 1 addition & 1 deletion src/app/(pages)/(app)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function Home() {
export default function HomePage() {
return (
<div className="flex w-full text-center justify-center">
How did you get here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import NotificationSettings from "@/components/dashboard/user/settings/notificat
import UserSettings from "@/components/dashboard/user/settings/user-settings";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { getUser } from "@/lib/auth";
import { UserType } from "@/lib/db/schemas/auth-schema";
import { Metadata } from "next";

const tabs = [
Expand All @@ -17,7 +18,7 @@ const tabs = [
id: "config",
name: "Config",
description: "Manage your upload client configurations.",
content: (user: any) => <ConfigSettings user={user} />,
content: (user: UserType) => <ConfigSettings user={user} />,
},
{
id: "notifications",
Expand All @@ -37,7 +38,7 @@ export const metadata: Metadata = {
title: "Account Settings",
};

export default async function Dashboard() {
export default async function AccountSettingsPage() {
const user = await getUser();
return (
<div className="mx-auto w-full max-w-5xl self-start flex flex-col gap-5">
Expand Down
2 changes: 1 addition & 1 deletion src/app/(pages)/(dashboard)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const metadata: Metadata = {
title: "Dashboard",
};

export default async function Dashboard() {
export default async function DashboardPage() {
const user = await getUser();
return (
<div className="flex flex-col gap-4 w-full items-center">
Expand Down
3 changes: 3 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const metadata: Metadata = {
},
description: env.NEXT_PUBLIC_WEBSITE_DESCRIPTION,
icons: [{ rel: "icon", url: env.NEXT_PUBLIC_WEBSITE_LOGO }],
openGraph: {
siteName: env.NEXT_PUBLIC_WEBSITE_NAME,
},
};

export default function RootLayout({
Expand Down
11 changes: 2 additions & 9 deletions src/components/dashboard/user/files/file.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import FileExtensionIcon from "@/components/file-icon";
import FileVideoPlayer from "@/components/file/video-player";
import SimpleTooltip from "@/components/simple-tooltip";
import { Button } from "@/components/ui/button";
import { InlineCodeBlock } from "@/components/ui/code-block";
Expand Down Expand Up @@ -161,15 +162,7 @@ function FilePreview({ fileMeta }: { fileMeta: FileType }) {
/>
)}

{isVideo && (
<ReactPlayer
url={url}
volume={0.25}
playing
controls
className="max-h-[70vh]"
/>
)}
{isVideo && <FileVideoPlayer url={url} className="max-h-[70vh]" />}
</DialogContent>
</Dialog>
);
Expand Down
20 changes: 20 additions & 0 deletions src/components/file/video-player.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use client";

import ReactPlayer from "react-player";

type VideoPlayerProps = {
url: string;
className?: string;
};

export default function FileVideoPlayer({ url, className }: VideoPlayerProps) {
return (
<ReactPlayer
url={url}
volume={0.25}
playing
controls
className={className}
/>
);
}
4 changes: 2 additions & 2 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import { env } from "./env";
*
* @returns the current user (wtf is the type? x.x)
*/
export const getUser = async (): Promise<Session["user"]> => {
export const getUser = async (): Promise<schema.UserType> => {
const session = await auth.api.getSession({
headers: await headers(),
});
// This shouldn't happen
if (!session) {
redirect("/");
}
return session.user;
return session.user as schema.UserType;
};

export const auth = betterAuth({
Expand Down

0 comments on commit 0f5a0eb

Please sign in to comment.