♻️ Refactor recent documents handling

This commit is contained in:
Jeffrey Chen 2025-11-05 15:07:41 +08:00
parent 188fa4e669
commit fe87cf521a
6 changed files with 330 additions and 140 deletions

View file

@ -80,6 +80,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/storage/getRecentDocs", model.CheckAuth, getRecentDocs)
ginServer.Handle("POST", "/api/storage/updateRecentDocViewTime", model.CheckAuth, updateRecentDocViewTime)
ginServer.Handle("POST", "/api/storage/updateRecentDocCloseTime", model.CheckAuth, updateRecentDocCloseTime)
ginServer.Handle("POST", "/api/storage/batchUpdateRecentDocCloseTime", model.CheckAuth, batchUpdateRecentDocCloseTime)
ginServer.Handle("POST", "/api/storage/updateRecentDocOpenTime", model.CheckAuth, updateRecentDocOpenTime)
ginServer.Handle("POST", "/api/storage/getOutlineStorage", model.CheckAuth, getOutlineStorage)

View file

@ -293,11 +293,11 @@ func updateRecentDocCloseTime(c *gin.Context) {
return
}
if nil == arg["rootID"] {
rootID, ok := arg["rootID"].(string)
if !ok || rootID == "" {
return
}
rootID := arg["rootID"].(string)
err := model.UpdateRecentDocCloseTime(rootID)
if err != nil {
ret.Code = -1
@ -305,3 +305,26 @@ func updateRecentDocCloseTime(c *gin.Context) {
return
}
}
func batchUpdateRecentDocCloseTime(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
rootIDsArg := arg["rootIDs"].([]interface{})
var rootIDs []string
for _, id := range rootIDsArg {
rootIDs = append(rootIDs, id.(string))
}
err := model.BatchUpdateRecentDocCloseTime(rootIDs)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
return
}
}