- 作者显示 用户名(UID): 修正Post.AuthorName GORM标签从 -:all 改为 -:migration;<-:false;column:author_name
- 审核流程: 帖子详情页新增"提交审核"按钮(draft/rejected时作者可见)
- 图片上传: 新增 POST /api/posts/upload-image 端点,限制5MB/jpg/png/gif/webp
- 代码块语言标注: 工具栏插入代码块时弹出语言输入框,生成 language-xxx class
- 状态中文显示: 管理后台/帖子详情页状态改为 PostStatusDisplayNames 映射
- 修复代码块插入位置错误: init时调用switchMode同步DOM; 无选区时appendChild; 防<pre>嵌套
- 修复 bluemonday.UGCPolicy() 剥离 code/pre 的 class 属性,显式 AllowAttrs("class")
- 修复分割线工具栏插入多余text占位符: hr/link/image以外不强制填占位文本
79 lines
2.5 KiB
Go
79 lines
2.5 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Post 帖子/文章模型
|
|
type Post struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Title string `gorm:"type:varchar(200);not null" json:"title"`
|
|
Body string `gorm:"type:text" json:"body"`
|
|
BodyHTML string `gorm:"type:text" json:"body_html"`
|
|
UserID uint `gorm:"index;not null" json:"user_id"`
|
|
Status string `gorm:"type:varchar(20);index;default:draft;not null" json:"status"`
|
|
RejectReason string `gorm:"type:varchar(500);default:''" json:"reject_reason,omitempty"`
|
|
AllowComment bool `gorm:"default:true" json:"allow_comment"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
// 非数据库字段(联表查询填充)
|
|
// gorm:"-:migration" 指定不创建/迁移该列,"<-:false" 禁止写入,"column:author_name" 允许
|
|
// 从 JOIN 查询的 users.username AS author_name 别名中读取
|
|
AuthorName string `gorm:"-:migration;<-:false;column:author_name" json:"author_name,omitempty"`
|
|
}
|
|
|
|
// 帖子状态常量
|
|
const (
|
|
PostStatusDraft = "draft"
|
|
PostStatusPending = "pending"
|
|
PostStatusApproved = "approved"
|
|
PostStatusRejected = "rejected"
|
|
PostStatusLocked = "locked"
|
|
)
|
|
|
|
// PostStatusDisplayNames 状态 → 中文名
|
|
var PostStatusDisplayNames = map[string]string{
|
|
PostStatusDraft: "草稿",
|
|
PostStatusPending: "待审核",
|
|
PostStatusApproved: "已发布",
|
|
PostStatusRejected: "已退回",
|
|
PostStatusLocked: "已锁定",
|
|
}
|
|
|
|
// PostListResult 帖子列表查询结果
|
|
type PostListResult struct {
|
|
Items []Post `json:"items"`
|
|
Total int64 `json:"total"`
|
|
Page int `json:"page"`
|
|
TotalPages int `json:"total_pages"`
|
|
}
|
|
|
|
// PostCreateRequest 发帖请求
|
|
type PostCreateRequest struct {
|
|
Title string `json:"title" binding:"required,min=1,max=200"`
|
|
Body string `json:"body" binding:"required,min=1"`
|
|
}
|
|
|
|
// PostUpdateRequest 编辑请求
|
|
type PostUpdateRequest struct {
|
|
Title string `json:"title" binding:"required,min=1,max=200"`
|
|
Body string `json:"body" binding:"required,min=1"`
|
|
}
|
|
|
|
// PostRejectRequest 退回请求
|
|
type PostRejectRequest struct {
|
|
Reason string `json:"reason" binding:"required,min=1,max=500"`
|
|
}
|
|
|
|
// PostListQuery 列表查询参数
|
|
type PostListQuery struct {
|
|
Keyword string `form:"keyword"`
|
|
Status string `form:"status"`
|
|
Page int `form:"page"`
|
|
PageSize int `form:"page_size"`
|
|
}
|