feat(documents): rebuild project document workbench

This commit is contained in:
2026-07-24 12:16:02 +08:00
parent 366136cee9
commit 77beaebb30
73 changed files with 5867 additions and 1264 deletions

View File

@@ -74,7 +74,7 @@ type ItemPatch struct {
}
type DepositResult struct {
NoteIdentity string
DocumentIdentity string
ProjectIdentity string
}
@@ -359,14 +359,27 @@ func (s *Service) DepositItem(userID uint, itemIdentity, projectIdentity string)
}
body += "[原文链接](" + item.URL + ")"
}
note := models.SaNote{
ProjectID: project.ID, CreatedBy: userID,
Title: item.Title, Markdown: body,
name := strings.TrimSpace(item.Title)
if !strings.HasSuffix(strings.ToLower(name), ".md") {
name += ".md"
}
if err := s.db.Create(&note).Error; err != nil {
var document models.SaDocument
err = s.db.Transaction(func(tx *gorm.DB) error {
document = models.SaDocument{
ProjectID: project.ID, CreatedBy: userID, Kind: models.DocumentKindFile,
Name: name, NormalizedName: strings.ToLower(name), Extension: ".md",
MimeType: "text/markdown; charset=utf-8", Size: int64(len([]byte(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: body}).Error
})
if err != nil {
return DepositResult{}, err
}
return DepositResult{NoteIdentity: note.Identity, ProjectIdentity: project.Identity}, nil
return DepositResult{DocumentIdentity: document.Identity, ProjectIdentity: project.Identity}, nil
}
func (s *Service) SyncSources(ctx context.Context, userID uint) ([]SyncResult, error) {