mirror of
https://gitbruv.vercel.app/api/git/bruv/gitbruv.git
synced 2025-12-20 23:24:09 +01:00
update
This commit is contained in:
parent
468781e311
commit
1055bd7f07
8 changed files with 416 additions and 85 deletions
|
|
@ -1,7 +1,9 @@
|
|||
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";
|
||||
|
|
@ -28,12 +30,15 @@ const LANGUAGE_MAP: Record<string, string> = {
|
|||
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) {
|
||||
|
|
@ -42,6 +47,21 @@ async function FileContent({ username, repoName, branch, filePath }: { username:
|
|||
|
||||
const fileName = filePath.split("/").pop() || "";
|
||||
const language = getLanguage(fileName);
|
||||
const fileSize = new TextEncoder().encode(file.content).length;
|
||||
|
||||
if (fileSize > SMALL_FILE_THRESHOLD) {
|
||||
return (
|
||||
<ChunkedCodeViewer
|
||||
username={username}
|
||||
repoName={repoName}
|
||||
branch={branch}
|
||||
filePath={filePath}
|
||||
language={language}
|
||||
initialContent={file.content}
|
||||
totalSize={fileSize}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <CodeViewer content={file.content} language={language} showLineNumbers />;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { Suspense } from "react";
|
||||
import { notFound } from "next/navigation";
|
||||
import { connection } from "next/server";
|
||||
import { getRepoPageData, getRepoReadme, getRepoCommitCountCached } from "@/actions/repositories";
|
||||
import { FileTree } from "@/components/file-tree";
|
||||
import { CodeViewer } from "@/components/code-viewer";
|
||||
|
|
@ -13,6 +14,7 @@ import Link from "next/link";
|
|||
import { getPublicServerUrl } from "@/lib/utils";
|
||||
|
||||
async function CommitCount({ username, repoName, branch }: { username: string; repoName: string; branch: string }) {
|
||||
await connection();
|
||||
const commitCount = await getRepoCommitCountCached(username, repoName);
|
||||
|
||||
if (commitCount === 0) return null;
|
||||
|
|
@ -30,6 +32,7 @@ async function CommitCount({ username, repoName, branch }: { username: string; r
|
|||
}
|
||||
|
||||
async function ReadmeSection({ username, repoName, readmeOid }: { username: string; repoName: string; readmeOid: string }) {
|
||||
await connection();
|
||||
const content = await getRepoReadme(username, repoName, readmeOid);
|
||||
|
||||
if (!content) return null;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
import { Suspense } from "react";
|
||||
import { notFound } from "next/navigation";
|
||||
import { db } from "@/db";
|
||||
import { users } from "@/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { getUserRepositoriesWithStars, getUserStarredRepos } from "@/actions/repositories";
|
||||
import { connection } from "next/server";
|
||||
import { getUserRepositoriesWithStars, getUserStarredRepos, getUserProfile } from "@/actions/repositories";
|
||||
import { RepoList } from "@/components/repo-list";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
|
|
@ -13,6 +11,7 @@ import Link from "next/link";
|
|||
import { GithubIcon, XIcon, LinkedInIcon } from "@/components/icons";
|
||||
|
||||
async function RepositoriesTab({ username }: { username: string }) {
|
||||
await connection();
|
||||
const repos = await getUserRepositoriesWithStars(username);
|
||||
|
||||
if (repos.length === 0) {
|
||||
|
|
@ -29,6 +28,7 @@ async function RepositoriesTab({ username }: { username: string }) {
|
|||
}
|
||||
|
||||
async function StarredTab({ username }: { username: string }) {
|
||||
await connection();
|
||||
const repos = await getUserStarredRepos(username);
|
||||
|
||||
if (repos.length === 0) {
|
||||
|
|
@ -65,9 +65,7 @@ export default async function ProfilePage({ params, searchParams }: { params: Pr
|
|||
const { username } = await params;
|
||||
const { tab } = await searchParams;
|
||||
|
||||
const user = await db.query.users.findFirst({
|
||||
where: eq(users.username, username),
|
||||
});
|
||||
const user = await getUserProfile(username);
|
||||
|
||||
if (!user) {
|
||||
notFound();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue