👔 Prevent user from setting published at before it real published date

This commit is contained in:
LittleSheep 2024-12-10 22:27:35 +08:00
parent 851c8e2f70
commit c125565896

View File

@ -358,6 +358,9 @@ func NewPost(user models.Publisher, item models.Post) (models.Post, error) {
if item.Alias != nil && len(*item.Alias) == 0 {
item.Alias = nil
}
if item.PublishedAt != nil && item.PublishedAt.Unix() < time.Now().Unix() {
return item, fmt.Errorf("post cannot be published before now")
}
if item.Alias != nil {
re := regexp.MustCompile(`^[a-z0-9.-]+$`)
@ -439,6 +442,9 @@ func EditPost(item models.Post) (models.Post, error) {
if item.Alias != nil && len(*item.Alias) == 0 {
item.Alias = nil
}
if item.PublishedAt != nil && item.PublishedAt.Unix() < item.CreatedAt.Unix() {
return item, fmt.Errorf("post cannot be published before it is created")
}
if item.Alias != nil {
re := regexp.MustCompile(`^[a-z0-9.-]+$`)