Agregar dropdown de eventos Frigate y corregir endpoint de creacion
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 59s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 59s
- Agregar toggle Live/Eventos en StreamViewer - Agregar dropdown para seleccionar eventos recientes (max 10) - Reproducir clips de eventos en el mismo reproductor - Crear endpoint proxy /api/frigate/events para listar eventos - Corregir URL de creacion de eventos: /api/events/:camera/:label/create - Actualizar useFrigateEvents con fetchEvents, formatEventTime, getEventClipUrl
This commit is contained in:
@@ -39,9 +39,7 @@ export default defineEventHandler(async (event) => {
|
||||
const cameraName = body.camera.replace(/_main$|_sub$/, '')
|
||||
|
||||
// Preparar payload para Frigate
|
||||
const frigatePayload: Record<string, unknown> = {
|
||||
label: body.label
|
||||
}
|
||||
const frigatePayload: Record<string, unknown> = {}
|
||||
|
||||
if (body.sub_label) {
|
||||
frigatePayload.sub_label = body.sub_label
|
||||
@@ -59,8 +57,9 @@ export default defineEventHandler(async (event) => {
|
||||
const FRIGATE_URL = process.env.FRIGATE_URL || 'http://192.168.87.29:5000'
|
||||
|
||||
try {
|
||||
// API: POST /api/events/:camera_name/:label/create
|
||||
const response = await fetch(
|
||||
`${FRIGATE_URL}/api/events/${cameraName}/create`,
|
||||
`${FRIGATE_URL}/api/events/${cameraName}/${body.label}/create`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
||||
68
nuxt4/server/api/frigate/events.get.ts
Normal file
68
nuxt4/server/api/frigate/events.get.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Proxy endpoint para obtener eventos de Frigate
|
||||
* GET /api/frigate/events?camera=X&limit=10
|
||||
*/
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
// Verificar autenticación via headers de Authentik
|
||||
const headers = getRequestHeaders(event)
|
||||
const username = headers['x-authentik-username']
|
||||
|
||||
if (!username) {
|
||||
throw createError({
|
||||
statusCode: 401,
|
||||
message: 'No autenticado'
|
||||
})
|
||||
}
|
||||
|
||||
// Leer query params
|
||||
const query = getQuery(event)
|
||||
const camera = query.camera as string | undefined
|
||||
const limit = query.limit ? parseInt(query.limit as string) : 10
|
||||
|
||||
// URL interna de Frigate
|
||||
const FRIGATE_URL = process.env.FRIGATE_URL || 'http://192.168.87.29:5000'
|
||||
|
||||
// Construir URL con filtros
|
||||
const params = new URLSearchParams()
|
||||
if (camera) {
|
||||
// Extraer nombre base de la cámara (sin _main o _sub)
|
||||
params.set('camera', camera.replace(/_main$|_sub$/, ''))
|
||||
}
|
||||
params.set('limit', limit.toString())
|
||||
params.set('has_clip', 'true') // Solo eventos con clip
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${FRIGATE_URL}/api/events?${params.toString()}`,
|
||||
{
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
throw createError({
|
||||
statusCode: response.status,
|
||||
message: `Error al obtener eventos: ${response.statusText}`
|
||||
})
|
||||
}
|
||||
|
||||
const events = await response.json()
|
||||
|
||||
return events
|
||||
} catch (error: unknown) {
|
||||
console.error('[Frigate Events] Error:', error)
|
||||
|
||||
if ((error as any).statusCode) {
|
||||
throw error
|
||||
}
|
||||
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: (error as Error)?.message || 'Error al obtener eventos'
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user