feat: copy full API key on-demand di halaman dev

Sebelumnya copy button mengcopy key yang sudah ter-mask dari list endpoint
Desa+ API. Sekarang klik copy fetch full key via GET /api-keys/:id lalu
salin ke clipboard.
This commit is contained in:
2026-05-25 11:59:54 +08:00
parent e32addbc85
commit a19846f589
2 changed files with 37 additions and 23 deletions

View File

@@ -1688,6 +1688,19 @@ export function createApp() {
return { keys: json.data ?? [] }
})
.get('/api/admin/api-keys/:id', async ({ request, set, params }) => {
const auth = await requireDeveloper(request, set)
if (!auth) return { error: set.status === 401 ? 'Unauthorized' : 'Forbidden' }
const app = await prisma.app.findUnique({ where: { id: 'desa-plus' } })
if (!app?.urlApi) { set.status = 503; return { error: 'desa-plus belum dikonfigurasi' } }
const res = await fetch(`${app.urlApi.replace(/\/$/, '')}/api/monitoring/api-keys/${params.id}`, {
headers: { 'x-api-key': app.apiKey ?? '' },
})
const json = await res.json()
set.status = res.status
return json
})
.post('/api/admin/api-keys', async ({ request, set }) => {
const auth = await requireDeveloper(request, set)
if (!auth) return { error: set.status === 401 ? 'Unauthorized' : 'Forbidden' }