Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

63 rindas
1.2 KiB

  1. package controller
  2. import (
  3. "net/http"
  4. "github.com/QuantumNous/new-api/model"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func GetModelChannels(c *gin.Context) {
  8. modelName := c.Query("model")
  9. if modelName == "" {
  10. c.JSON(http.StatusBadRequest, gin.H{
  11. "success": false,
  12. "message": "model parameter is required",
  13. })
  14. return
  15. }
  16. userId := c.GetInt("id")
  17. if userId == 0 {
  18. c.JSON(http.StatusUnauthorized, gin.H{
  19. "success": false,
  20. "message": "unauthorized",
  21. })
  22. return
  23. }
  24. userCache, err := model.GetUserCache(userId)
  25. if err != nil || userCache == nil {
  26. c.JSON(http.StatusInternalServerError, gin.H{
  27. "success": false,
  28. "message": "failed to get user info",
  29. })
  30. return
  31. }
  32. userGroup := userCache.Group
  33. if userGroup == "" {
  34. c.JSON(http.StatusInternalServerError, gin.H{
  35. "success": false,
  36. "message": "failed to get user group",
  37. })
  38. return
  39. }
  40. channels, defaultChannelId, err := model.GetModelChannelsForGroup(modelName, userGroup)
  41. if err != nil {
  42. c.JSON(http.StatusInternalServerError, gin.H{
  43. "success": false,
  44. "message": "failed to query channels",
  45. })
  46. return
  47. }
  48. c.JSON(http.StatusOK, gin.H{
  49. "success": true,
  50. "data": gin.H{
  51. "channels": channels,
  52. "default_channel_id": defaultChannelId,
  53. },
  54. })
  55. }