feat: fs other api
This commit is contained in:
parent
2a68c3cc7b
commit
721f18a7f4
@ -2,12 +2,13 @@ package local
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/alist-org/alist/v3/internal/errs"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alist-org/alist/v3/internal/errs"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/operations"
|
||||||
@ -175,7 +176,7 @@ func (d *Local) Put(ctx context.Context, dstDir model.Obj, stream model.FileStre
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Local) Other(ctx context.Context, data interface{}) (interface{}, error) {
|
func (d *Local) Other(ctx context.Context, args model.OtherArgs) (interface{}, error) {
|
||||||
return nil, errs.NotSupport
|
return nil, errs.NotSupport
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,15 @@ package virtual
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/errs"
|
"github.com/alist-org/alist/v3/internal/errs"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils/random"
|
"github.com/alist-org/alist/v3/pkg/utils/random"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"io"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Virtual struct {
|
type Virtual struct {
|
||||||
@ -93,7 +94,7 @@ func (d *Virtual) Put(ctx context.Context, dstDir model.Obj, stream model.FileSt
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Virtual) Other(ctx context.Context, data interface{}) (interface{}, error) {
|
func (d *Virtual) Other(ctx context.Context, args model.OtherArgs) (interface{}, error) {
|
||||||
return nil, errs.NotSupport
|
return nil, errs.NotSupport
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ type Meta interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Other interface {
|
type Other interface {
|
||||||
Other(ctx context.Context, data interface{}) (interface{}, error)
|
Other(ctx context.Context, args model.OtherArgs) (interface{}, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Reader interface {
|
type Reader interface {
|
||||||
|
@ -2,6 +2,7 @@ package fs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/operations"
|
||||||
@ -102,3 +103,11 @@ func GetStorage(path string) (driver.Driver, error) {
|
|||||||
}
|
}
|
||||||
return storageDriver, nil
|
return storageDriver, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Other(ctx context.Context, args model.FsOtherArgs) (interface{}, error) {
|
||||||
|
res, err := other(ctx, args)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("failed remove %s: %+v", args.Path, err)
|
||||||
|
}
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
@ -2,7 +2,9 @@ package fs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/errs"
|
"github.com/alist-org/alist/v3/internal/errs"
|
||||||
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/operations"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -45,3 +47,12 @@ func remove(ctx context.Context, path string) error {
|
|||||||
}
|
}
|
||||||
return operations.Remove(ctx, storage, actualPath)
|
return operations.Remove(ctx, storage, actualPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func other(ctx context.Context, args model.FsOtherArgs) (interface{}, error) {
|
||||||
|
storage, actualPath, err := operations.GetStorageAndActualPath(args.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "failed get storage")
|
||||||
|
}
|
||||||
|
args.Path = actualPath
|
||||||
|
return operations.Other(ctx, storage, args)
|
||||||
|
}
|
@ -19,3 +19,15 @@ type Link struct {
|
|||||||
FilePath *string // local file, return the filepath
|
FilePath *string // local file, return the filepath
|
||||||
Expiration *time.Duration // url expiration time
|
Expiration *time.Duration // url expiration time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OtherArgs struct {
|
||||||
|
Obj Obj
|
||||||
|
Method string
|
||||||
|
Data interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type FsOtherArgs struct {
|
||||||
|
Path string `json:"path" form:"path"`
|
||||||
|
Method string `json:"method" form:"method"`
|
||||||
|
Data interface{} `json:"data" form:"data"`
|
||||||
|
}
|
@ -150,6 +150,19 @@ func Link(ctx context.Context, storage driver.Driver, path string, args model.Li
|
|||||||
return link, file, err
|
return link, file, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// other api
|
||||||
|
func Other(ctx context.Context, storage driver.Driver, args model.FsOtherArgs) (interface{}, error) {
|
||||||
|
obj, err := Get(ctx, storage, args.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessagef(err, "failed to get obj")
|
||||||
|
}
|
||||||
|
return storage.Other(ctx, model.OtherArgs{
|
||||||
|
Obj: obj,
|
||||||
|
Method: args.Method,
|
||||||
|
Data: args.Data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func MakeDir(ctx context.Context, storage driver.Driver, path string) error {
|
func MakeDir(ctx context.Context, storage driver.Driver, path string) error {
|
||||||
// check if dir exists
|
// check if dir exists
|
||||||
f, err := Get(ctx, storage, path)
|
f, err := Get(ctx, storage, path)
|
||||||
|
@ -253,3 +253,36 @@ func FsGet(c *gin.Context) {
|
|||||||
RawURL: rawURL,
|
RawURL: rawURL,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FsOtherReq struct {
|
||||||
|
model.FsOtherArgs
|
||||||
|
Password string `json:"password" form:"password"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func FsOther(c *gin.Context) {
|
||||||
|
var req FsOtherReq
|
||||||
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
|
common.ErrorResp(c, err, 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user := c.MustGet("user").(*model.User)
|
||||||
|
req.Path = stdpath.Join(user.BasePath, req.Path)
|
||||||
|
meta, err := db.GetNearestMeta(req.Path)
|
||||||
|
if err != nil {
|
||||||
|
if !errors.Is(errors.Cause(err), errs.MetaNotFound) {
|
||||||
|
common.ErrorResp(c, err, 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.Set("meta", meta)
|
||||||
|
if !canAccess(user, meta, req.Path, req.Password) {
|
||||||
|
common.ErrorStrResp(c, "password is incorrect", 403)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res, err := fs.Other(c, req.FsOtherArgs)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResp(c, err, 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
common.SuccessResp(c, res)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user