You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.go 2.4 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package cloudbrain
  2. import (
  3. "regexp"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/modules/setting"
  10. )
  11. func GetAiCenterShow(aiCenter string, ctx *context.Context) string {
  12. aiCenterInfo := strings.Split(aiCenter, "+")
  13. if len(aiCenterInfo) == 2 {
  14. if setting.C2NetMapInfo != nil {
  15. if info, ok := setting.C2NetMapInfo[aiCenterInfo[0]]; ok {
  16. if ctx.Language() == "zh-CN" {
  17. return info.Content
  18. } else {
  19. return info.ContentEN
  20. }
  21. } else {
  22. return aiCenterInfo[1]
  23. }
  24. } else {
  25. return aiCenterInfo[1]
  26. }
  27. }
  28. return ""
  29. }
  30. func GetDisplayJobName(username string) string {
  31. t := time.Now()
  32. return jobNamePrefixValid(cutString(username, 5)) + t.Format("2006010215") + strconv.Itoa(int(t.Unix()))[5:]
  33. }
  34. func cutString(str string, lens int) string {
  35. if len(str) < lens {
  36. return str
  37. }
  38. return str[:lens]
  39. }
  40. func jobNamePrefixValid(s string) string {
  41. lowStr := strings.ToLower(s)
  42. re := regexp.MustCompile(`[^a-z0-9_\\-]+`)
  43. removeSpecial := re.ReplaceAllString(lowStr, "")
  44. re = regexp.MustCompile(`^[_\\-]+`)
  45. return re.ReplaceAllString(removeSpecial, "")
  46. }
  47. func GetAiCenterInfoByCenterCode(aiCenterCode string) *setting.C2NetSequenceInfo {
  48. if setting.AiCenterCodeAndNameMapInfo != nil {
  49. if info, ok := setting.AiCenterCodeAndNameMapInfo[aiCenterCode]; ok {
  50. return info
  51. } else {
  52. return nil
  53. }
  54. } else {
  55. return nil
  56. }
  57. }
  58. func getAiCenterCode(aiCenter string) string {
  59. aiCenterInfo := strings.Split(aiCenter, "+")
  60. return aiCenterInfo[0]
  61. }
  62. func UpdateCloudbrainAiCenter(cloudbrain *models.CloudbrainInfo) *models.CloudbrainInfo {
  63. if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainOne {
  64. cloudbrain.Cloudbrain.AiCenter = models.AICenterOfCloudBrainOne
  65. cloudbrain.Cloudbrain.Cluster = models.OpenICluster
  66. }
  67. if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainTwo {
  68. cloudbrain.Cloudbrain.AiCenter = models.AICenterOfCloudBrainTwo
  69. cloudbrain.Cloudbrain.Cluster = models.OpenICluster
  70. }
  71. if cloudbrain.Cloudbrain.Type == models.TypeCDCenter {
  72. cloudbrain.Cloudbrain.AiCenter = models.AICenterOfChengdu
  73. cloudbrain.Cloudbrain.Cluster = models.OpenICluster
  74. }
  75. if cloudbrain.Cloudbrain.Type == models.TypeC2Net {
  76. cloudbrain.Cloudbrain.AiCenter = getAiCenterCode(cloudbrain.Cloudbrain.AiCenter)
  77. cloudbrain.Cloudbrain.Cluster = models.C2NetCluster
  78. }
  79. return cloudbrain
  80. }