[SEN] 分离ONVIF/RTSP凭据并持久化Profile (#50) #52

Open
ila wants to merge 21 commits from agent/codex/50-sense-split-camera-credentials into agent/codex/48-sense-onvif-digest
Showing only changes of commit da5318f8f0 - Show all commits
+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()})
}