- 编辑器:Tiptap 替换为 Vditor 3.11.2(wysiwyg 模式,本地托管 5.8MB,去 CDN) - 存储:Body 字段从 HTML 改为 Markdown,去除 BodyHTML,新增 Excerpt 列表摘要 - 安全:去除 bluemonday 依赖(MD 纯文本无 XSS 风险),go.mod 已清理 - Shortcode:新增 [zone:type:params] 扩展语法,支持活动/游戏/投票/资源卡片 - 图片上传:POST /api/posts/upload-image 直接返回 Vditor 原生响应格式 - 草稿:localStorage 键名改为 draft_post_body_md,与旧 HTML 草稿隔离 - 详情页:Vditor.method.min.js 客户端 MD → HTML 渲染,去 highlight.js CDN - 样式:去 Tiptap 样式 ~190 行,精简工具栏 CSS,新增卡片样式 - 文档:vditor-migration-plan.md 完整记录迁移决策、架构、用法
79 lines
2.6 KiB
Go
79 lines
2.6 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"` // Markdown content
|
|
Excerpt string `gorm:"type:varchar(500)" json:"excerpt"` // plain text summary for list
|
|
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"`
|
|
}
|