Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

53 righe
1.3 KiB

  1. package controller
  2. import (
  3. "net/http"
  4. "github.com/QuantumNous/new-api/model"
  5. "github.com/QuantumNous/new-api/service"
  6. "github.com/QuantumNous/new-api/setting"
  7. "github.com/QuantumNous/new-api/setting/ratio_setting"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func GetGroups(c *gin.Context) {
  11. groupNames := make([]string, 0)
  12. for groupName := range ratio_setting.GetGroupRatioCopy() {
  13. groupNames = append(groupNames, groupName)
  14. }
  15. c.JSON(http.StatusOK, gin.H{
  16. "success": true,
  17. "message": "",
  18. "data": groupNames,
  19. })
  20. }
  21. func GetUserGroups(c *gin.Context) {
  22. usableGroups := make(map[string]map[string]interface{})
  23. userGroup := ""
  24. userId := c.GetInt("id")
  25. userGroup, _ = model.GetUserGroup(userId, false)
  26. userUsableGroups := service.GetUserUsableGroups(userGroup)
  27. for groupName, _ := range ratio_setting.GetGroupRatioCopy() {
  28. // UserUsableGroups contains the groups that the user can use
  29. if desc, ok := userUsableGroups[groupName]; ok {
  30. usableGroups[groupName] = map[string]interface{}{
  31. "ratio": service.GetUserGroupRatio(userGroup, groupName),
  32. "desc": desc,
  33. }
  34. }
  35. }
  36. if _, ok := userUsableGroups["auto"]; ok {
  37. usableGroups["auto"] = map[string]interface{}{
  38. "ratio": "自动",
  39. "desc": setting.GetUsableGroupDescription("auto"),
  40. }
  41. }
  42. c.JSON(http.StatusOK, gin.H{
  43. "success": true,
  44. "message": "",
  45. "data": usableGroups,
  46. })
  47. }