All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m5s
- /api/streams/list: proxy a streams.nucleoriofrio.com/api/streams - /api/frigate/event: proxy a camaras.nucleoriofrio.com/api/events - Actualizar composables para usar los proxies del backend - Los iframes de streaming siguen usando URLs directas (sesion propia)
94 lines
2.2 KiB
TypeScript
94 lines
2.2 KiB
TypeScript
/**
|
|
* Composable para gestionar eventos de Frigate
|
|
* Usa proxy backend para evitar problemas de CORS/cookies entre subdominios
|
|
* API Proxy: /api/frigate/event
|
|
*/
|
|
|
|
export interface FrigateEventParams {
|
|
label: string
|
|
sub_label?: string
|
|
duration?: number
|
|
include_recording?: boolean
|
|
draw?: {
|
|
boxes?: Array<{
|
|
box: [number, number, number, number]
|
|
color?: [number, number, number]
|
|
score?: number
|
|
}>
|
|
}
|
|
}
|
|
|
|
export interface FrigateEventResponse {
|
|
success: boolean
|
|
event_id?: string
|
|
message?: string
|
|
}
|
|
|
|
export const useFrigateEvents = () => {
|
|
const isCreating = useState<boolean>('frigate_creating', () => false)
|
|
const error = useState<string | null>('frigate_error', () => null)
|
|
const lastEventId = useState<string | null>('frigate_last_event', () => null)
|
|
|
|
/**
|
|
* Crea un evento en Frigate para una camara especifica via proxy
|
|
*/
|
|
const createEvent = async (
|
|
camera: string,
|
|
params: FrigateEventParams
|
|
): Promise<FrigateEventResponse> => {
|
|
isCreating.value = true
|
|
error.value = null
|
|
|
|
try {
|
|
// Usar proxy backend para evitar CORS/cookies issues
|
|
const response = await $fetch<FrigateEventResponse>('/api/frigate/event', {
|
|
method: 'POST',
|
|
body: {
|
|
camera,
|
|
...params
|
|
}
|
|
})
|
|
|
|
if (response.event_id) {
|
|
lastEventId.value = response.event_id
|
|
}
|
|
|
|
return { success: true, ...response }
|
|
} catch (err: unknown) {
|
|
const errorMessage = (err as Error)?.message || 'Error al crear evento'
|
|
error.value = errorMessage
|
|
console.error('[Frigate] Error creating event:', err)
|
|
return { success: false, message: errorMessage }
|
|
} finally {
|
|
isCreating.value = false
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Crea un evento rapido "eventoWhisper" de 1 minuto
|
|
*/
|
|
const createQuickEvent = async (camera: string): Promise<FrigateEventResponse> => {
|
|
return createEvent(camera, {
|
|
label: 'eventoWhisper',
|
|
duration: 60,
|
|
include_recording: true
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Limpia el error
|
|
*/
|
|
const clearError = () => {
|
|
error.value = null
|
|
}
|
|
|
|
return {
|
|
isCreating: readonly(isCreating),
|
|
error: readonly(error),
|
|
lastEventId: readonly(lastEventId),
|
|
createEvent,
|
|
createQuickEvent,
|
|
clearError
|
|
}
|
|
}
|