2024-02-18 00:01:54 -05:00
|
|
|
import type { RequestHandler } from '@sveltejs/kit'
|
2024-04-05 02:00:17 -04:00
|
|
|
import { Connections } from '$lib/server/connections'
|
2024-02-18 00:01:54 -05:00
|
|
|
|
|
|
|
|
export const GET: RequestHandler = async ({ url }) => {
|
2024-05-28 00:46:34 -04:00
|
|
|
const ids = url.searchParams.get('id')?.replace(/\s/g, '').split(',')
|
|
|
|
|
if (!ids) return new Response('Missing id query parameter', { status: 400 })
|
2024-02-18 00:01:54 -05:00
|
|
|
|
2024-05-28 00:46:34 -04:00
|
|
|
const connections = (
|
|
|
|
|
await Promise.all(
|
|
|
|
|
ids.map((id) =>
|
|
|
|
|
Connections.getConnection(id)
|
|
|
|
|
?.getConnectionInfo()
|
|
|
|
|
.catch((reason) => {
|
|
|
|
|
console.error(`Failed to fetch connection info: ${reason}`)
|
|
|
|
|
return undefined
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
).filter((connection): connection is ConnectionInfo => connection?.id !== undefined)
|
2024-02-18 00:01:54 -05:00
|
|
|
|
|
|
|
|
return Response.json({ connections })
|
|
|
|
|
}
|