feat: complete split camera credentials (#50)

This commit is contained in:
ila
2026-08-13 12:23:49 +08:00
parent 4042011345
commit da5318f8f0
+19 -3
View File
@@ -78,15 +78,30 @@ func (m *Module) update(w http.ResponseWriter, r *http.Request) {
}
func (m *Module) credential(w http.ResponseWriter, r *http.Request) {
var req struct {
Username string `json:"username"`
Password string `json:"password"`
Username string `json:"username"`
Password string `json:"password"`
ONVIFUsername string `json:"onvif_username"`
ONVIFPassword string `json:"onvif_password"`
RTSPSameAsONVIF *bool `json:"rtsp_same_as_onvif"`
RTSPUsername string `json:"rtsp_username"`
RTSPPassword string `json:"rtsp_password"`
}
if err := platform.DecodeJSON(r, &req); err != nil {
platform.WriteError(w, err)
return
}
actor, _ := identity.PrincipalFromContext(r.Context())
item, err := m.service.SetCredential(r.Context(), actor, r.PathValue("id"), req.Username, req.Password)
if req.ONVIFUsername == "" {
req.ONVIFUsername = req.Username
}
if req.ONVIFPassword == "" {
req.ONVIFPassword = req.Password
}
rtspSame := true
if req.RTSPSameAsONVIF != nil {
rtspSame = *req.RTSPSameAsONVIF
}
item, err := m.service.SetCredentials(r.Context(), actor, r.PathValue("id"), req.ONVIFUsername, req.ONVIFPassword, rtspSame, req.RTSPUsername, req.RTSPPassword)
if err != nil {
writeDeviceError(w, err)
return
@@ -122,3 +137,4 @@ func writeDeviceError(w http.ResponseWriter, err error) {
}
platform.WriteError(w, &platform.APIError{Status: status, Code: code, Message: err.Error()})
}