An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:recycle: Code style: unused function (#17307)
Jeffrey Chen349a8ddc981e
diff --git a/kernel/av/av.go b/kernel/av/av.goindex 83493a2e66..f977a5efc1 100644--- a/kernel/av/av.go+++ b/kernel/av/av.go@@ -73,16 +73,6 @@ func (kValues *KeyValues) GetBlockValue() (ret *Value) {return}-func GetKeyBlockValue(blockKeyValues []*KeyValues) (ret *Value) {- for _, kv := range blockKeyValues {- if KeyTypeBlock == kv.Key.Type && 0 < len(kv.Values) {- ret = kv.Values[0]- break- }- }- return-}-func GetValue(keyValues []*KeyValues, keyID, itemID string) (ret *Value) {for _, kv := range keyValues {if kv.Key.ID == keyID {diff --git a/kernel/cache/asset.go b/kernel/cache/asset.goindex 05b83de8df..2263a88307 100644--- a/kernel/cache/asset.go+++ b/kernel/cache/asset.go@@ -111,18 +111,6 @@ var (assetsLock = sync.Mutex{})-// IterateAssets 遍历所有资源,适合只读场景-func IterateAssets(fn func(path string, asset *Asset) bool) {- assetsLock.Lock()- defer assetsLock.Unlock()-- for path, asset := range assetsCache {- if !fn(path, asset) {- break- }- }-}-// FilterAssets 根据过滤函数返回符合条件的资源func FilterAssets(filter func(path string, asset *Asset) bool) (ret map[string]*Asset) {assetsLock.Lock()@@ -137,14 +125,6 @@ func FilterAssets(filter func(path string, asset *Asset) bool) (ret map[string]*return}-// GetAssetByPath 根据路径获取资源-func GetAssetByPath(path string) *Asset {- assetsLock.Lock()- defer assetsLock.Unlock()-- return assetsCache[path]-}-func RemoveAsset(path string) {assetsLock.Lock()defer assetsLock.Unlock()diff --git a/kernel/model/history.go b/kernel/model/history.goindex e38d81b04c..97eff1860b 100644--- a/kernel/model/history.go+++ b/kernel/model/history.go@@ -801,34 +801,6 @@ func recentModifiedAssets() (ret []string) {return}-var attributeViewLatestHistoryTime = time.Now().Unix()--func recentModifiedAttributeViews() (ret []string) {- entries, err := os.ReadDir(filepath.Join(util.DataDir, "storage", "av"))- if nil != err {- logging.LogErrorf("read attribute view dir failed: %s", err)- return- }-- for _, entry := range entries {- if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".json") {- continue- }-- info, err := entry.Info()- if nil != err {- logging.LogErrorf("read attribute view file info failed: %s", err)- continue- }-- if info.ModTime().Unix() > attributeViewLatestHistoryTime {- ret = append(ret, filepath.Join(util.DataDir, "storage", "av", entry.Name()))- }- }- attributeViewLatestHistoryTime = time.Now().Unix()- return-}-const (HistoryOpClean = "clean"HistoryOpUpdate = "update"diff --git a/kernel/model/import.go b/kernel/model/import.goindex f6da24015f..6a7408e766 100644--- a/kernel/model/import.go+++ b/kernel/model/import.go@@ -56,19 +56,6 @@ import ("github.com/siyuan-note/siyuan/kernel/util")-func HTML2Markdown(htmlStr string, luteEngine *lute.Lute) (markdown string, withMath bool, err error) {- tree, withMath := HTML2Tree(htmlStr, luteEngine)-- var formatted []byte- renderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions, luteEngine.ParseOptions)- for nodeType, rendererFunc := range luteEngine.HTML2MdRendererFuncs {- renderer.ExtRendererFuncs[nodeType] = rendererFunc- }- formatted = renderer.Render()- markdown = gulu.Str.FromBytes(formatted)- return-}-func HTML2Tree(htmlStr string, luteEngine *lute.Lute) (tree *parse.Tree, withMath bool) {htmlStr = gulu.Str.RemovePUA(htmlStr)assetDirPath := filepath.Join(util.DataDir, "assets")diff --git a/kernel/server/port.go b/kernel/server/port.godeleted file mode 100644index e62321a206..0000000000--- a/kernel/server/port.go+++ /dev/null@@ -1,139 +0,0 @@-// SiYuan - Refactor your thinking-// Copyright (c) 2020-present, b3log.org-//-// This program is free software: you can redistribute it and/or modify-// it under the terms of the GNU Affero General Public License as published by-// the Free Software Foundation, either version 3 of the License, or-// (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU Affero General Public License for more details.-//-// You should have received a copy of the GNU Affero General Public License-// along with this program. If not, see <https://www.gnu.org/licenses/>.--package server--import (- "fmt"- "os"- "os/exec"- "path/filepath"- "strconv"- "strings"- "time"-- "github.com/88250/gulu"- goPS "github.com/mitchellh/go-ps"- "github.com/siyuan-note/logging"- "github.com/siyuan-note/siyuan/kernel/util"-)--func killRunningKernel() {- defer logging.Recover()-- now := time.Now()- defer logging.LogInfof("check running kernel elapsed [%dms]", time.Since(now).Milliseconds())-- processes, err := goPS.Processes()- if err != nil {- logging.LogErrorf("get processes failed: %s", err)- killByPort(util.FixedPort)- return- }-- currentPid := os.Getpid()- killed := false- for _, process := range processes {- if process.Pid() == currentPid {- continue- }- procName := strings.ToLower(process.Executable())- if strings.Contains(procName, "siyuan-kernel") {- kill(fmt.Sprintf("%d", process.Pid()))- killed = true- }- }-- if killed {- portJSON := filepath.Join(util.HomeDir, ".config", "siyuan", "port.json")- os.RemoveAll(portJSON)- }-}--func killByPort(port string) {- if !util.IsPortOpen(port) {- return- }-- portJSON := filepath.Join(util.HomeDir, ".config", "siyuan", "port.json")- os.RemoveAll(portJSON)-- pid := pidByPort(port)- if "" == pid {- return- }-- pidInt, _ := strconv.Atoi(pid)- proc, _ := goPS.FindProcess(pidInt)- var name string- if nil != proc {- name = proc.Executable()- }- kill(pid)- logging.LogInfof("killed process [name=%s, pid=%s]", name, pid)-}--func kill(pid string) {- var killCmd *exec.Cmd- if gulu.OS.IsWindows() {- killCmd = exec.Command("cmd", "/c", "TASKKILL /F /PID "+pid)- } else {- killCmd = exec.Command("kill", "-9", pid)- }- gulu.CmdAttr(killCmd)- killCmd.CombinedOutput()-}--func pidByPort(port string) (ret string) {- if gulu.OS.IsWindows() {- cmd := exec.Command("cmd", "/c", "netstat -ano | findstr "+port)- gulu.CmdAttr(cmd)- data, err := cmd.CombinedOutput()- if err != nil {- logging.LogErrorf("netstat failed: %s", err)- return- }- output := string(data)- lines := strings.SplitSeq(output, "\n")- for l := range lines {- if strings.Contains(l, "LISTENING") {- l = l[strings.Index(l, "LISTENING")+len("LISTENING"):]- l = strings.TrimSpace(l)- ret = l- return- }- }- return- }-- cmd := exec.Command("lsof", "-Fp", "-i", ":"+port)- gulu.CmdAttr(cmd)- data, err := cmd.CombinedOutput()- if err != nil {- logging.LogErrorf("lsof failed: %s", err)- return- }- output := string(data)- lines := strings.SplitSeq(output, "\n")- for l := range lines {- if strings.HasPrefix(l, "p") {- l = l[1:]- ret = l- return- }- }- return-}diff --git a/kernel/sql/asset.go b/kernel/sql/asset.goindex 370bc7a476..e6013b0da3 100644--- a/kernel/sql/asset.go+++ b/kernel/sql/asset.go@@ -110,16 +110,6 @@ func QueryAssetByHash(hash string) (ret *Asset) {return}-func scanAssetRows(rows *sql.Rows) (ret *Asset) {- var asset Asset- if err := rows.Scan(&asset.ID, &asset.BlockID, &asset.RootID, &asset.Box, &asset.DocPath, &asset.Path, &asset.Name, &asset.Title, &asset.Hash); err != nil {- logging.LogErrorf("query scan field failed: %s", err)- return- }- ret = &asset- return-}-func assetHashByLocalPath(linkDest, boxLocalPath, docDirLocalPath string) (ret string) {if lp := assetLocalPath(linkDest, boxLocalPath, docDirLocalPath); "" != lp {if !gulu.File.IsDir(lp) {diff --git a/kernel/treenode/node.go b/kernel/treenode/node.goindex ddd5ef52d7..265574cbc9 100644--- a/kernel/treenode/node.go+++ b/kernel/treenode/node.go@@ -326,21 +326,6 @@ func NextBlock(node *ast.Node) *ast.Node {return nil}-func FirstChildBlock(node *ast.Node) (ret *ast.Node) {- ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {- if !entering {- return ast.WalkContinue- }-- if n.IsBlock() {- ret = n- return ast.WalkStop- }- return ast.WalkContinue- })- return-}-func GetNodeInTree(tree *parse.Tree, id string) (ret *ast.Node) {ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {if !entering {diff --git a/kernel/util/file.go b/kernel/util/file.goindex ce99a3239f..1e89840d39 100644--- a/kernel/util/file.go+++ b/kernel/util/file.go@@ -206,13 +206,6 @@ func LastID(p string) (name, id string) {return}-func IsCorruptedSYData(data []byte) bool {- if 64 > len(data) || '{' != data[0] {- return true- }- return false-}-func IsValidUploadFileName(name string) bool {return name == FilterUploadFileName(name)}diff --git a/kernel/util/misc.go b/kernel/util/misc.goindex 32d3b3f757..a484b7001e 100644--- a/kernel/util/misc.go+++ b/kernel/util/misc.go@@ -211,21 +211,6 @@ func GetContainsSubStrs(s string, subStrs []string) (ret []string) {return}-func ReplaceStr(strs []string, old, new string) (ret []string, changed bool) {- if old == new {- return strs, false- }-- for i, v := range strs {- if v == old {- strs[i] = new- changed = true- }- }- ret = strs- return-}-func SanitizeSVG(svgInput string) string {// 1. 将字符串解析为节点树doc, err := html.Parse(strings.NewReader(svgInput))