From 62732ba348ecbf5744231e15caaa11d8f3b8efdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E9=97=BB=E9=A3=8E?= Date: Sun, 21 Jun 2026 19:42:47 +0800 Subject: [PATCH] up --- handlers/article.go | 19 ++++++++++++++++++- i18n/i18n.go | 2 ++ templates/admin/dashboard.html | 9 ++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/handlers/article.go b/handlers/article.go index 28b2d22..e38c056 100644 --- a/handlers/article.go +++ b/handlers/article.go @@ -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, diff --git a/i18n/i18n.go b/i18n/i18n.go index 0fd153b..d8e175f 100644 --- a/i18n/i18n.go +++ b/i18n/i18n.go @@ -54,6 +54,7 @@ var translations = map[Lang]map[string]string{ "dash_users": "Users", "dash_mgmt_title": "Blog Management", "dash_mgmt_desc": "Post management, categories, and settings will appear here in future updates.", + "dash_new_article": "New Article", "dash_page_title": "Dashboard", // Footer @@ -154,6 +155,7 @@ var translations = map[Lang]map[string]string{ "dash_users": "用户", "dash_mgmt_title": "博客管理", "dash_mgmt_desc": "文章管理、分类和设置将在后续版本中添加。", + "dash_new_article": "新建文章", "dash_page_title": "后台管理", // 页脚 diff --git a/templates/admin/dashboard.html b/templates/admin/dashboard.html index ae6bb18..f06fba4 100644 --- a/templates/admin/dashboard.html +++ b/templates/admin/dashboard.html @@ -35,7 +35,14 @@

{{index .Tr "dash_mgmt_title"}}

-

{{index .Tr "dash_mgmt_desc"}}

+

{{index .Tr "dash_mgmt_desc"}}

+ + + + + {{index .Tr "dash_new_article"}} +
{{template "footer" .}}