通过自动提及和标签创建功能,增强文章编辑功能

- 在文章编辑过程中,实现了自动创建不存在的@提及和#标签的功能,确保它们被添加到相应的数据库中。
- 更新了内容处理逻辑,以利用新创建的提及和标签,从而改善用户体验和内容管理。
- 增强了人物和链接标签创建的后端处理能力,使文章编辑过程中能够实现无缝集成。
This commit is contained in:
Alex-larget
2026-03-16 11:09:26 +08:00
parent b3ce6b5445
commit d4ba905ee5
29 changed files with 732 additions and 10 deletions

View File

@@ -33,10 +33,13 @@ func DBLinkTagSave(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": false, "error": "请求体无效"})
return
}
if body.TagID == "" || body.Label == "" {
c.JSON(http.StatusOK, gin.H{"success": false, "error": "tagId 和 label 必填"})
if body.Label == "" {
c.JSON(http.StatusOK, gin.H{"success": false, "error": "label 必填"})
return
}
if body.TagID == "" {
body.TagID = body.Label
}
if body.Type == "" {
body.Type = "url"
}
@@ -46,6 +49,11 @@ func DBLinkTagSave(c *gin.Context) {
}
db := database.DB()
var existing model.LinkTag
// 按 label 查找:文章编辑自动创建场景,若已存在则直接返回
if db.Where("label = ?", body.Label).First(&existing).Error == nil {
c.JSON(http.StatusOK, gin.H{"success": true, "linkTag": existing})
return
}
if db.Where("tag_id = ?", body.TagID).First(&existing).Error == nil {
existing.Label = body.Label
existing.URL = body.URL

View File

@@ -64,11 +64,18 @@ func DBPersonSave(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": false, "error": "name 必填"})
return
}
if body.PersonID == "" {
body.PersonID = fmt.Sprintf("%s_%d", body.Name, time.Now().UnixMilli())
}
db := database.DB()
var existing model.Person
// 按 name 查找文章编辑自动创建场景PersonID 为空时先查是否已存在
if body.PersonID == "" {
if db.Where("name = ?", strings.TrimSpace(body.Name)).First(&existing).Error == nil {
c.JSON(http.StatusOK, gin.H{"success": true, "person": existing})
return
}
}
if body.PersonID == "" {
body.PersonID = fmt.Sprintf("%s_%d", strings.ToLower(strings.ReplaceAll(strings.TrimSpace(body.Name), " ", "_")), time.Now().UnixMilli())
}
if db.Where("person_id = ?", body.PersonID).First(&existing).Error == nil {
existing.Name = body.Name
existing.Label = body.Label