From 33c50765e77fbb960fe0d59ab70586d358417b78 Mon Sep 17 00:00:00 2001 From: mbaharip <62494292+mbahArip@users.noreply.github.com> Date: Fri, 24 Jan 2025 17:46:24 +0700 Subject: [PATCH] update: Separate internal to it's own route file --- src/app/[...rest]/page.tsx | 79 ++----------------- src/app/ngdi-internal/configurator/page.tsx | 14 ++++ src/app/ngdi-internal/deploy/page.tsx | 14 ++++ .../ngdi-internal/embed/[...rest]/page.tsx | 77 ++++++++++++++++++ src/app/ngdi-internal/page.tsx | 21 +++++ 5 files changed, 132 insertions(+), 73 deletions(-) create mode 100644 src/app/ngdi-internal/configurator/page.tsx create mode 100644 src/app/ngdi-internal/deploy/page.tsx create mode 100644 src/app/ngdi-internal/embed/[...rest]/page.tsx create mode 100644 src/app/ngdi-internal/page.tsx diff --git a/src/app/[...rest]/page.tsx b/src/app/[...rest]/page.tsx index e6c765c..427cae9 100644 --- a/src/app/[...rest]/page.tsx +++ b/src/app/[...rest]/page.tsx @@ -2,8 +2,7 @@ import { type Metadata, type ResolvedMetadata } from "next"; import { notFound } from "next/navigation"; import { FileActions, FileBreadcrumb, FileExplorerLayout, FileReadme } from "~/components/explorer"; -import { Status } from "~/components/global"; -import { Password } from "~/components/layout"; +import { ErrorComponent, Password } from "~/components/layout"; import { PreviewLayout } from "~/components/preview"; import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card"; @@ -15,44 +14,17 @@ import { CheckPagePassword } from "~/actions/password"; import { ValidatePaths } from "~/actions/paths"; import { CreateFileToken } from "~/actions/token"; -import ErrorComponent from "../error"; -import ConfiguratorPage from "./ConfiguratorPage"; -import DeployPage from "./DeployPage"; -import EmbedPage from "./EmbedPage"; - export const revalidate = 60; export const dynamic = "force-dynamic"; -export const dynamicParams = false; type Props = { params: Promise<{ rest: string[]; }>; }; -const internal = (paths: string[]) => { - const joinedPaths = (paths.join("/").startsWith("/") ? paths.join("/") : `/${paths.join("/")}`).replace(/\/+/g, "/"); - - return { - isInternalRoot: joinedPaths === "/_", - isGuidePage: joinedPaths === "/_/deploy", - isConfiguratorPage: joinedPaths === "/_/configurator", - isEmbedRootPage: joinedPaths === "/_/embed", - isEmbedPage: joinedPaths.startsWith("/_/embed/"), - }; -}; export async function generateMetadata({ params }: Props, parent: ResolvedMetadata): Promise { - const p = await params; - let rest = p.rest; - const { isInternalRoot, isGuidePage, isConfiguratorPage, isEmbedPage, isEmbedRootPage } = internal(p.rest); - if (isInternalRoot) - return { title: "Reserved Internal Path", description: "This path is reserved for internal pages" }; - if (isGuidePage) return { title: "Guide", description: "Read on how to deploy your own index" }; - if (isConfiguratorPage) return { title: "Configurator", description: "Configure your index" }; - if (isEmbedRootPage) return { title: "Not Found" }; - if (isEmbedPage) { - rest = rest.slice(2); - } + const { rest } = await params; const paths = await ValidatePaths(rest); if (!paths.success) return { title: "Not Found" }; @@ -61,14 +33,10 @@ export async function generateMetadata({ params }: Props, parent: ResolvedMetada if (!currentPath?.id) return { title: "Not Found" }; const banner = await GetBanner(currentPath.id); - if (isEmbedPage && !currentPath.mimeType.includes("video") && !currentPath.mimeType.includes("audio")) - return { title: "Not Found" }; return { - title: isEmbedPage ? `${decodeURIComponent(currentPath.path)} (embed)` : decodeURIComponent(currentPath.path), - description: isEmbedPage - ? `Embed ${currentPath.path}` - : currentPath.mimeType.includes("folder") + title: decodeURIComponent(currentPath.path), + description: currentPath.mimeType.includes("folder") ? `Browse ${currentPath.path} files` : `View ${currentPath.path}`, openGraph: { @@ -85,29 +53,12 @@ export async function generateMetadata({ params }: Props, parent: ResolvedMetada }; } export default async function RestPage({ params }: Props) { - const p = await params; - let rest = p.rest; - const { isInternalRoot, isConfiguratorPage, isEmbedPage, isEmbedRootPage, isGuidePage } = internal(p.rest); - if (isInternalRoot) - return ( -
- -
- ); - if (isGuidePage) return ; - if (isConfiguratorPage) return ; - if (isEmbedRootPage) return notFound(); - if (isEmbedPage) rest = rest.slice(2); + const { rest } = await params; const paths = await ValidatePaths(rest); if (!paths.success) notFound(); const unlocked = await CheckPagePassword(paths.data); - if (!unlocked.success && isEmbedPage) - return ; if (!unlocked.success) { return ( ; const Layout: React.FC<{ @@ -137,7 +88,6 @@ export default async function RestPage({ params }: Props) { ); if (currentPath.mimeType.includes("folder")) { - if (isEmbedPage) return ; const [data, readme] = await Promise.all([ListFiles({ id: currentPath.id }), GetReadme(currentPath.id)]); if (!data.success) return ; if (!readme.success) return ; @@ -181,23 +131,6 @@ export default async function RestPage({ params }: Props) { const token = await CreateFileToken(file.data); if (!token.success) return ; - if (isEmbedPage) { - if (!currentPath.mimeType.includes("video") && !currentPath.mimeType.includes("audio")) - return ( -
- -
- ); - return ( -
- -
- ); - } - return ( ; +} diff --git a/src/app/ngdi-internal/deploy/page.tsx b/src/app/ngdi-internal/deploy/page.tsx new file mode 100644 index 0000000..42da795 --- /dev/null +++ b/src/app/ngdi-internal/deploy/page.tsx @@ -0,0 +1,14 @@ +import { type Metadata } from "next"; + +import { DeployPage } from "~/components/internal"; + +export const dynamic = "force-static"; + +export const metadata: Metadata = { + title: "Deploying Guide", + description: "Read on how to deploy your own index instance", +}; + +export default function InternalDeployPage() { + return ; +} diff --git a/src/app/ngdi-internal/embed/[...rest]/page.tsx b/src/app/ngdi-internal/embed/[...rest]/page.tsx new file mode 100644 index 0000000..73834ad --- /dev/null +++ b/src/app/ngdi-internal/embed/[...rest]/page.tsx @@ -0,0 +1,77 @@ +import { type Metadata, type ResolvedMetadata } from "next"; +import { notFound } from "next/navigation"; + +import { EmbedPage } from "~/components/internal"; +import { ErrorComponent } from "~/components/layout"; + +import { GetFile } from "~/actions/files"; +import { CheckPagePassword } from "~/actions/password"; +import { ValidatePaths } from "~/actions/paths"; +import { CreateFileToken } from "~/actions/token"; + +export const revalidate = 60; +export const dynamic = "force-dynamic"; + +type Props = { + params: Promise<{ + rest: string[]; + }>; +}; + +export async function generateMetadata({ params }: Props, parent: ResolvedMetadata): Promise { + const { rest } = await params; + + const paths = await ValidatePaths(rest); + if (!paths.success) return { title: "Not Found" }; + + const currentPath = paths.data.pop(); + if (!currentPath?.id) return { title: "Not Found" }; + + if (!currentPath.mimeType.includes("video") && !currentPath.mimeType.includes("audio")) return { title: "Not Found" }; + + return { + title: `${decodeURIComponent(currentPath.path)} (embed)`, + description: `Embed view of ${currentPath.path}`, + openGraph: { + images: parent.openGraph?.images, + }, + }; +} + +export default async function InternalEmbedPage({ params }: Props) { + const { rest } = await params; + + const paths = await ValidatePaths(rest); + if (!paths.success) notFound(); + + const unlocked = await CheckPagePassword(paths.data); + if (!unlocked.success) return ; + + const currentPath = paths.data.pop(); + if (!currentPath) return ; + + if (!currentPath.mimeType.includes("video") && !currentPath.mimeType.includes("audio")) + return ( +
+ +
+ ); + + const file = await GetFile(currentPath.id); + if (!file.success) { + if (file.error === "NotFound") notFound(); + return ; + } + if (!file.data) return ; + const token = await CreateFileToken(file.data); + if (!token.success) return ; + + return ( +
+ +
+ ); +} diff --git a/src/app/ngdi-internal/page.tsx b/src/app/ngdi-internal/page.tsx new file mode 100644 index 0000000..2714412 --- /dev/null +++ b/src/app/ngdi-internal/page.tsx @@ -0,0 +1,21 @@ +import { type Metadata } from "next"; + +import { Status } from "~/components/global"; + +export const dynamic = "force-static"; + +export const metadata: Metadata = { + title: "Reserved Internal Path", + description: "This path is preserved for all internal pages, make sure you don't use this path on your google drive", +}; + +export default async function InternalRootPage() { + return ( +
+ +
+ ); +}