first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 22:09:32 +03:00
commit 71eff2d979
78 changed files with 10173 additions and 0 deletions

77
app/api/images/route.ts Normal file
View File

@@ -0,0 +1,77 @@
import { NextRequest, NextResponse } from "next/server";
import { db } from "@/db";
import { images } from "@/db/schema";
import { eq, desc } from "drizzle-orm";
import { auth } from "@/app/lib/auth";
async function getUserId(request: NextRequest): Promise<string | null> {
try {
const session = await auth.api.getSession({
headers: request.headers,
});
return session?.user?.id || null;
} catch {
return null;
}
}
function getBaseUrl(request: NextRequest): string {
// First, check environment variables (production should set this)
if (process.env.NEXT_PUBLIC_APP_URL) {
return process.env.NEXT_PUBLIC_APP_URL;
}
if (process.env.APP_URL) {
return process.env.APP_URL;
}
// Check for reverse proxy headers (X-Forwarded-Host, X-Forwarded-Proto)
const forwardedHost = request.headers.get("x-forwarded-host");
const forwardedProto = request.headers.get("x-forwarded-proto");
if (forwardedHost && forwardedProto) {
return `${forwardedProto}://${forwardedHost}`;
}
// Fallback to request origin
return request.nextUrl.origin;
}
export async function GET(request: NextRequest) {
try {
const userId = await getUserId(request);
if (!userId) {
return NextResponse.json(
{ message: "Yetkisiz erişim" },
{ status: 401 }
);
}
const userImages = await db
.select()
.from(images)
.where(eq(images.userId, userId))
.orderBy(desc(images.createdAt));
// Get base URL
const baseUrl = getBaseUrl(request);
return NextResponse.json({
images: userImages.map((img) => ({
id: img.id,
originalName: img.originalName,
url: `${baseUrl}${img.url}`,
width: img.width,
height: img.height,
quality: img.quality,
format: img.format,
fileSize: img.fileSize,
createdAt: img.createdAt.toISOString(),
})),
});
} catch (error: any) {
return NextResponse.json(
{ message: "Resimler yüklenemedi" },
{ status: 500 }
);
}
}