增加清理附件按钮,对悬空无引用的图片/附件进行清理 (#918)

* add attach_clean & change_theme

* add attach_clean & change_theme

* add

* add readme

---------

Co-authored-by: root <root@DESKTOP-L84EQPB.localdomain>
This commit is contained in:
Sharklet
2023-12-19 13:19:31 +08:00
committed by GitHub
parent 0dbb5d7967
commit 71b8e528ff
13 changed files with 200 additions and 18 deletions

View File

@@ -634,6 +634,41 @@ func (c *ManagerController) AttachList() {
c.Data["Lists"] = attachList
}
//附件清理.
func (c *ManagerController) AttachClean() {
c.Prepare()
attachList, _, err := models.NewAttachment().FindToPager(0, 0)
if err != nil {
c.Abort("500")
}
for _, item := range attachList {
p := filepath.Join(conf.WorkingDirectory, item.FilePath)
item.IsExist = filetil.FileExists(p)
if item.IsExist {
// 判断
searchList, err := models.NewDocumentSearchResult().SearchAllDocument(item.HttpPath)
if err != nil {
c.Abort("500")
} else if len(searchList) == 0 {
logs.Info("delete file:", item.FilePath)
item.FilePath = p
if err := item.Delete(); err != nil {
logs.Error("AttachDelete => ", err)
c.JsonResult(6002, err.Error())
break
}
}
}
}
c.JsonResult(0, "ok")
}
//附件详情.
func (c *ManagerController) AttachDetailed() {
c.Prepare()