2024-01-30 12:27:37 -05:00
|
|
|
import type { RequestHandler } from '@sveltejs/kit'
|
2024-04-05 02:00:17 -04:00
|
|
|
import { Connections } from '$lib/server/connections'
|
2024-01-30 12:27:37 -05:00
|
|
|
|
|
|
|
|
export const GET: RequestHandler = async ({ params }) => {
|
2024-02-18 00:01:54 -05:00
|
|
|
const userId = params.userId!
|
2024-01-30 12:27:37 -05:00
|
|
|
|
2024-05-28 00:46:34 -04:00
|
|
|
const userConnections = Connections.getUserConnections(userId)
|
|
|
|
|
if (!userConnections) return new Response('Invalid user id', { status: 400 })
|
|
|
|
|
|
|
|
|
|
const connections = (
|
|
|
|
|
await Promise.all(
|
|
|
|
|
userConnections.map((connection) =>
|
|
|
|
|
connection.getConnectionInfo().catch((reason) => {
|
|
|
|
|
console.log(`Failed to fetch connection info: ${reason}`)
|
|
|
|
|
return undefined
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
).filter((info): info is ConnectionInfo => info !== undefined)
|
2024-02-23 00:53:54 -05:00
|
|
|
|
2024-02-18 00:01:54 -05:00
|
|
|
return Response.json({ connections })
|
2024-01-30 12:27:37 -05:00
|
|
|
}
|