Aktueller Stand
This commit is contained in:
39
app/api/settings/app-name/route.ts
Normal file
39
app/api/settings/app-name/route.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "../../../../lib/prisma";
|
||||
import { isSuperAdminSession, requireSession } from "../../../../lib/auth-helpers";
|
||||
|
||||
const DEFAULT_APP_NAME = "Vereinskalender";
|
||||
|
||||
export async function GET() {
|
||||
const setting = await prisma.setting.findUnique({
|
||||
where: { key: "app_name" }
|
||||
});
|
||||
return NextResponse.json({ name: setting?.value || DEFAULT_APP_NAME });
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const { session } = await requireSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
if (!isSuperAdminSession(session)) {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const name = String(body?.name || "").trim();
|
||||
if (!name) {
|
||||
return NextResponse.json({ error: "Name erforderlich." }, { status: 400 });
|
||||
}
|
||||
if (name.length > 60) {
|
||||
return NextResponse.json({ error: "Name ist zu lang." }, { status: 400 });
|
||||
}
|
||||
|
||||
await prisma.setting.upsert({
|
||||
where: { key: "app_name" },
|
||||
update: { value: name },
|
||||
create: { key: "app_name", value: name }
|
||||
});
|
||||
|
||||
return NextResponse.json({ name });
|
||||
}
|
||||
@@ -16,6 +16,7 @@ const MIME_TO_EXT: Record<string, string> = {
|
||||
"image/webp": "webp",
|
||||
"image/svg+xml": "svg"
|
||||
};
|
||||
const MAX_FILE_SIZE = 2 * 1024 * 1024;
|
||||
|
||||
const resolveLogoPath = (relativePath: string) => {
|
||||
const absolutePath = path.join(DATA_DIR, relativePath);
|
||||
@@ -51,6 +52,9 @@ export async function POST(request: Request) {
|
||||
if (!extension) {
|
||||
return NextResponse.json({ error: "Dateityp nicht unterstützt." }, { status: 400 });
|
||||
}
|
||||
if (file.size > MAX_FILE_SIZE) {
|
||||
return NextResponse.json({ error: "Datei ist zu groß (max. 2 MB)." }, { status: 400 });
|
||||
}
|
||||
|
||||
await fs.mkdir(UPLOADS_DIR, { recursive: true });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user