@@ -81,28 +81,22 @@ async def create_event(
8181 return success_response (EventItem .model_validate (event ).model_dump ())
8282
8383
84- @router .patch ("/events/by-ai-id/{ai_event_id}/video " , status_code = 200 )
85- async def attach_event_video (
84+ @router .post ("/events/broadcast " , status_code = 200 )
85+ async def broadcast_only (
8686 request : Request ,
87- ai_event_id : str ,
88- video : UploadFile | None = File (None ),
89- db : Session = Depends (get_db ),
87+ camera_id : str = Form (...),
88+ anomaly_type : str = Form ("fight" ),
89+ confidence : float = Form (...),
90+ detected_at : str = Form (...),
9091):
9192 _check_callback_secret (request )
92- form = await request .form ()
93- video_bytes = await video .read () if video else None
94- thumbnail_bytes_list = []
95- thumb_index = 1
96- while True :
97- thumb_upload = form .get (f"thumb_{ thumb_index } " )
98- if not isinstance (thumb_upload , (UploadFile , StarletteUploadFile )):
99- break
100- thumbnail_bytes_list .append (await thumb_upload .read ())
101- thumb_index += 1
102- event = EventService .attach_video (db , ai_event_id , video_bytes , thumbnail_bytes_list )
103- if not event :
104- raise AppException (status_code = 404 , code = "NOT_FOUND" , message = "이벤트를 찾을 수 없습니다." )
105- return success_response (EventItem .model_validate (event ).model_dump ())
93+ await broadcast_event (camera_id , {
94+ "camera_id" : camera_id ,
95+ "anomaly_type" : anomaly_type ,
96+ "confidence" : confidence ,
97+ "detected_at" : detected_at ,
98+ })
99+ return success_response ({"broadcast" : True })
106100
107101
108102@router .post ("/event-payloads" , status_code = 201 )
0 commit comments