feat(strm): support multiple drivers (#510)

This commit is contained in:
hshpy
2025-07-02 15:16:46 +08:00
committed by GitHub
parent 44f4658f37
commit 5c4cd1b198
2 changed files with 5 additions and 44 deletions

View File

@ -112,18 +112,10 @@ func (d *Strm) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]
}
func (d *Strm) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
root, sub := d.getRootAndPath(file.GetPath())
dsts, ok := d.pathMap[root]
if !ok {
return nil, errs.ObjectNotFound
}
for _, dst := range dsts {
link, err := d.link(ctx, dst, sub)
if err == nil {
return link, nil
}
}
return nil, errs.ObjectNotFound
link := d.getLink(ctx, file.GetPath())
return &model.Link{
MFile: model.NewNopMFile(strings.NewReader(link)),
}, nil
}
func (d *Strm) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
@ -150,24 +142,4 @@ func (d *Strm) Put(ctx context.Context, dstDir model.Obj, s model.FileStreamer,
return errors.New("strm Driver cannot put file")
}
func (d *Strm) PutURL(ctx context.Context, dstDir model.Obj, name, url string) error {
return errors.New("strm Driver cannot put file")
}
func (d *Strm) GetArchiveMeta(ctx context.Context, obj model.Obj, args model.ArchiveArgs) (model.ArchiveMeta, error) {
return nil, errs.NotImplement
}
func (d *Strm) ListArchive(ctx context.Context, obj model.Obj, args model.ArchiveInnerArgs) ([]model.Obj, error) {
return nil, errs.NotImplement
}
func (d *Strm) Extract(ctx context.Context, obj model.Obj, args model.ArchiveInnerArgs) (*model.Link, error) {
return nil, errs.NotImplement
}
func (d *Strm) ArchiveDecompress(ctx context.Context, srcObj, dstDir model.Obj, args model.ArchiveDecompressArgs) error {
return errs.NotImplement
}
var _ driver.Driver = (*Strm)(nil)

View File

@ -111,7 +111,7 @@ func (d *Strm) list(ctx context.Context, dst, sub string, args *fs.ListArgs) ([]
Size: size,
Modified: obj.ModTime(),
IsFolder: obj.IsDir(),
Path: stdpath.Join(sub, obj.GetName()),
Path: stdpath.Join(reqPath, obj.GetName()),
}
thumb, ok := model.GetThumb(obj)
if !ok {
@ -126,17 +126,6 @@ func (d *Strm) list(ctx context.Context, dst, sub string, args *fs.ListArgs) ([]
})
}
func (d *Strm) link(ctx context.Context, dst, sub string) (*model.Link, error) {
reqPath := stdpath.Join(dst, sub)
_, err := fs.Get(ctx, reqPath, &fs.GetArgs{NoLog: true})
if err != nil {
return nil, err
}
return &model.Link{
MFile: model.NewNopMFile(strings.NewReader(d.getLink(ctx, reqPath))),
}, nil
}
func (d *Strm) getLink(ctx context.Context, path string) string {
apiUrl := d.SiteUrl
if len(apiUrl) > 0 {