This commit is contained in:
2026-06-21 19:42:47 +08:00
parent a84982e1f5
commit 62732ba348
3 changed files with 28 additions and 2 deletions
+18 -1
View File
@@ -97,6 +97,23 @@ func ArticleCreate(db *gorm.DB) gin.HandlerFunc {
return
}
// The session stores user.ID, which is a gorm uint — but be defensive
// across int / uint / int64 storage so a type mismatch never panics.
var authorID uint
switch v := userID.(type) {
case uint:
authorID = v
case int:
authorID = uint(v)
case int64:
authorID = uint(v)
case float64:
authorID = uint(v)
default:
c.Redirect(http.StatusFound, "/login")
return
}
var publishedAt *time.Time
if status == models.ArticlePublished {
now := time.Now()
@@ -104,7 +121,7 @@ func ArticleCreate(db *gorm.DB) gin.HandlerFunc {
}
article := models.Article{
AuthorID: uint(userID.(int)),
AuthorID: authorID,
Title: title,
Slug: slug,
Summary: summary,