feat: add delete oauth app for admin

This commit is contained in:
三咲智子 Kevin Deng 2023-01-15 17:34:17 +08:00
parent 2e7979817a
commit ba5b89d5b8
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E
4 changed files with 22 additions and 0 deletions

View file

@ -10,6 +10,8 @@ NUXT_CLOUDFLARE_API_TOKEN=
NUXT_STORAGE_DRIVER=
NUXT_STORAGE_FS_BASE=
NUXT_ADMIN_KEY=
NUXT_PUBLIC_DISABLE_VERSION_CHECK=
NUXT_GITHUB_CLIENT_ID=

View file

@ -76,6 +76,7 @@ export default defineNuxtConfig({
},
},
runtimeConfig: {
adminKey: '',
cloudflare: {
accountId: '',
namespaceId: '',

View file

@ -0,0 +1,13 @@
import { deleteApp } from '~~/server/shared'
export default defineEventHandler(async (event) => {
const { server } = getRouterParams(event)
const { key } = getQuery(event)
if (key !== String(useRuntimeConfig().adminKey))
return { status: false, error: 'incorrect key' }
await deleteApp(server)
return { status: true }
})

View file

@ -63,6 +63,12 @@ export async function getApp(origin: string, server: string) {
}
}
export async function deleteApp(server: string) {
const keys = (await storage.getKeys('servers:')).filter(k => k.endsWith(`${server}.json`))
for (const key of keys)
await storage.removeItem(key)
}
export async function listServers() {
const keys = await storage.getKeys('servers:')
const servers = new Set<string>()