mirror of
https://github.com/r-freeman/portfolio.git
synced 2025-04-22 19:54:36 +00:00
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 3m10s
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import {createClient} from '@/lib/supabase/server'
|
|
import {headers} from 'next/headers'
|
|
|
|
export async function PATCH(request: Request, {params}: { params: Promise<{ id: number }> }) {
|
|
const {id} = await params
|
|
const headersList = await headers()
|
|
const authorizationHeader = headersList.get('authorization')
|
|
|
|
if (authorizationHeader === `Bearer ${process.env.NTFY_TOKEN}`) {
|
|
if (typeof id !== 'undefined') {
|
|
const supabase = await createClient()
|
|
|
|
await supabase.from('comments')
|
|
.update({published: true})
|
|
.eq('id', id)
|
|
|
|
return new Response(null, {status: 204})
|
|
}
|
|
return new Response(JSON.stringify({status: 'Not Found'}), {status: 404})
|
|
}
|
|
|
|
return new Response(JSON.stringify({status: 'Unauthorized'}), {status: 401})
|
|
}
|
|
|
|
export async function DELETE(request: Request, {params}: { params: Promise<{ id: number }> }) {
|
|
const {id} = await params
|
|
const headersList = await headers()
|
|
const authorizationHeader = headersList.get('authorization')
|
|
|
|
if (authorizationHeader === `Bearer ${process.env.NTFY_TOKEN}`) {
|
|
if (typeof id !== 'undefined') {
|
|
const supabase = await createClient()
|
|
|
|
await supabase.from('comments')
|
|
.delete()
|
|
.eq('id', id)
|
|
|
|
return new Response(null, {status: 204})
|
|
}
|
|
return new Response(JSON.stringify({status: 'Not Found'}), {status: 404})
|
|
}
|
|
|
|
return new Response(JSON.stringify({status: 'Unauthorized'}), {status: 401})
|
|
} |