MCPcopy Create free account
hub / github.com/NoFxAiOS/nofx / handleUpdateModelConfigs

Method handleUpdateModelConfigs

api/handler_ai_model.go:136–236  ·  view source on GitHub ↗

handleUpdateModelConfigs Update AI model configurations (supports both encrypted and plain text based on config)

(c *gin.Context)

Source from the content-addressed store, hash-verified

134
135// handleUpdateModelConfigs Update AI model configurations (supports both encrypted and plain text based on config)
136func (s *Server) handleUpdateModelConfigs(c *gin.Context) {
137 userID := c.GetString("user_id")
138 cfg := config.Get()
139
140 // Read raw request body
141 bodyBytes, err := c.GetRawData()
142 if err != nil {
143 c.JSON(http.StatusBadRequest, gin.H{"error": "Failed to read request body"})
144 return
145 }
146
147 var req UpdateModelConfigRequest
148
149 // Check if transport encryption is enabled
150 if !cfg.TransportEncryption {
151 // Transport encryption disabled, accept plain JSON
152 if err := json.Unmarshal(bodyBytes, &req); err != nil {
153 logger.Infof("❌ Failed to parse plain JSON request: %v", err)
154 c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request format"})
155 return
156 }
157 logger.Infof("📝 Received plain text model config (UserID: %s)", userID)
158 } else {
159 // Transport encryption enabled, require encrypted payload
160 var encryptedPayload crypto.EncryptedPayload
161 if err := json.Unmarshal(bodyBytes, &encryptedPayload); err != nil {
162 logger.Infof("❌ Failed to parse encrypted payload: %v", err)
163 c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request format, encrypted transmission required"})
164 return
165 }
166
167 // Verify encrypted data
168 if encryptedPayload.WrappedKey == "" {
169 logger.Infof("❌ Detected unencrypted request (UserID: %s)", userID)
170 c.JSON(http.StatusBadRequest, gin.H{
171 "error": "This endpoint only supports encrypted transmission, please use encrypted client",
172 "code": "ENCRYPTION_REQUIRED",
173 "message": "Encrypted transmission is required for security reasons",
174 })
175 return
176 }
177
178 // Decrypt data
179 decrypted, err := s.cryptoHandler.cryptoService.DecryptSensitiveData(&encryptedPayload)
180 if err != nil {
181 logger.Infof("❌ Failed to decrypt model config (UserID: %s): %v", userID, err)
182 c.JSON(http.StatusBadRequest, gin.H{"error": "Failed to decrypt data"})
183 return
184 }
185
186 // Parse decrypted data
187 if err := json.Unmarshal([]byte(decrypted), &req); err != nil {
188 logger.Infof("❌ Failed to parse decrypted data: %v", err)
189 c.JSON(http.StatusBadRequest, gin.H{"error": "Failed to parse decrypted data"})
190 return
191 }
192 logger.Infof("🔓 Decrypted model config data (UserID: %s)", userID)
193 }

Callers

nothing calls this directly

Calls 13

GetFunction · 0.92
InfofFunction · 0.92
ValidateURLFunction · 0.92
WarnfFunction · 0.92
SafeInternalErrorFunction · 0.85
DecryptSensitiveDataMethod · 0.80
ListByAIModelIDMethod · 0.80
TraderMethod · 0.80
AIModelMethod · 0.80
RemoveTraderMethod · 0.80

Tested by

no test coverage detected