Browse Source

:fire: 移除已经废弃的创建反链接口

Liang Ding 2 years ago
parent
commit
556fb1f2d4
2 changed files with 0 additions and 124 deletions
  1. 0 27
      kernel/api/ref.go
  2. 0 97
      kernel/model/backlink.go

+ 0 - 27
kernel/api/ref.go

@@ -145,30 +145,3 @@ func getBacklink(c *gin.Context) {
 	}
 	util.RandomSleep(200, 500)
 }
-
-func createBacklink(c *gin.Context) {
-	ret := gulu.Ret.NewResult()
-	defer c.JSON(http.StatusOK, ret)
-
-	arg, ok := util.JsonArg(c, ret)
-	if !ok {
-		return
-	}
-
-	defID := arg["defID"].(string)
-	refID := arg["refID"].(string)
-	refText := arg["refText"].(string)
-	isDynamic := arg["isDynamic"].(bool)
-	refRootID, err := model.CreateBacklink(defID, refID, refText, isDynamic)
-	if nil != err {
-		ret.Code = -1
-		ret.Msg = err.Error()
-		return
-	}
-	ret.Data = map[string]interface{}{
-		"defID":     defID,
-		"refID":     refID,
-		"refRootID": refRootID,
-		"refText":   refText,
-	}
-}

+ 0 - 97
kernel/model/backlink.go

@@ -20,7 +20,6 @@ import (
 	"bytes"
 	"fmt"
 	"path"
-	"regexp"
 	"sort"
 	"strconv"
 	"strings"
@@ -64,102 +63,6 @@ func RefreshBacklink(id string) {
 	}
 }
 
-func CreateBacklink(defID, refID, refText string, isDynamic bool) (refRootID string, err error) {
-	refTree, err := loadTreeByBlockID(refID)
-	if nil != err {
-		return "", err
-	}
-	refNode := treenode.GetNodeInTree(refTree, refID)
-	if nil == refNode {
-		return
-	}
-	refRootID = refTree.Root.ID
-
-	defBlockTree := treenode.GetBlockTree(defID)
-	if nil == defBlockTree {
-		return
-	}
-	defRoot := sql.GetBlock(defBlockTree.RootID)
-	if nil == defRoot {
-		return
-	}
-
-	refTextLower := strings.ToLower(refText)
-	defBlock := sql.QueryBlockByNameOrAlias(defRoot.ID, refText)
-	if nil == defBlock {
-		if strings.ToLower(defRoot.Content) == refTextLower {
-			// 如果命名别名没有命中,但文档名和提及关键字匹配,则使用文档作为定义块
-			defBlock = defRoot
-		}
-		if nil == defBlock {
-			// 使用锚文本进行搜索,取第一个匹配的定义块
-			if defIDs := sql.QueryBlockDefIDsByRefText(refTextLower, nil); 0 < len(defIDs) {
-				if defBlock = sql.GetBlock(defIDs[0]); nil != defBlock {
-					goto OK
-				}
-			}
-		}
-		if nil == defBlock {
-			defBlock = sql.GetBlock(defBlockTree.ID)
-		}
-		if nil == defBlock {
-			return
-		}
-		if strings.ToLower(defBlock.Content) != refTextLower {
-			return
-		}
-	}
-
-OK:
-	luteEngine := NewLute()
-	found := false
-	var toRemove []*ast.Node
-	ast.Walk(refNode, func(n *ast.Node, entering bool) ast.WalkStatus {
-		if !entering {
-			return ast.WalkContinue
-		}
-
-		if ast.NodeText != n.Type {
-			return ast.WalkContinue
-		}
-
-		text := gulu.Str.FromBytes(n.Tokens)
-		re := regexp.MustCompile("(?i)" + refText)
-		if strings.Contains(strings.ToLower(text), refTextLower) {
-			if isDynamic {
-				text = re.ReplaceAllString(text, "(("+defBlock.ID+" '"+refText+"'))")
-			} else {
-				text = re.ReplaceAllString(text, "(("+defBlock.ID+" \""+refText+"\"))")
-			}
-			found = true
-			subTree := parse.Inline("", []byte(text), luteEngine.ParseOptions)
-			var toInsert []*ast.Node
-			for newNode := subTree.Root.FirstChild.FirstChild; nil != newNode; newNode = newNode.Next {
-				toInsert = append(toInsert, newNode)
-			}
-			for _, insert := range toInsert {
-				n.InsertBefore(insert)
-			}
-			toRemove = append(toRemove, n)
-		}
-		return ast.WalkContinue
-	})
-
-	for _, n := range toRemove {
-		n.Unlink()
-	}
-
-	if found {
-		refTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
-		if err = indexWriteJSONQueue(refTree); nil != err {
-			return "", err
-		}
-		IncSync()
-	}
-	sql.WaitForWritingDatabase()
-	return
-}
-
 type Backlink struct {
 	DOM        string       `json:"dom"`
 	BlockPaths []*BlockPath `json:"blockPaths"`