- Phase 0: 实现服务端回复导出策略矩阵引擎 (replyexport.EvaluatePolicy)、数据库迁移 (2026-09-11-message-export-policy.sql)、SSE done 事件挂载与能力探测 API - Phase 1: 构建前端 ReplyDocumentIR 语法树解析与渲染管道,支持 Markdown / DOCX 文件下载及带格式富文本剪贴板复制 - Phase 2: 实现私密自由文档 (freeform_documents) 领域服务、PostgreSQL 乐观锁版本管理、ACL 隐私隔离、一键共享与右侧栏编辑联动 - 专项修复: 1. 修复后台 API 路由注册并加入双向拉取同步,确保私密保存实时进入我的私密列表 2. 实现轻量回复专属 DOCX 生成与静默下载逻辑 (downloadDocxReply) 3. 将 LaTeX 公式转为标准 MathML 矢量标记,支持粘贴到 Microsoft Word / WPS 自动识别为原生公式
89 lines
3.5 KiB
Go
89 lines
3.5 KiB
Go
package freedoc
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
ErrNotFound = errors.New("freeform document not found")
|
|
ErrForbidden = errors.New("permission denied to access document")
|
|
ErrConflict = errors.New("optimistic concurrency conflict: version or sha mismatch")
|
|
ErrInvalidParam = errors.New("invalid parameter")
|
|
ErrMessageNotExportable = errors.New("chat message is not exportable or content is empty")
|
|
)
|
|
|
|
// FreeformDocument 自由私密/共享文档元数据
|
|
type FreeformDocument struct {
|
|
DocID string `json:"doc_id"`
|
|
ProjectID int `json:"project_id"`
|
|
OwnerUserID int `json:"owner_user_id"`
|
|
SourceMessageID *int64 `json:"source_message_id,omitempty"`
|
|
SourceContentSHA256 string `json:"source_content_sha256"`
|
|
Title string `json:"title"`
|
|
GovernanceMode string `json:"governance_mode"` // 恒为 'freeform'
|
|
Space string `json:"space"` // 'my_private' | 'project_shared' | 'trash'
|
|
CurrentVersionID int `json:"current_version_id"`
|
|
CurrentSHA256 string `json:"current_sha256"`
|
|
IsDeleted bool `json:"is_deleted"`
|
|
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// FreeformDocumentVersion 自由文档历史版本快照
|
|
type FreeformDocumentVersion struct {
|
|
ID int64 `json:"id"`
|
|
DocID string `json:"doc_id"`
|
|
VersionNo int `json:"version_no"`
|
|
ContentSHA256 string `json:"content_sha256"`
|
|
ContentMarkdown string `json:"content_markdown"`
|
|
CreatedBy int `json:"created_by"`
|
|
ChangeSummary string `json:"change_summary"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// FreeformDocDetail 自由文档详情(含当前版本 Markdown 正文)
|
|
type FreeformDocDetail struct {
|
|
Document FreeformDocument `json:"document"`
|
|
Content string `json:"content_markdown"`
|
|
}
|
|
|
|
// FreeformDocSummary 列表项概要
|
|
type FreeformDocSummary struct {
|
|
DocID string `json:"doc_id"`
|
|
ProjectID int `json:"project_id"`
|
|
OwnerUserID int `json:"owner_user_id"`
|
|
Title string `json:"title"`
|
|
Space string `json:"space"`
|
|
CurrentVersionID int `json:"current_version_id"`
|
|
CurrentSHA256 string `json:"current_sha256"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// CreateFromMessageRequest 从单条消息保存到私密文档请求
|
|
type CreateFromMessageRequest struct {
|
|
MessageID int64 `json:"message_id"`
|
|
ProjectID int `json:"project_id"`
|
|
Title string `json:"title,omitempty"`
|
|
ExpectedSHA256 string `json:"expected_sha256,omitempty"`
|
|
}
|
|
|
|
// CreateFreeformDocRequest 直接创建空白/自定义自由文档请求
|
|
type CreateFreeformDocRequest struct {
|
|
ProjectID int `json:"project_id"`
|
|
Title string `json:"title"`
|
|
ContentMarkdown string `json:"content_markdown"`
|
|
Space string `json:"space,omitempty"` // 默认 'my_private'
|
|
}
|
|
|
|
// UpdateFreeformDocRequest 更新自由文档请求
|
|
type UpdateFreeformDocRequest struct {
|
|
Title *string `json:"title,omitempty"`
|
|
ContentMarkdown *string `json:"content_markdown,omitempty"`
|
|
ChangeSummary string `json:"change_summary,omitempty"`
|
|
ExpectedVersion *int `json:"expected_version,omitempty"`
|
|
ExpectedSHA256 *string `json:"expected_sha256,omitempty"`
|
|
}
|