|
- package cloudbrain
-
- import (
- "regexp"
- "strconv"
- "strings"
- "time"
-
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/setting"
- )
-
- func GetAiCenterShow(aiCenter string, ctx *context.Context) string {
- aiCenterInfo := strings.Split(aiCenter, "+")
-
- if len(aiCenterInfo) == 2 {
- if setting.C2NetMapInfo != nil {
- if info, ok := setting.C2NetMapInfo[aiCenterInfo[0]]; ok {
- if ctx.Language() == "zh-CN" {
- return info.Content
- } else {
- return info.ContentEN
- }
- } else {
- return aiCenterInfo[1]
- }
-
- } else {
- return aiCenterInfo[1]
- }
-
- }
-
- return ""
-
- }
- func GetDisplayJobName(username string) string {
- t := time.Now()
- return jobNamePrefixValid(cutString(username, 5)) + t.Format("2006010215") + strconv.Itoa(int(t.Unix()))[5:]
- }
-
- func cutString(str string, lens int) string {
- if len(str) < lens {
- return str
- }
- return str[:lens]
- }
-
- func jobNamePrefixValid(s string) string {
- lowStr := strings.ToLower(s)
- re := regexp.MustCompile(`[^a-z0-9_\\-]+`)
-
- removeSpecial := re.ReplaceAllString(lowStr, "")
-
- re = regexp.MustCompile(`^[_\\-]+`)
- return re.ReplaceAllString(removeSpecial, "")
-
- }
|