feat(documents): rebuild project document workbench
This commit is contained in:
@@ -59,8 +59,8 @@ func (a StaticAnalyzer) Analyze(item models.SaInboxItem, userID uint) ([]Suggest
|
||||
// 默认分析器只把用户主动收集的内容整理成可审阅草稿;它不调用 provider,也不创建正式对象。
|
||||
return []Suggestion{
|
||||
{Kind: "task", Title: "跟进:" + subject, Body: body},
|
||||
{Kind: "note", Title: subject + "整理笔记", Body: body},
|
||||
{Kind: "source", Title: subject + "背景资料", Body: body},
|
||||
{Kind: "document", Title: subject + "整理笔记.md", Body: body},
|
||||
{Kind: "document", Title: subject + "背景资料.md", Body: body},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ func normalizeSuggestions(suggestions []Suggestion) ([]Suggestion, error) {
|
||||
for _, suggestion := range suggestions {
|
||||
kind := strings.ToLower(strings.TrimSpace(suggestion.Kind))
|
||||
title := strings.TrimSpace(suggestion.Title)
|
||||
if title == "" || (kind != "task" && kind != "note" && kind != "source") {
|
||||
if title == "" || (kind != "task" && kind != "document") {
|
||||
return nil, ErrInvalidSuggestion
|
||||
}
|
||||
result = append(result, Suggestion{Kind: kind, Title: title, Body: strings.TrimSpace(suggestion.Body)})
|
||||
@@ -274,17 +274,21 @@ func createConfirmedObject(tx *gorm.DB, item models.SaInboxItem, suggestion mode
|
||||
ProjectID: item.ProjectID, ProjectIdentity: item.ProjectIdentity, CreatedBy: item.CreatedBy,
|
||||
SourceInboxItemID: &sourceInboxItemID, Title: suggestion.Title, Description: suggestion.Body, Status: "open",
|
||||
}).Error
|
||||
case "note":
|
||||
return tx.Create(&models.SaNote{
|
||||
case "document":
|
||||
name := strings.TrimSpace(suggestion.Title)
|
||||
if !strings.HasSuffix(strings.ToLower(name), ".md") {
|
||||
name += ".md"
|
||||
}
|
||||
document := models.SaDocument{
|
||||
ProjectID: item.ProjectID, ProjectIdentity: item.ProjectIdentity, CreatedBy: item.CreatedBy,
|
||||
SourceInboxItemID: &sourceInboxItemID, Title: suggestion.Title, Markdown: suggestion.Body,
|
||||
}).Error
|
||||
case "source":
|
||||
// 文本型 Inbox 资料不是上传文件,不构造或伪造任何本地路径。
|
||||
return tx.Create(&models.SaSource{
|
||||
ProjectID: item.ProjectID, ProjectIdentity: item.ProjectIdentity, CreatedBy: item.CreatedBy,
|
||||
SourceInboxItemID: &sourceInboxItemID, Kind: "text", Title: suggestion.Title, ContentText: suggestion.Body,
|
||||
}).Error
|
||||
SourceInboxItemID: &sourceInboxItemID, Kind: models.DocumentKindFile, Name: name,
|
||||
NormalizedName: strings.ToLower(name), Extension: ".md", MimeType: "text/markdown; charset=utf-8",
|
||||
Size: int64(len([]byte(suggestion.Body))), Revision: 1, ScanStatus: "not_scanned",
|
||||
}
|
||||
if err := tx.Create(&document).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Create(&models.SaDocumentContent{DocumentID: document.ID, Markdown: suggestion.Body}).Error
|
||||
default:
|
||||
return ErrInvalidSuggestion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user