refactor: split the db package hook and cache to the op package (#2747)
* refactor:separate the setting method from the db package to the op package and add the cache * refactor:separate the meta method from the db package to the op package * fix:setting not load database data * refactor:separate the user method from the db package to the op package * refactor:remove user JoinPath error * fix:op package user cache * refactor:fs package list method * fix:tile virtual paths (close #2743) * Revert "refactor:remove user JoinPath error" This reverts commit 4e20daaf9e700da047000d4fd4900abbe05c3848. * clean path directly may lead to unknown behavior * fix: The path of the meta passed in must be prefix of reqPath * chore: rename all virtualPath to mountPath * fix: `getStoragesByPath` and `GetStorageVirtualFilesByPath` is_sub_path: /a/b isn't subpath of /a/bc * fix: don't save setting if hook error Co-authored-by: Noah Hsu <i@nn.ci>
This commit is contained in:
@ -6,9 +6,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"github.com/alist-org/alist/v3/internal/op"
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -22,7 +21,7 @@ func ListMetas(c *gin.Context) {
|
||||
}
|
||||
req.Validate()
|
||||
log.Debugf("%+v", req)
|
||||
metas, total, err := db.GetMetas(req.Page, req.PerPage)
|
||||
metas, total, err := op.GetMetas(req.Page, req.PerPage)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
@ -44,8 +43,7 @@ func CreateMeta(c *gin.Context) {
|
||||
common.ErrorStrResp(c, fmt.Sprintf("%s is illegal: %s", r, err.Error()), 400)
|
||||
return
|
||||
}
|
||||
req.Path = utils.FixAndCleanPath(req.Path)
|
||||
if err := db.CreateMeta(&req); err != nil {
|
||||
if err := op.CreateMeta(&req); err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
} else {
|
||||
common.SuccessResp(c)
|
||||
@ -63,8 +61,7 @@ func UpdateMeta(c *gin.Context) {
|
||||
common.ErrorStrResp(c, fmt.Sprintf("%s is illegal: %s", r, err.Error()), 400)
|
||||
return
|
||||
}
|
||||
req.Path = utils.FixAndCleanPath(req.Path)
|
||||
if err := db.UpdateMeta(&req); err != nil {
|
||||
if err := op.UpdateMeta(&req); err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
} else {
|
||||
common.SuccessResp(c)
|
||||
@ -89,7 +86,7 @@ func DeleteMeta(c *gin.Context) {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
if err := db.DeleteMetaById(uint(id)); err != nil {
|
||||
if err := op.DeleteMetaById(uint(id)); err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
}
|
||||
@ -103,7 +100,7 @@ func GetMeta(c *gin.Context) {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
meta, err := db.GetMetaById(uint(id))
|
||||
meta, err := op.GetMetaById(uint(id))
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
|
Reference in New Issue
Block a user