MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / AddChannel

Function AddChannel

controller/channel.go:431–521  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

429}
430
431func AddChannel(c *gin.Context) {
432 addChannelRequest := AddChannelRequest{}
433 err := c.ShouldBindJSON(&addChannelRequest)
434 if err != nil {
435 common.ApiError(c, err)
436 return
437 }
438
439 // 使用统一的校验函数
440 if err := validateChannel(addChannelRequest.Channel, true); err != nil {
441 c.JSON(http.StatusOK, gin.H{
442 "success": false,
443 "message": err.Error(),
444 })
445 return
446 }
447
448 addChannelRequest.Channel.CreatedTime = common.GetTimestamp()
449 keys := make([]string, 0)
450 switch addChannelRequest.Mode {
451 case "multi_to_single":
452 addChannelRequest.Channel.ChannelInfo.IsMultiKey = true
453 addChannelRequest.Channel.ChannelInfo.MultiKeyMode = addChannelRequest.MultiKeyMode
454 if addChannelRequest.Channel.Type == constant.ChannelTypeVertexAi {
455 array, err := getVertexArrayKeys(addChannelRequest.Channel.Key)
456 if err != nil {
457 c.JSON(http.StatusOK, gin.H{
458 "success": false,
459 "message": err.Error(),
460 })
461 return
462 }
463 addChannelRequest.Channel.ChannelInfo.MultiKeySize = len(array)
464 addChannelRequest.Channel.Key = strings.Join(array, "\n")
465 } else {
466 cleanKeys := make([]string, 0)
467 for _, key := range strings.Split(addChannelRequest.Channel.Key, "\n") {
468 if key == "" {
469 continue
470 }
471 key = strings.TrimSpace(key)
472 cleanKeys = append(cleanKeys, key)
473 }
474 addChannelRequest.Channel.ChannelInfo.MultiKeySize = len(cleanKeys)
475 addChannelRequest.Channel.Key = strings.Join(cleanKeys, "\n")
476 }
477 keys = []string{addChannelRequest.Channel.Key}
478 case "batch":
479 if addChannelRequest.Channel.Type == constant.ChannelTypeVertexAi {
480 // multi json
481 keys, err = getVertexArrayKeys(addChannelRequest.Channel.Key)
482 if err != nil {
483 c.JSON(http.StatusOK, gin.H{
484 "success": false,
485 "message": err.Error(),
486 })
487 return
488 }

Callers

nothing calls this directly

Calls 6

ApiErrorFunction · 0.92
GetTimestampFunction · 0.92
BatchInsertChannelsFunction · 0.92
validateChannelFunction · 0.85
getVertexArrayKeysFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected