mirror of
https://gitlab.w-hs.de/an14051/backerup-website.git
synced 2026-07-27 17:35:29 +00:00
feat: add admin links management and updaterup page
- Implemented AdminLinksPage for managing link entries with admin role check. - Created API routes for fetching, updating, and deleting link entries. - Added ProductTabs component for navigation between Backerup and Updaterup. - Developed UpdaterupPage with detailed features, setup instructions, and statistics. - Introduced links database functionality for runtime-editable link overrides.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { getSession } from '@/lib/session'
|
||||
import { resetLink, type LinkKey } from '@/lib/links-db'
|
||||
import { LINKS } from '@/lib/links'
|
||||
|
||||
export async function DELETE(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ key: string }> },
|
||||
) {
|
||||
const session = await getSession()
|
||||
if (!session || session.role !== 'admin') {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
||||
}
|
||||
|
||||
const { key } = await params
|
||||
if (!(key in LINKS)) {
|
||||
return NextResponse.json({ error: 'Unknown link key' }, { status: 400 })
|
||||
}
|
||||
|
||||
await resetLink(key as LinkKey)
|
||||
return NextResponse.json({ ok: true })
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { getSession } from '@/lib/session'
|
||||
import { getAllLinkEntries, setLink, type LinkKey } from '@/lib/links-db'
|
||||
import { LINKS } from '@/lib/links'
|
||||
|
||||
export async function GET() {
|
||||
const session = await getSession()
|
||||
if (!session || session.role !== 'admin') {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
||||
}
|
||||
const entries = await getAllLinkEntries()
|
||||
return NextResponse.json(entries)
|
||||
}
|
||||
|
||||
export async function PUT(request: Request) {
|
||||
const session = await getSession()
|
||||
if (!session || session.role !== 'admin') {
|
||||
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
||||
}
|
||||
|
||||
let body: { key?: string; value?: string }
|
||||
try {
|
||||
body = (await request.json()) as { key?: string; value?: string }
|
||||
} catch {
|
||||
return NextResponse.json({ error: 'Invalid JSON' }, { status: 400 })
|
||||
}
|
||||
|
||||
const key = String(body.key ?? '').trim() as LinkKey
|
||||
const value = String(body.value ?? '').trim()
|
||||
|
||||
if (!key || !(key in LINKS)) {
|
||||
return NextResponse.json({ error: 'Unknown link key' }, { status: 400 })
|
||||
}
|
||||
if (!value) {
|
||||
return NextResponse.json({ error: 'Value cannot be empty' }, { status: 400 })
|
||||
}
|
||||
|
||||
await setLink(key, value)
|
||||
return NextResponse.json({ ok: true })
|
||||
}
|
||||
Reference in New Issue
Block a user