mirror of
https://github.com/elk-zone/elk
synced 2024-11-27 14:28:10 +09:00
feat(api): list servers
This commit is contained in:
parent
6c9908d030
commit
52a8ae47fe
@ -107,6 +107,9 @@ export default defineNuxtConfig({
|
||||
crawlLinks: false,
|
||||
routes: ['/', '/200.html'],
|
||||
},
|
||||
routeRules: {
|
||||
'/list-servers': { swr: true },
|
||||
},
|
||||
},
|
||||
app: {
|
||||
keepalive: true,
|
||||
|
10
server/api/list-servers.ts
Normal file
10
server/api/list-servers.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { defineEventHandler } from 'h3'
|
||||
import { listServers } from '~/server/shared'
|
||||
|
||||
let servers: string[]
|
||||
|
||||
export default defineEventHandler(async () => {
|
||||
if (!servers)
|
||||
servers = await listServers()
|
||||
return servers
|
||||
})
|
@ -64,3 +64,16 @@ export async function getApp(server: string) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function listServers() {
|
||||
const keys = await storage.getKeys()
|
||||
const servers = new Set<string>()
|
||||
for await (const key of keys) {
|
||||
if (!key.startsWith('servers:'))
|
||||
continue
|
||||
const id = key.split(':').pop()!.replace(/\.json$/, '')
|
||||
if (id)
|
||||
servers.add(id)
|
||||
}
|
||||
return Array.from(servers).sort()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user