feat: 代码片段功能与 Markdown 内嵌片段渲染、文档截图等
This commit is contained in:
@@ -64,6 +64,7 @@ func InitDB(dsn string) error {
|
||||
&Badge{}, &UserBadge{},
|
||||
&PostPollVote{}, &PostLotteryEntry{}, &Ad{}, &SidebarWidget{}, &FriendLink{},
|
||||
&ImportRecord{}, &LibraryDoc{}, &LibraryFile{}, &LibrarySection{},
|
||||
&CodeSnippet{}, &SnippetVersion{}, &SnippetComment{}, &SnippetCommentEditHistory{},
|
||||
); err != nil {
|
||||
return fmt.Errorf("自动迁移失败: %w", err)
|
||||
}
|
||||
|
||||
@@ -576,6 +576,75 @@ type LibrarySection struct {
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// CodeSnippet 代码片段:用户所有,公开进广场,私有仅自己可见
|
||||
type CodeSnippet struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Title string `gorm:"size:120;not null" json:"title"`
|
||||
Description string `gorm:"type:text" json:"description"`
|
||||
Language string `gorm:"size:32;not null;index" json:"language"`
|
||||
Code string `gorm:"type:text;not null" json:"code"`
|
||||
Visibility string `gorm:"size:16;not null;default:private;index" json:"visibility"` // public/private
|
||||
UserID uint `gorm:"index;not null" json:"user_id"`
|
||||
ForkedFromID *uint `gorm:"index" json:"forked_from_id"`
|
||||
CopyCount int `gorm:"not null;default:0" json:"copy_count"`
|
||||
ViewCount int `gorm:"not null;default:0" json:"view_count"`
|
||||
CommentCount int `gorm:"not null;default:0" json:"comment_count"`
|
||||
ForkCount int `gorm:"not null;default:0" json:"fork_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// SnippetVersion 编辑前旧值快照(同 PostEditHistory 思路)
|
||||
type SnippetVersion struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
SnippetID uint `gorm:"index;not null" json:"snippet_id"`
|
||||
EditorID uint `gorm:"index;not null" json:"editor_id"`
|
||||
OldTitle string `gorm:"size:120;not null;default:''" json:"old_title"`
|
||||
OldLanguage string `gorm:"size:32;not null;default:''" json:"old_language"`
|
||||
OldDescription string `gorm:"type:text" json:"old_description"`
|
||||
OldCode string `gorm:"type:text;not null" json:"old_code"`
|
||||
CreatedAt time.Time `gorm:"index" json:"created_at"`
|
||||
}
|
||||
|
||||
// SnippetComment 片段评论(楼层树:ParentID 空=主评,非空=回复;RootID=所属主楼)
|
||||
type SnippetComment struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
SnippetID uint `gorm:"index;not null" json:"snippet_id"`
|
||||
UserID uint `gorm:"index;not null" json:"user_id,omitempty"`
|
||||
ParentID *uint `gorm:"index" json:"parent_id"`
|
||||
RootID *uint `gorm:"index" json:"root_id"`
|
||||
Depth int `gorm:"not null;default:0" json:"depth"`
|
||||
Content string `gorm:"type:text;not null" json:"content"`
|
||||
DeleteType string `gorm:"size:32;default:''" json:"delete_type,omitempty"`
|
||||
DeletedBy uint `gorm:"not null;default:0" json:"deleted_by,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
}
|
||||
|
||||
// SnippetCommentEditHistory 片段评论修订快照(每次编辑前的旧正文;登录用户可见)
|
||||
type SnippetCommentEditHistory struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
CommentID uint `gorm:"index;not null" json:"comment_id"`
|
||||
EditorID uint `gorm:"index;not null" json:"editor_id"`
|
||||
OldContent string `gorm:"type:text;not null" json:"old_content"`
|
||||
CreatedAt time.Time `gorm:"index" json:"created_at"`
|
||||
}
|
||||
|
||||
const (
|
||||
SnippetVisibilityPublic = "public"
|
||||
SnippetVisibilityPrivate = "private"
|
||||
)
|
||||
|
||||
// NormalizeSnippetVisibility 归一化可见性:空或未知值一律回落 private
|
||||
func NormalizeSnippetVisibility(v string) string {
|
||||
if v == SnippetVisibilityPublic {
|
||||
return SnippetVisibilityPublic
|
||||
}
|
||||
return SnippetVisibilityPrivate
|
||||
}
|
||||
|
||||
// SiteSetting 站点级键值设置(如历史在线峰值 peak_online)
|
||||
type SiteSetting struct {
|
||||
Key string `gorm:"primaryKey;size:64" json:"key"`
|
||||
|
||||
Reference in New Issue
Block a user