mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-11-25 19:37:41 +08:00
* feat(cache): improve cache management * feat(disk-usage): add cache * feat(disk-usage): add refresh * fix(disk-usage): cache with ttl * feat(cache): implement KeyedCache and TypedCache for improved caching mechanism * fix(copy): update object retrieval to use Get instead of GetUnwrap * refactor(cache): simplify DirectoryCache structure and improve object management * fix(cache): correct cache entry initialization and key deletion logic in TypedCache * refactor(driver): remove GetObjInfo interface and simplify Link function logic https://github.com/OpenListTeam/OpenList/pull/888/files#r2430925783 * fix(link): optimize link retrieval and caching logic * refactor(cache): consolidate cache management and improve directory cache handling * fix(cache): add cache control based on storage configuration in List function * . * refactor: replace fmt.Sprintf with strconv for integer conversions * refactor(cache): enhance cache entry management with Expirable interface * fix(cache): improve link reference acquisition logic to handle expiration * refactor: replace OnlyLinkMFile with NoLinkSF in driver configurations and logic * refactor(link): enhance link caching logic with dynamic type keys based on IP and User-Agent * feat(drivers): add LinkCacheType to driver configurations for enhanced caching * refactor(cache): streamline directory object management in cache operations * refactor(cache): remove unnecessary 'dirty' field from CacheEntry structure * refactor(cache): replace 'dirty' field with bitwise flags * refactor(io): 调高SyncClosers.AcquireReference的优先级 * refactor(link): 优化链接获取逻辑,增加重 * refactor(link): 添加RequireReference字段以增强链接管理 * refactor(link): 移除MFile字段,改用RangeReader * refactor: 移除不必要的NoLinkSF字段 * refactor(cache): 修改目录缓存的脏标志定义和更新逻辑 * feat(cache): add expiration gc --------- Co-authored-by: KirCute <951206789@qq.com> Co-authored-by: KirCute <kircute@foxmail.com> Co-authored-by: j2rong4cn <j2rong@qq.com>
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package fs
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/OpenListTeam/OpenList/v4/internal/conf"
|
|
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
|
"github.com/OpenListTeam/OpenList/v4/internal/op"
|
|
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
|
"github.com/pkg/errors"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// List files
|
|
func list(ctx context.Context, path string, args *ListArgs) ([]model.Obj, error) {
|
|
meta, _ := ctx.Value(conf.MetaKey).(*model.Meta)
|
|
user, _ := ctx.Value(conf.UserKey).(*model.User)
|
|
virtualFiles := op.GetStorageVirtualFilesWithDetailsByPath(ctx, path, !args.WithStorageDetails, args.Refresh)
|
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
|
if err != nil && len(virtualFiles) == 0 {
|
|
return nil, errors.WithMessage(err, "failed get storage")
|
|
}
|
|
|
|
var _objs []model.Obj
|
|
if storage != nil {
|
|
_objs, err = op.List(ctx, storage, actualPath, model.ListArgs{
|
|
ReqPath: path,
|
|
Refresh: args.Refresh,
|
|
WithStorageDetails: args.WithStorageDetails,
|
|
})
|
|
if err != nil {
|
|
if !args.NoLog {
|
|
log.Errorf("fs/list: %+v", err)
|
|
}
|
|
if len(virtualFiles) == 0 {
|
|
return nil, errors.WithMessage(err, "failed get objs")
|
|
}
|
|
}
|
|
}
|
|
|
|
om := model.NewObjMerge()
|
|
if whetherHide(user, meta, path) {
|
|
om.InitHideReg(meta.Hide)
|
|
}
|
|
objs := om.Merge(_objs, virtualFiles...)
|
|
return objs, nil
|
|
}
|
|
|
|
func whetherHide(user *model.User, meta *model.Meta, path string) bool {
|
|
// if is admin, don't hide
|
|
if user == nil || user.CanSeeHides() {
|
|
return false
|
|
}
|
|
// if meta is nil, don't hide
|
|
if meta == nil {
|
|
return false
|
|
}
|
|
// if meta.Hide is empty, don't hide
|
|
if meta.Hide == "" {
|
|
return false
|
|
}
|
|
// if meta doesn't apply to sub_folder, don't hide
|
|
if !utils.PathEqual(meta.Path, path) && !meta.HSub {
|
|
return false
|
|
}
|
|
// if is guest, hide
|
|
return true
|
|
}
|