🐛 Fix editing post got rejected

This commit is contained in:
LittleSheep 2024-12-22 23:44:51 +08:00
parent 8cd7dca8aa
commit 1a3e43a12f
3 changed files with 6 additions and 5 deletions

View File

@ -179,13 +179,15 @@ func editArticle(c *fiber.Ctx) error {
item.Categories = data.Categories item.Categories = data.Categories
item.IsDraft = data.IsDraft item.IsDraft = data.IsDraft
item.PublishedUntil = data.PublishedUntil item.PublishedUntil = data.PublishedUntil
item.PublishedAt = data.PublishedAt
item.VisibleUsers = data.VisibleUsers item.VisibleUsers = data.VisibleUsers
item.InvisibleUsers = data.InvisibleUsers item.InvisibleUsers = data.InvisibleUsers
// Preload publisher data // Preload publisher data
item.Publisher = publisher item.Publisher = publisher
if item.PublishedAt == nil {
item.PublishedAt = data.PublishedAt
}
if data.Visibility != nil { if data.Visibility != nil {
item.Visibility = *data.Visibility item.Visibility = *data.Visibility
} }

View File

@ -202,7 +202,6 @@ func editStory(c *fiber.Ctx) error {
item.Tags = data.Tags item.Tags = data.Tags
item.Categories = data.Categories item.Categories = data.Categories
item.IsDraft = data.IsDraft item.IsDraft = data.IsDraft
item.PublishedAt = data.PublishedAt
item.PublishedUntil = data.PublishedUntil item.PublishedUntil = data.PublishedUntil
item.VisibleUsers = data.VisibleUsers item.VisibleUsers = data.VisibleUsers
item.InvisibleUsers = data.InvisibleUsers item.InvisibleUsers = data.InvisibleUsers
@ -210,6 +209,9 @@ func editStory(c *fiber.Ctx) error {
// Preload publisher data // Preload publisher data
item.Publisher = publisher item.Publisher = publisher
if item.PublishedAt == nil {
item.PublishedAt = data.PublishedAt
}
if data.Visibility != nil { if data.Visibility != nil {
item.Visibility = *data.Visibility item.Visibility = *data.Visibility
} }

View File

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