mirror of
https://github.com/AlistGo/alist.git
synced 2025-11-25 19:37:41 +08:00
* 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 4e20daaf9e.
* 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>
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package db
|
|
|
|
import (
|
|
"github.com/alist-org/alist/v3/internal/model"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func GetMetaByPath(path string) (*model.Meta, error) {
|
|
meta := model.Meta{Path: path}
|
|
if err := db.Where(meta).First(&meta).Error; err != nil {
|
|
return nil, errors.Wrapf(err, "failed select meta")
|
|
}
|
|
return &meta, nil
|
|
}
|
|
|
|
func GetMetaById(id uint) (*model.Meta, error) {
|
|
var u model.Meta
|
|
if err := db.First(&u, id).Error; err != nil {
|
|
return nil, errors.Wrapf(err, "failed get old meta")
|
|
}
|
|
return &u, nil
|
|
}
|
|
|
|
func CreateMeta(u *model.Meta) error {
|
|
return errors.WithStack(db.Create(u).Error)
|
|
}
|
|
|
|
func UpdateMeta(u *model.Meta) error {
|
|
return errors.WithStack(db.Save(u).Error)
|
|
}
|
|
|
|
func GetMetas(pageIndex, pageSize int) (metas []model.Meta, count int64, err error) {
|
|
metaDB := db.Model(&model.Meta{})
|
|
if err = metaDB.Count(&count).Error; err != nil {
|
|
return nil, 0, errors.Wrapf(err, "failed get metas count")
|
|
}
|
|
if err = metaDB.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&metas).Error; err != nil {
|
|
return nil, 0, errors.Wrapf(err, "failed get find metas")
|
|
}
|
|
return metas, count, nil
|
|
}
|
|
|
|
func DeleteMetaById(id uint) error {
|
|
return errors.WithStack(db.Delete(&model.Meta{}, id).Error)
|
|
}
|