fix: 修复发帖后链接404 + 通知卡片跳转错误
- post_repo.go: FindByIDWithAuthor/Restore 中 posts.uid 改为 posts.id(posts 表主键是 id,不存在 uid 列) - theme/loader.go: 新增 derefUint 模板函数,显式解引用 *uint 指针(Go 1.26 模板引擎传参给 printf 时不自动解引用) - messages/index.html: 通知卡片链接使用 derefUint 包裹 RelatedID 避免打印指针地址
This commit is contained in:
@ -37,7 +37,7 @@ func (r *PostRepo) FindByIDWithAuthor(id uint) (*model.Post, error) {
|
||||
err := r.db.Table("posts").
|
||||
Select("posts.*, users.username as author_name").
|
||||
Joins("LEFT JOIN users ON users.uid = posts.user_id").
|
||||
Where("posts.uid = ?", id).
|
||||
Where("posts.id = ?", id).
|
||||
First(&post).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -157,7 +157,7 @@ func (r *PostRepo) CountPending() (int64, error) {
|
||||
|
||||
// Restore 恢复软删除
|
||||
func (r *PostRepo) Restore(id uint) error {
|
||||
result := r.db.Unscoped().Model(&model.Post{}).Where("uid = ?", id).Update("deleted_at", nil)
|
||||
result := r.db.Unscoped().Model(&model.Post{}).Where("id = ?", id).Update("deleted_at", nil)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
||||
@ -24,6 +24,15 @@ func LoadTemplates(roots ...TemplateRoot) (*template.Template, error) {
|
||||
"subtract": func(a, b int) int { return a - b },
|
||||
"formatTTL": formatTTL,
|
||||
"assetV": common.AssetV,
|
||||
// derefUint 安全解引用 *uint 指针。
|
||||
// Go 1.26 的模板引擎在将 *uint 传给 printf/print 时不会自动解引用,
|
||||
// 导致打印指针地址而非值。通过此函数显式解引用后传给 printf。
|
||||
"derefUint": func(p *uint) uint {
|
||||
if p == nil {
|
||||
return 0
|
||||
}
|
||||
return *p
|
||||
},
|
||||
}
|
||||
t := template.New("").Funcs(funcMap)
|
||||
for _, root := range roots {
|
||||
|
||||
Reference in New Issue
Block a user