From a84c655c58db88db9a2f4b5fc0683e47941de6b7 Mon Sep 17 00:00:00 2001 From: Ahmet Kilinc Date: Sat, 20 Dec 2025 03:59:04 +0000 Subject: [PATCH] fix? --- app/api/debug/r2/route.ts | 43 ++++++++++++++++++++++++++++++++++ app/api/git/[...path]/route.ts | 17 +------------- 2 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 app/api/debug/r2/route.ts diff --git a/app/api/debug/r2/route.ts b/app/api/debug/r2/route.ts new file mode 100644 index 0000000..4e3e37d --- /dev/null +++ b/app/api/debug/r2/route.ts @@ -0,0 +1,43 @@ +import { NextRequest, NextResponse } from "next/server"; +import { r2List, r2Get } from "@/lib/r2"; +import { db } from "@/db"; +import { users } from "@/db/schema"; +import { eq } from "drizzle-orm"; +import { getRepoPrefix } from "@/lib/r2-fs"; + +export async function GET(request: NextRequest) { + const { searchParams } = new URL(request.url); + const username = searchParams.get("username"); + const repo = searchParams.get("repo"); + + if (!username || !repo) { + return NextResponse.json({ error: "Missing username or repo" }, { status: 400 }); + } + + const user = await db.query.users.findFirst({ + where: eq(users.username, username), + }); + + if (!user) { + return NextResponse.json({ error: "User not found" }, { status: 404 }); + } + + const repoPrefix = getRepoPrefix(user.id, `${repo}.git`); + const allKeys = await r2List(repoPrefix + "/"); + + const head = await r2Get(`${repoPrefix}/HEAD`); + const config = await r2Get(`${repoPrefix}/config`); + + const refsHeadsMain = await r2Get(`${repoPrefix}/refs/heads/main`); + const refsMaster = await r2Get(`${repoPrefix}/refs/heads/master`); + + return NextResponse.json({ + repoPrefix, + totalKeys: allKeys.length, + keys: allKeys.slice(0, 100), + head: head?.toString(), + config: config?.toString(), + "refs/heads/main": refsHeadsMain?.toString(), + "refs/heads/master": refsMaster?.toString(), + }); +} diff --git a/app/api/git/[...path]/route.ts b/app/api/git/[...path]/route.ts index 111e7e4..3096272 100644 --- a/app/api/git/[...path]/route.ts +++ b/app/api/git/[...path]/route.ts @@ -36,10 +36,7 @@ async function verifyPassword(password: string, hash: string): Promise } async function authenticateUser(authHeader: string | null): Promise<{ id: string; username: string } | null> { - console.log("[Git Auth] Starting authentication"); - if (!authHeader || !authHeader.startsWith("Basic ")) { - console.log("[Git Auth] No auth header or not Basic auth"); return null; } @@ -47,10 +44,7 @@ async function authenticateUser(authHeader: string | null): Promise<{ id: string const credentials = Buffer.from(base64Credentials, "base64").toString("utf-8"); const [email, password] = credentials.split(":"); - console.log("[Git Auth] Email:", email); - if (!email || !password) { - console.log("[Git Auth] Missing email or password"); return null; } @@ -59,8 +53,6 @@ async function authenticateUser(authHeader: string | null): Promise<{ id: string where: eq(users.email, email), }); - console.log("[Git Auth] User found:", !!user); - if (!user) { return null; } @@ -69,24 +61,17 @@ async function authenticateUser(authHeader: string | null): Promise<{ id: string where: eq(accounts.userId, user.id), }); - console.log("[Git Auth] Account found:", !!account, "providerId:", account?.providerId, "hasPassword:", !!account?.password); - if (!account?.password) { return null; } - console.log("[Git Auth] Password hash format:", account.password.substring(0, 20) + "..."); - const valid = await verifyPassword(password, account.password); - console.log("[Git Auth] Password valid:", valid); - if (!valid) { return null; } return { id: user.id, username: user.username }; - } catch (err) { - console.error("[Git Auth] Error:", err); + } catch { return null; } }