Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 6m46s
Reemplazo completo de Evolution API por implementación directa con Baileys. Características: - Dashboard completo con Nuxt UI v4 - Soporte para múltiples instancias de WhatsApp - Conexión via QR code o pairing code - Persistencia de mensajes en PostgreSQL - API REST para integraciones externas - Webhooks con firma HMAC - SSE para actualizaciones en tiempo real - Autenticación con Authentik
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
/**
|
|
* GET /api/instances
|
|
* List all instances
|
|
*/
|
|
import { query } from '../../utils/database'
|
|
import { baileysManager } from '../../services/baileys/manager'
|
|
|
|
interface InstanceRow {
|
|
id: string
|
|
name: string
|
|
phone_number: string | null
|
|
status: string
|
|
last_connected_at: Date | null
|
|
created_at: Date
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
// Check auth
|
|
const username = getHeader(event, 'x-authentik-username')
|
|
if (!username) {
|
|
throw createError({ statusCode: 401, message: 'Unauthorized' })
|
|
}
|
|
|
|
const result = await query<InstanceRow>(
|
|
`SELECT id, name, phone_number, status, last_connected_at, created_at
|
|
FROM instances
|
|
ORDER BY created_at DESC`
|
|
)
|
|
|
|
// Enrich with live status from manager
|
|
return result.rows.map(row => {
|
|
const liveStatus = baileysManager.getStatus(row.id)
|
|
return {
|
|
id: row.id,
|
|
name: row.name,
|
|
phoneNumber: row.phone_number,
|
|
status: liveStatus?.status || row.status,
|
|
lastConnectedAt: row.last_connected_at,
|
|
createdAt: row.created_at
|
|
}
|
|
})
|
|
})
|