🐛 Fix validator still validating alias when it is blank

This commit is contained in:
LittleSheep 2024-08-18 00:07:53 +08:00
parent d3371a7240
commit a9bfb5767c

View File

@ -271,6 +271,10 @@ func EnsurePostCategoriesAndTags(item models.Post) (models.Post, error) {
}
func NewPost(user models.Account, item models.Post) (models.Post, error) {
if item.Alias != nil && len(*item.Alias) == 0 {
item.Alias = nil
}
if item.Alias != nil {
re := regexp.MustCompile(`^[a-z0-9.-]+$`)
if !re.MatchString(*item.Alias) {
@ -333,6 +337,10 @@ func NewPost(user models.Account, item models.Post) (models.Post, error) {
}
func EditPost(item models.Post) (models.Post, error) {
if item.Alias != nil && len(*item.Alias) == 0 {
item.Alias = nil
}
if item.Alias != nil {
re := regexp.MustCompile(`^[a-z0-9.-]+$`)
if !re.MatchString(*item.Alias) {