fix: 判断 conn 是否存在,防止 NOP

This commit is contained in:
2024-08-22 13:44:00 +08:00
parent 9a595fa997
commit 93bc5e80c4
2 changed files with 19 additions and 6 deletions

View File

@ -14,7 +14,16 @@ func CreateEventSubscription(c *gin.Context) {
xaddr := c.Param("xaddr")
callbackURL := event.AttributedURIType(fmt.Sprintf("%s/onvif/subscriptions/%s/callback", config.Conf.App.URL, xaddr))
log.Printf("CreateEventSubscription callback URL: %s", callbackURL)
result, err := conns[xaddr].SubscribeEvents(callbackURL, "PT60S")
conn := conns[xaddr]
if conn == nil {
c.JSON(http.StatusNotFound, gin.H{
"message": "Connection not found",
})
return
}
result, err := conn.SubscribeEvents(callbackURL, "PT60S")
if err != nil {
c.JSON(http.StatusServiceUnavailable, gin.H{
"message": err.Error(),