import { FileHeader } from "@/app/[domain]/components/fileHeader"; import { TopBar } from "@/app/[domain]/components/topBar"; import { Separator } from '@/components/ui/separator'; import { getFileSource, listRepositories } from '@/lib/server/searchService'; import { base64Decode, isServiceError } from "@/lib/utils"; import { CodePreview } from "./codePreview"; import { ErrorCode } from "@/lib/errorCodes"; import { LuFileX2, LuBookX } from "react-icons/lu"; import { getOrgFromDomain } from "@/data/org"; import { notFound } from "next/navigation"; import { ServiceErrorException } from "@/lib/serviceError"; interface BrowsePageProps { params: { path: string[]; domain: string; }; } export default async function BrowsePage({ params, }: BrowsePageProps) { const rawPath = decodeURIComponent(params.path.join('/')); const sentinalIndex = rawPath.search(/\/-\/(tree|blob)\//); if (sentinalIndex === -1) { notFound(); } const repoAndRevisionName = rawPath.substring(0, sentinalIndex).split('@'); const repoName = repoAndRevisionName[0]; const revisionName = repoAndRevisionName.length > 1 ? repoAndRevisionName[1] : undefined; const { path, pathType } = ((): { path: string, pathType: 'tree' | 'blob' } => { const path = rawPath.substring(sentinalIndex + '/-/'.length); const pathType = path.startsWith('tree/') ? 'tree' : 'blob'; switch (pathType) { case 'tree': return { path: path.substring('tree/'.length), pathType, }; case 'blob': return { path: path.substring('blob/'.length), pathType, }; } })(); const org = await getOrgFromDomain(params.domain); if (!org) { notFound(); } // @todo (bkellam) : We should probably have a endpoint to fetch repository metadata // given it's name or id. const reposResponse = await listRepositories(org.id); if (isServiceError(reposResponse)) { throw new ServiceErrorException(reposResponse); } const repo = reposResponse.List.Repos.find(r => r.Repository.Name === repoName); if (pathType === 'tree') { // @todo : proper tree handling return ( <> Tree view not supported ) } return (
{repo && ( <>
)}
{repo === undefined ? (
Repository not found
) : ( )}
) } interface CodePreviewWrapper { path: string, repoName: string, revisionName: string, orgId: number, } const CodePreviewWrapper = async ({ path, repoName, revisionName, orgId, }: CodePreviewWrapper) => { // @todo: this will depend on `pathType`. const fileSourceResponse = await getFileSource({ fileName: path, repository: repoName, branch: revisionName, }, orgId); if (isServiceError(fileSourceResponse)) { if (fileSourceResponse.errorCode === ErrorCode.FILE_NOT_FOUND) { return (
File not found
) } throw new ServiceErrorException(fileSourceResponse); } return ( ) }