mirror of
https://github.com/ershisan99/www.git
synced 2026-01-26 21:12:05 +00:00
add refresh logic
This commit is contained in:
28
src/app/api/refresh-history/route.ts
Normal file
28
src/app/api/refresh-history/route.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { env } from '@/env'
|
||||
import { syncHistory } from '@/server/api/routers/history'
|
||||
import { headers } from 'next/headers'
|
||||
|
||||
const SECURE_TOKEN = env.CRON_SECRET
|
||||
|
||||
export async function POST() {
|
||||
const headersList = await headers()
|
||||
const authToken = headersList.get('authorization')?.replace('Bearer ', '')
|
||||
|
||||
if (authToken !== SECURE_TOKEN) {
|
||||
return new Response('unauthorized', { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
try {
|
||||
console.log('refreshing history...')
|
||||
await syncHistory()
|
||||
} catch (err) {
|
||||
console.error('history refresh failed:', err)
|
||||
return new Response('internal error', { status: 500 })
|
||||
}
|
||||
return Response.json({ success: true })
|
||||
} catch (err) {
|
||||
console.error('refresh failed:', err)
|
||||
return new Response('internal error', { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user