import { Suspense } from "react"; import { notFound } from "next/navigation"; import { connection } from "next/server"; import Link from "next/link"; import { getRepository, getRepoFile, getRepoBranches } from "@/actions/repositories"; import { ChunkedCodeViewer } from "@/components/chunked-code-viewer"; import { CodeViewer } from "@/components/code-viewer"; import { BranchSelector } from "@/components/branch-selector"; import { Badge } from "@/components/ui/badge"; import { Lock, Globe, ChevronRight, Home, FileCode, Loader2 } from "lucide-react"; const LANGUAGE_MAP: Record = { ts: "typescript", tsx: "typescript", js: "javascript", jsx: "javascript", py: "python", rb: "ruby", go: "go", rs: "rust", java: "java", md: "markdown", json: "json", yaml: "yaml", yml: "yaml", css: "css", html: "html", sh: "bash", bash: "bash", zsh: "bash", }; const SMALL_FILE_THRESHOLD = 50 * 1024; function getLanguage(filename: string): string { const ext = filename.split(".").pop()?.toLowerCase() || ""; return LANGUAGE_MAP[ext] || "text"; } async function FileContent({ username, repoName, branch, filePath }: { username: string; repoName: string; branch: string; filePath: string }) { await connection(); const file = await getRepoFile(username, repoName, branch, filePath); if (!file) { notFound(); } const fileName = filePath.split("/").pop() || ""; const language = getLanguage(fileName); const fileSize = new TextEncoder().encode(file.content).length; if (fileSize > SMALL_FILE_THRESHOLD) { return ( ); } return ; } function CodeSkeleton() { return (
); } export default async function BlobPage({ params }: { params: Promise<{ username: string; repo: string; path: string[] }> }) { const { username, repo: repoName, path: pathSegments } = await params; const branch = pathSegments[0]; const filePath = pathSegments.slice(1).join("/"); const [repo, branches] = await Promise.all([getRepository(username, repoName), getRepoBranches(username, repoName)]); if (!repo) { notFound(); } const pathParts = filePath.split("/").filter(Boolean); const fileName = pathParts[pathParts.length - 1]; return (
{username} / {repoName} {repo.visibility === "private" ? ( <> Private ) : ( <> Public )}
{fileName}
}>
); }