Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-01-09 09:28:09 +08:00
parent f8e49f4e13
commit 941e153a4b
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
21 changed files with 176 additions and 16 deletions

View file

@ -68,6 +68,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/system/addMicrosoftDefenderExclusion", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, addMicrosoftDefenderExclusion)
ginServer.Handle("POST", "/api/system/ignoreAddMicrosoftDefenderExclusion", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, ignoreAddMicrosoftDefenderExclusion)
ginServer.Handle("POST", "/api/system/vacuumDataIndex", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, vacuumDataIndex)
ginServer.Handle("POST", "/api/system/clearTempFiles", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, clearTempFiles)
ginServer.Handle("POST", "/api/system/rebuildDataIndex", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, rebuildDataIndex)
ginServer.Handle("POST", "/api/storage/setLocalStorage", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setLocalStorage) // TODO 请使用 /api/storage/setLocalStorageVal该端点计划于 2026 年 6 月 30 日后删除 https://github.com/siyuan-note/siyuan/issues/16664#issuecomment-3694774305

View file

@ -35,6 +35,13 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func clearTempFiles(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
model.ClearTempFiles()
}
func vacuumDataIndex(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

View file

@ -684,6 +684,72 @@ func normalizeTree(tree *parse.Tree) (yfmRootID, yfmTitle, yfmUpdated string) {
return
}
func ClearTempFiles() {
var count int
var size int64
msgId := util.PushMsg(Conf.Language(276), 30*1000)
defer func() {
msg := fmt.Sprintf(Conf.Language(277), count, humanize.BytesCustomCeil(uint64(size), 2))
util.PushUpdateMsg(msgId, msg, 7000)
}()
bazaarTmp := filepath.Join(util.TempDir, "bazaar")
clearTempDir(bazaarTmp, &count, &size)
exportTmp := filepath.Join(util.TempDir, "export")
clearTempDir(exportTmp, &count, &size)
importTmp := filepath.Join(util.TempDir, "import")
clearTempDir(importTmp, &count, &size)
convertTmp := filepath.Join(util.TempDir, "convert")
clearTempDir(convertTmp, &count, &size)
osTmp := filepath.Join(util.TempDir, "os")
clearTempDir(osTmp, &count, &size)
base64Tmp := filepath.Join(util.TempDir, "base64")
clearTempDir(base64Tmp, &count, &size)
installTmp := filepath.Join(util.TempDir, "install")
clearTempDir(installTmp, &count, &size)
thumbnailsTmp := filepath.Join(util.TempDir, "thumbnails")
clearTempDir(thumbnailsTmp, &count, &size)
}
func clearTempDir(dir string, count *int, size *int64) {
entries, err := os.ReadDir(dir)
if err != nil {
return
}
for _, entry := range entries {
entryPath := filepath.Join(dir, entry.Name())
info, err := os.Stat(entryPath)
if err != nil {
continue
}
if info.IsDir() {
clearTempDir(entryPath, count, size)
} else {
if err := os.Remove(entryPath); err != nil {
continue
}
*count++
*size += info.Size()
}
}
if util.IsEmptyDir(dir) {
os.Remove(dir)
}
return
}
func VacuumDataIndex() {
util.PushEndlessProgress(Conf.language(270))
defer util.PushClearProgress()