部署脚本
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@ attack:
|
||||
windowDurationSeconds: 60
|
||||
pprof: false
|
||||
host: "172.104.166.87"
|
||||
listenAddr: "20001"
|
||||
listenAddr: "20101"
|
||||
origDomain: "https://yuan.bbaazz.me/"
|
||||
trustedProxies: ""
|
||||
bucketVideoAddressV2: "http://139.162.27.29:19996"
|
||||
|
||||
@@ -126,6 +126,37 @@ func MakeRandomSlug(exists func(string) bool) string {
|
||||
}
|
||||
}
|
||||
|
||||
// GetSlugAbbr 取标题的拼音首字母缩写(中文每字取首字母,英文每词取首字母),全小写。
|
||||
func GetSlugAbbr(text string) string {
|
||||
s := strings.ToLower(slug.Make(text))
|
||||
var b strings.Builder
|
||||
newWord := true
|
||||
for _, r := range s {
|
||||
if r == '-' || r == '_' {
|
||||
newWord = true
|
||||
continue
|
||||
}
|
||||
if newWord && ((r >= 'a' && r <= 'z') || (r >= '0' && r <= '9')) {
|
||||
b.WriteRune(r)
|
||||
newWord = false
|
||||
}
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// MakeAbbrSlug 优先按标题拼音首字母缩写生成 slug;缩写为空或全数字时回退 5 位随机字母,碰撞时追加 3 位随机字母。
|
||||
func MakeAbbrSlug(source string, exists func(string) bool) string {
|
||||
abbr := GetSlugAbbr(source)
|
||||
if abbr == "" || IsSlugAllDigits(abbr) {
|
||||
abbr = strings.ToLower(GetRandomLetters(5))
|
||||
}
|
||||
final := abbr
|
||||
for exists(final) {
|
||||
final = abbr + strings.ToLower(GetRandomLetters(3))
|
||||
}
|
||||
return final
|
||||
}
|
||||
|
||||
// MakeUniqueSlug 生成唯一 slug;exists 返回 true 表示已被占用。生成结果不能全是数字。
|
||||
func MakeUniqueSlug(source string, exists func(string) bool) string {
|
||||
pinyin := GetSlugInfo(source)
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ attack:
|
||||
windowDurationSeconds: 60
|
||||
pprof: false
|
||||
host: "172.104.166.87"
|
||||
listenAddr: "20002"
|
||||
listenAddr: "20102"
|
||||
origDomain: "https://yuan.bbaazz.me/"
|
||||
trustedProxies: ""
|
||||
bucketVideoAddressV2: "http://139.162.27.29:19996"
|
||||
|
||||
@@ -1276,7 +1276,7 @@ func ensureImportedPlayletSlug(ctx context.Context, playlet *playletmod.Playlet)
|
||||
if playlet == nil {
|
||||
return srvdef.New(srvdef.ErrParamError, "短剧数据为空", "")
|
||||
}
|
||||
playlet.Slug = utils.MakeRandomSlug(func(slug string) bool {
|
||||
playlet.Slug = utils.MakeAbbrSlug(playlet.Title, func(slug string) bool {
|
||||
exist, _ := playletmod.FindOnePlaylet(ctx, bson.M{
|
||||
playletmod.FN.Playlet.Slug: slug,
|
||||
})
|
||||
|
||||
@@ -176,7 +176,7 @@ func ensurePlayletSlug(ctx context.Context, ac *playletmod.Playlet, excludeId in
|
||||
}
|
||||
return nil
|
||||
}
|
||||
ac.Slug = utils.MakeRandomSlug(func(slug string) bool {
|
||||
ac.Slug = utils.MakeAbbrSlug(ac.Title, func(slug string) bool {
|
||||
filter := bson.M{playletmod.FN.Playlet.Slug: slug}
|
||||
if excludeId > 0 {
|
||||
filter[playletmod.FN.Playlet.Id] = bson.M{"$ne": excludeId}
|
||||
@@ -208,7 +208,11 @@ func preparePlayletSlugOnUpdate(ctx context.Context, id int64, info *playletmod.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
newSlug := utils.MakeRandomSlug(func(s string) bool {
|
||||
title := info.Title
|
||||
if req.Title != nil {
|
||||
title = strings.TrimSpace(*req.Title)
|
||||
}
|
||||
newSlug := utils.MakeAbbrSlug(title, func(s string) bool {
|
||||
exist, _ := playletmod.FindOnePlaylet(ctx, bson.M{
|
||||
playletmod.FN.Playlet.Slug: s,
|
||||
playletmod.FN.Playlet.Id: bson.M{"$ne": id},
|
||||
|
||||
Reference in New Issue
Block a user