2024-02-18 00:01:54 -05:00
|
|
|
import type { RequestHandler } from '@sveltejs/kit'
|
2024-07-04 02:54:24 -04:00
|
|
|
import { ConnectionFactory } from '$lib/server/api-helper'
|
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-07-04 02:54:24 -04:00
|
|
|
const connections = (await Promise.all(ids.map((id) => ConnectionFactory.getConnection(id).catch(() => null)))).filter((result): result is Connection => result !== null)
|
2024-02-18 00:01:54 -05:00
|
|
|
|
2024-06-21 03:35:00 -04:00
|
|
|
const getConnectionInfo = (connection: Connection) =>
|
|
|
|
|
connection.getConnectionInfo().catch((reason) => {
|
|
|
|
|
console.error(`Failed to fetch connection info: ${reason}`)
|
|
|
|
|
return null
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const connectionInfo = (await Promise.all(connections.map(getConnectionInfo))).filter((connectionInfo): connectionInfo is ConnectionInfo => connectionInfo !== null)
|
|
|
|
|
|
|
|
|
|
return Response.json({ connections: connectionInfo })
|
2024-02-18 00:01:54 -05:00
|
|
|
}
|