mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-11-25 11:29:29 +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>
107 lines
2.4 KiB
Go
107 lines
2.4 KiB
Go
package virtual
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/OpenListTeam/OpenList/v4/internal/driver"
|
|
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
|
"github.com/OpenListTeam/OpenList/v4/internal/stream"
|
|
"github.com/OpenListTeam/OpenList/v4/pkg/utils/random"
|
|
)
|
|
|
|
type Virtual struct {
|
|
model.Storage
|
|
Addition
|
|
}
|
|
|
|
func (d *Virtual) Config() driver.Config {
|
|
return config
|
|
}
|
|
|
|
func (d *Virtual) Init(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (d *Virtual) Drop(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (d *Virtual) GetAddition() driver.Additional {
|
|
return &d.Addition
|
|
}
|
|
|
|
func (d *Virtual) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
|
|
var res []model.Obj
|
|
for i := 0; i < d.NumFile; i++ {
|
|
res = append(res, d.genObj(false))
|
|
}
|
|
for i := 0; i < d.NumFolder; i++ {
|
|
res = append(res, d.genObj(true))
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
type DummyMFile struct{}
|
|
|
|
func (f DummyMFile) Read(p []byte) (n int, err error) {
|
|
return random.Rand.Read(p)
|
|
}
|
|
|
|
func (f DummyMFile) ReadAt(p []byte, off int64) (n int, err error) {
|
|
return random.Rand.Read(p)
|
|
}
|
|
|
|
func (DummyMFile) Seek(offset int64, whence int) (int64, error) {
|
|
return offset, nil
|
|
}
|
|
|
|
func (d *Virtual) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
|
return &model.Link{
|
|
RangeReader: stream.GetRangeReaderFromMFile(file.GetSize(), DummyMFile{}),
|
|
}, nil
|
|
}
|
|
|
|
func (d *Virtual) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) (model.Obj, error) {
|
|
dir := &model.Object{
|
|
Name: dirName,
|
|
Size: 0,
|
|
IsFolder: true,
|
|
Modified: time.Now(),
|
|
}
|
|
return dir, nil
|
|
}
|
|
|
|
func (d *Virtual) Move(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj, error) {
|
|
return srcObj, nil
|
|
}
|
|
|
|
func (d *Virtual) Rename(ctx context.Context, srcObj model.Obj, newName string) (model.Obj, error) {
|
|
obj := &model.Object{
|
|
Name: newName,
|
|
Size: srcObj.GetSize(),
|
|
IsFolder: srcObj.IsDir(),
|
|
Modified: time.Now(),
|
|
}
|
|
return obj, nil
|
|
}
|
|
|
|
func (d *Virtual) Copy(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj, error) {
|
|
return srcObj, nil
|
|
}
|
|
|
|
func (d *Virtual) Remove(ctx context.Context, obj model.Obj) error {
|
|
return nil
|
|
}
|
|
|
|
func (d *Virtual) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) (model.Obj, error) {
|
|
file := &model.Object{
|
|
Name: stream.GetName(),
|
|
Size: stream.GetSize(),
|
|
Modified: time.Now(),
|
|
}
|
|
return file, nil
|
|
}
|
|
|
|
var _ driver.Driver = (*Virtual)(nil)
|