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 1.1 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package cloudbrain
  2. import (
  3. "regexp"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "code.gitea.io/gitea/modules/context"
  8. "code.gitea.io/gitea/modules/setting"
  9. )
  10. func GetAiCenterShow(aiCenter string, ctx *context.Context) string {
  11. aiCenterInfo := strings.Split(aiCenter, "+")
  12. if len(aiCenterInfo) == 2 {
  13. if setting.C2NetMapInfo != nil {
  14. if info, ok := setting.C2NetMapInfo[aiCenterInfo[0]]; ok {
  15. if ctx.Language() == "zh-CN" {
  16. return info.Content
  17. } else {
  18. return info.ContentEN
  19. }
  20. } else {
  21. return aiCenterInfo[1]
  22. }
  23. } else {
  24. return aiCenterInfo[1]
  25. }
  26. }
  27. return ""
  28. }
  29. func GetDisplayJobName(username string) string {
  30. t := time.Now()
  31. return jobNamePrefixValid(cutString(username, 5)) + t.Format("2006010215") + strconv.Itoa(int(t.Unix()))[5:]
  32. }
  33. func cutString(str string, lens int) string {
  34. if len(str) < lens {
  35. return str
  36. }
  37. return str[:lens]
  38. }
  39. func jobNamePrefixValid(s string) string {
  40. lowStr := strings.ToLower(s)
  41. re := regexp.MustCompile(`[^a-z0-9_\\-]+`)
  42. removeSpecial := re.ReplaceAllString(lowStr, "")
  43. re = regexp.MustCompile(`^[_\\-]+`)
  44. return re.ReplaceAllString(removeSpecial, "")
  45. }