Skip to content

Commit

Permalink
feat: add delete oauth app for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jan 15, 2023
1 parent 2e79798 commit ba5b89d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default defineNuxtConfig({
},
},
runtimeConfig: {
adminKey: '',
cloudflare: {
accountId: '',
namespaceId: '',
Expand Down
13 changes: 13 additions & 0 deletions server/api/[server]/clear.ts
Original file line number Diff line number Diff line change
@@ -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 }
})
6 changes: 6 additions & 0 deletions server/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>()
Expand Down

0 comments on commit ba5b89d

Please sign in to comment.