Admin panel shows a prominent open/closed toggle above the tabs. When closed, the shop displays a branded closure message and the checkout API returns 503. The closure state persists in data/store-status.json. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
24 lines
772 B
TypeScript
24 lines
772 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { getStoreStatus, setStoreStatus } from '@/lib/store-status'
|
|
import { cookies } from 'next/headers'
|
|
|
|
function isAuthed() {
|
|
return cookies().get('bpb_admin')?.value === 'true'
|
|
}
|
|
|
|
export async function GET() {
|
|
if (!isAuthed()) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
return NextResponse.json(await getStoreStatus())
|
|
}
|
|
|
|
export async function PUT(req: NextRequest) {
|
|
if (!isAuthed()) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
const body = await req.json()
|
|
const status = {
|
|
closed: Boolean(body.closed),
|
|
message: String(body.message ?? '').trim(),
|
|
}
|
|
await setStoreStatus(status)
|
|
return NextResponse.json({ ok: true, ...status })
|
|
}
|