first commit

This commit is contained in:
mstfyldz
2026-08-16 17:18:23 +03:00
commit 5ace6898b6
61 changed files with 12065 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
import { NextResponse } from "next/server";
import { isAdminAuthenticated, ADMIN_USERNAME } from "@/lib/auth";
export async function GET() {
const authenticated = await isAdminAuthenticated();
return NextResponse.json({
authenticated,
username: authenticated ? ADMIN_USERNAME : null,
});
}
+40
View File
@@ -0,0 +1,40 @@
import { NextResponse } from "next/server";
import { validateCredentials, createSessionToken, COOKIE_NAME } from "@/lib/auth";
export async function POST(request: Request) {
try {
const { username, password } = await request.json();
if (!validateCredentials(username, password)) {
return NextResponse.json(
{ error: "Kullanıcı adı veya şifre hatalı!" },
{ status: 401 }
);
}
const token = createSessionToken(username);
const response = NextResponse.json({
success: true,
message: "Giriş başarılı",
username,
});
response.cookies.set({
name: COOKIE_NAME,
value: token,
httpOnly: true,
secure: process.env.NODE_ENV === "production",
sameSite: "lax",
path: "/",
maxAge: 7 * 24 * 60 * 60, // 7 days
});
return response;
} catch (error) {
console.error("Login error:", error);
return NextResponse.json(
{ error: "Giriş işlemi sırasında sunucu hatası oluştu" },
{ status: 500 }
);
}
}
+19
View File
@@ -0,0 +1,19 @@
import { NextResponse } from "next/server";
import { COOKIE_NAME } from "@/lib/auth";
export async function POST() {
const response = NextResponse.json({
success: true,
message: "Çıkış yapıldı",
});
response.cookies.set({
name: COOKIE_NAME,
value: "",
httpOnly: true,
expires: new Date(0),
path: "/",
});
return response;
}
+30
View File
@@ -0,0 +1,30 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
export async function POST(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const body = await request.json();
const { increment } = body;
const updatedPost = await prisma.post.update({
where: { id },
data: {
likes: {
increment: increment !== undefined ? (increment ? 1 : -1) : 1,
},
},
});
return NextResponse.json(updatedPost);
} catch (error) {
console.error("Error updating likes:", error);
return NextResponse.json(
{ error: "Failed to update likes" },
{ status: 500 }
);
}
}
+104
View File
@@ -0,0 +1,104 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { isAdminAuthenticated } from "@/lib/auth";
export async function PUT(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const isAuth = await isAdminAuthenticated();
if (!isAuth) {
return NextResponse.json(
{ error: "Bu işlem için yetkiniz yok (Admin girişi gerekli)" },
{ status: 401 }
);
}
const { id } = await params;
const body = await request.json();
const {
type,
date,
timestamp,
mood,
moodLabel,
title,
content,
marginNotes,
tags,
likes,
highlightWords,
authorNote,
imageUrl,
imageCaption,
codeSnippet,
codeLanguage,
audioDuration,
audioTitle,
stampedText,
} = body;
const updatedPost = await prisma.post.update({
where: { id },
data: {
type,
date,
timestamp,
mood,
moodLabel,
title,
content,
marginNotes: marginNotes || [],
tags: tags || [],
likes: likes !== undefined ? likes : undefined,
highlightWords: highlightWords || [],
authorNote,
imageUrl,
imageCaption,
codeSnippet,
codeLanguage,
audioDuration,
audioTitle,
stampedText,
},
});
return NextResponse.json(updatedPost);
} catch (error) {
console.error("Error updating post:", error);
return NextResponse.json(
{ error: "Not güncellenirken sunucu hatası oluştu" },
{ status: 500 }
);
}
}
export async function DELETE(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const isAuth = await isAdminAuthenticated();
if (!isAuth) {
return NextResponse.json(
{ error: "Bu işlem için yetkiniz yok (Admin girişi gerekli)" },
{ status: 401 }
);
}
const { id } = await params;
await prisma.post.delete({
where: { id },
});
return NextResponse.json({ success: true, message: "Not silindi" });
} catch (error) {
console.error("Error deleting post:", error);
return NextResponse.json(
{ error: "Not silinirken sunucu hatası oluştu" },
{ status: 500 }
);
}
}
+80
View File
@@ -0,0 +1,80 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
export async function GET() {
try {
const posts = await prisma.post.findMany({
orderBy: {
createdAt: "desc",
},
});
return NextResponse.json(posts);
} catch (error) {
console.error("Error fetching posts:", error);
return NextResponse.json(
{ error: "Failed to fetch posts from database" },
{ status: 500 }
);
}
}
export async function POST(request: Request) {
try {
const body = await request.json();
const {
id,
type,
date,
timestamp,
mood,
moodLabel,
title,
content,
marginNotes,
tags,
likes,
highlightWords,
authorNote,
imageUrl,
imageCaption,
codeSnippet,
codeLanguage,
audioDuration,
audioTitle,
stampedText,
} = body;
const newPost = await prisma.post.create({
data: {
id: id || `post-${Date.now()}`,
type,
date,
timestamp,
mood,
moodLabel,
title,
content,
marginNotes: marginNotes || [],
tags: tags || [],
likes: likes || 0,
highlightWords: highlightWords || [],
authorNote,
imageUrl,
imageCaption,
codeSnippet,
codeLanguage,
audioDuration,
audioTitle,
stampedText,
},
});
return NextResponse.json(newPost, { status: 201 });
} catch (error) {
console.error("Error creating post:", error);
return NextResponse.json(
{ error: "Failed to create post in database" },
{ status: 500 }
);
}
}