mirror of https://github.com/Xhofe/alist
style: shorten name `operations` to `op`
parent
9ec6d5be7a
commit
7ac1d14eeb
|
@ -12,7 +12,7 @@ import (
|
||||||
_ "github.com/alist-org/alist/v3/drivers"
|
_ "github.com/alist-org/alist/v3/drivers"
|
||||||
"github.com/alist-org/alist/v3/internal/bootstrap/data"
|
"github.com/alist-org/alist/v3/internal/bootstrap/data"
|
||||||
"github.com/alist-org/alist/v3/internal/conf"
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -37,7 +37,7 @@ func convert(s string) string {
|
||||||
func generateDriversJson() {
|
func generateDriversJson() {
|
||||||
drivers := make(Drivers)
|
drivers := make(Drivers)
|
||||||
drivers["drivers"] = make(KV[interface{}])
|
drivers["drivers"] = make(KV[interface{}])
|
||||||
driverInfoMap := operations.GetDriverInfoMap()
|
driverInfoMap := op.GetDriverInfoMap()
|
||||||
for k, v := range driverInfoMap {
|
for k, v := range driverInfoMap {
|
||||||
drivers["drivers"][k] = convert(k)
|
drivers["drivers"][k] = convert(k)
|
||||||
items := make(KV[interface{}])
|
items := make(KV[interface{}])
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (d *AliDrive) Init(ctx context.Context, storage model.Storage) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// TODO login / refresh token
|
// TODO login / refresh token
|
||||||
//operations.MustSaveDriverStorage(d)
|
//op.MustSaveDriverStorage(d)
|
||||||
err = d.refreshToken()
|
err = d.refreshToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -2,7 +2,7 @@ package local
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Addition struct {
|
type Addition struct {
|
||||||
|
@ -23,5 +23,5 @@ func New() driver.Driver {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
operations.RegisterDriver(config, New)
|
op.RegisterDriver(config, New)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/drivers/base"
|
"github.com/alist-org/alist/v3/drivers/base"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
)
|
)
|
||||||
|
@ -30,7 +30,7 @@ func (d *AliDrive) refreshToken() error {
|
||||||
return fmt.Errorf("failed to refresh token: %s", e.Message)
|
return fmt.Errorf("failed to refresh token: %s", e.Message)
|
||||||
}
|
}
|
||||||
d.RefreshToken, d.AccessToken = resp.RefreshToken, resp.AccessToken
|
d.RefreshToken, d.AccessToken = resp.RefreshToken, resp.AccessToken
|
||||||
operations.MustSaveDriverStorage(d)
|
op.MustSaveDriverStorage(d)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"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/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/alist-org/alist/v3/server/common"
|
"github.com/alist-org/alist/v3/server/common"
|
||||||
"github.com/disintegration/imaging"
|
"github.com/disintegration/imaging"
|
||||||
|
@ -49,7 +49,7 @@ func (d *Local) Init(ctx context.Context, storage model.Storage) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
operations.MustSaveDriverStorage(d)
|
op.MustSaveDriverStorage(d)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package local
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Addition struct {
|
type Addition struct {
|
||||||
|
@ -23,5 +23,5 @@ func New() driver.Driver {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
operations.RegisterDriver(config, New)
|
op.RegisterDriver(config, New)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package onedrive
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Addition struct {
|
type Addition struct {
|
||||||
|
@ -27,5 +27,5 @@ func New() driver.Driver {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
operations.RegisterDriver(config, New)
|
op.RegisterDriver(config, New)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"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/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
@ -92,7 +92,7 @@ func (d *Onedrive) _refreshToken() error {
|
||||||
return errs.EmptyToken
|
return errs.EmptyToken
|
||||||
}
|
}
|
||||||
d.RefreshToken, d.AccessToken = resp.RefreshToken, resp.AccessToken
|
d.RefreshToken, d.AccessToken = resp.RefreshToken, resp.AccessToken
|
||||||
operations.MustSaveDriverStorage(d)
|
op.MustSaveDriverStorage(d)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package local
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Addition struct {
|
type Addition struct {
|
||||||
|
@ -22,5 +22,5 @@ func New() driver.Driver {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
operations.RegisterDriver(config, New)
|
op.RegisterDriver(config, New)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/drivers/base"
|
"github.com/alist-org/alist/v3/drivers/base"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
)
|
)
|
||||||
|
@ -46,7 +46,7 @@ func (d *PikPak) refreshToken() error {
|
||||||
}).Post(url)
|
}).Post(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.Status = err.Error()
|
d.Status = err.Error()
|
||||||
operations.MustSaveDriverStorage(d)
|
op.MustSaveDriverStorage(d)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if e.ErrorCode != 0 {
|
if e.ErrorCode != 0 {
|
||||||
|
@ -55,14 +55,14 @@ func (d *PikPak) refreshToken() error {
|
||||||
return d.login()
|
return d.login()
|
||||||
}
|
}
|
||||||
d.Status = e.Error
|
d.Status = e.Error
|
||||||
operations.MustSaveDriverStorage(d)
|
op.MustSaveDriverStorage(d)
|
||||||
return errors.New(e.Error)
|
return errors.New(e.Error)
|
||||||
}
|
}
|
||||||
data := res.Body()
|
data := res.Body()
|
||||||
d.Status = "work"
|
d.Status = "work"
|
||||||
d.RefreshToken = jsoniter.Get(data, "refresh_token").ToString()
|
d.RefreshToken = jsoniter.Get(data, "refresh_token").ToString()
|
||||||
d.AccessToken = jsoniter.Get(data, "access_token").ToString()
|
d.AccessToken = jsoniter.Get(data, "access_token").ToString()
|
||||||
operations.MustSaveDriverStorage(d)
|
op.MustSaveDriverStorage(d)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ func (d *Template) Init(ctx context.Context, storage model.Storage) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// TODO login / refresh token
|
// TODO login / refresh token
|
||||||
//operations.MustSaveDriverStorage(d)
|
//op.MustSaveDriverStorage(d)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package local
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Addition struct {
|
type Addition struct {
|
||||||
|
@ -29,5 +29,5 @@ func New() driver.Driver {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
operations.RegisterDriver(config, New)
|
op.RegisterDriver(config, New)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package virtual
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Addition struct {
|
type Addition struct {
|
||||||
|
@ -26,5 +26,5 @@ func New() driver.Driver {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
operations.RegisterDriver(config, New)
|
op.RegisterDriver(config, New)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/conf"
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/errs"
|
"github.com/alist-org/alist/v3/internal/errs"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/task"
|
"github.com/alist-org/alist/v3/pkg/task"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
func AddURI(ctx context.Context, uri string, dstDirPath string) error {
|
func AddURI(ctx context.Context, uri string, dstDirPath string) error {
|
||||||
// check storage
|
// check storage
|
||||||
storage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath)
|
storage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed get storage")
|
return errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ func AddURI(ctx context.Context, uri string, dstDirPath string) error {
|
||||||
return errors.WithStack(errs.UploadNotSupported)
|
return errors.WithStack(errs.UploadNotSupported)
|
||||||
}
|
}
|
||||||
// check path is valid
|
// check path is valid
|
||||||
obj, err := operations.Get(ctx, storage, dstDirActualPath)
|
obj, err := op.Get(ctx, storage, dstDirActualPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errs.IsObjectNotFound(err) {
|
if !errs.IsObjectNotFound(err) {
|
||||||
return errors.WithMessage(err, "failed get object")
|
return errors.WithMessage(err, "failed get object")
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
conf2 "github.com/alist-org/alist/v3/internal/conf"
|
conf2 "github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/db"
|
"github.com/alist-org/alist/v3/internal/db"
|
||||||
"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/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/task"
|
"github.com/alist-org/alist/v3/pkg/task"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
@ -39,7 +39,7 @@ func TestConnect(t *testing.T) {
|
||||||
|
|
||||||
func TestDown(t *testing.T) {
|
func TestDown(t *testing.T) {
|
||||||
TestConnect(t)
|
TestConnect(t)
|
||||||
err := operations.CreateStorage(context.Background(), model.Storage{
|
err := op.CreateStorage(context.Background(), model.Storage{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
MountPath: "/",
|
MountPath: "/",
|
||||||
Index: 0,
|
Index: 0,
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"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/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/task"
|
"github.com/alist-org/alist/v3/pkg/task"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -114,7 +114,7 @@ var TransferTaskManager = task.NewTaskManager(3, func(k *uint64) {
|
||||||
|
|
||||||
func (m *Monitor) Complete() error {
|
func (m *Monitor) Complete() error {
|
||||||
// check dstDir again
|
// check dstDir again
|
||||||
storage, dstDirActualPath, err := operations.GetStorageAndActualPath(m.dstDirPath)
|
storage, dstDirActualPath, err := op.GetStorageAndActualPath(m.dstDirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed get storage")
|
return errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ func (m *Monitor) Complete() error {
|
||||||
ReadCloser: f,
|
ReadCloser: f,
|
||||||
Mimetype: mimetype,
|
Mimetype: mimetype,
|
||||||
}
|
}
|
||||||
return operations.Put(tsk.Ctx, storage, dstDirActualPath, stream, tsk.SetProgress)
|
return op.Put(tsk.Ctx, storage, dstDirActualPath, stream, tsk.SetProgress)
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,12 @@ import (
|
||||||
"github.com/alist-org/alist/v3/internal/db"
|
"github.com/alist-org/alist/v3/internal/db"
|
||||||
"github.com/alist-org/alist/v3/internal/message"
|
"github.com/alist-org/alist/v3/internal/message"
|
||||||
"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/op"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initDevData() {
|
func initDevData() {
|
||||||
err := operations.CreateStorage(context.Background(), model.Storage{
|
err := op.CreateStorage(context.Background(), model.Storage{
|
||||||
MountPath: "/",
|
MountPath: "/",
|
||||||
Index: 0,
|
Index: 0,
|
||||||
Driver: "local",
|
Driver: "local",
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/alist-org/alist/v3/internal/conf"
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/db"
|
"github.com/alist-org/alist/v3/internal/db"
|
||||||
"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/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ func LoadStorages() {
|
||||||
}
|
}
|
||||||
go func(storages []model.Storage) {
|
go func(storages []model.Storage) {
|
||||||
for i := range storages {
|
for i := range storages {
|
||||||
err := operations.LoadStorage(context.Background(), storages[i])
|
err := op.LoadStorage(context.Background(), storages[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log.Errorf("failed get enabled storages: %+v", err)
|
utils.Log.Errorf("failed get enabled storages: %+v", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// why don't need `cache` for storage?
|
// why don't need `cache` for storage?
|
||||||
// because all storage store in `operations.storagesMap`
|
// because all storage store in `op.storagesMap`
|
||||||
// the most of the read operation is from `operations.storagesMap`
|
// the most of the read operation is from `op.storagesMap`
|
||||||
// just for persistence in database
|
// just for persistence in database
|
||||||
|
|
||||||
// CreateStorage just insert storage to database
|
// CreateStorage just insert storage to database
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"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/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/task"
|
"github.com/alist-org/alist/v3/pkg/task"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -21,17 +21,17 @@ var CopyTaskManager = task.NewTaskManager(3, func(tid *uint64) {
|
||||||
// Copy if in the same storage, call move method
|
// Copy if in the same storage, call move method
|
||||||
// if not, add copy task
|
// if not, add copy task
|
||||||
func _copy(ctx context.Context, srcObjPath, dstDirPath string) (bool, error) {
|
func _copy(ctx context.Context, srcObjPath, dstDirPath string) (bool, error) {
|
||||||
srcStorage, srcObjActualPath, err := operations.GetStorageAndActualPath(srcObjPath)
|
srcStorage, srcObjActualPath, err := op.GetStorageAndActualPath(srcObjPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.WithMessage(err, "failed get src storage")
|
return false, errors.WithMessage(err, "failed get src storage")
|
||||||
}
|
}
|
||||||
dstStorage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath)
|
dstStorage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.WithMessage(err, "failed get dst storage")
|
return false, errors.WithMessage(err, "failed get dst storage")
|
||||||
}
|
}
|
||||||
// copy if in the same storage, just call driver.Copy
|
// copy if in the same storage, just call driver.Copy
|
||||||
if srcStorage.GetStorage() == dstStorage.GetStorage() {
|
if srcStorage.GetStorage() == dstStorage.GetStorage() {
|
||||||
return false, operations.Copy(ctx, srcStorage, srcObjActualPath, dstDirActualPath)
|
return false, op.Copy(ctx, srcStorage, srcObjActualPath, dstDirActualPath)
|
||||||
}
|
}
|
||||||
// not in the same storage
|
// not in the same storage
|
||||||
CopyTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64]{
|
CopyTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64]{
|
||||||
|
@ -45,13 +45,13 @@ func _copy(ctx context.Context, srcObjPath, dstDirPath string) (bool, error) {
|
||||||
|
|
||||||
func copyBetween2Storages(t *task.Task[uint64], srcStorage, dstStorage driver.Driver, srcObjPath, dstDirPath string) error {
|
func copyBetween2Storages(t *task.Task[uint64], srcStorage, dstStorage driver.Driver, srcObjPath, dstDirPath string) error {
|
||||||
t.SetStatus("getting src object")
|
t.SetStatus("getting src object")
|
||||||
srcObj, err := operations.Get(t.Ctx, srcStorage, srcObjPath)
|
srcObj, err := op.Get(t.Ctx, srcStorage, srcObjPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessagef(err, "failed get src [%s] file", srcObjPath)
|
return errors.WithMessagef(err, "failed get src [%s] file", srcObjPath)
|
||||||
}
|
}
|
||||||
if srcObj.IsDir() {
|
if srcObj.IsDir() {
|
||||||
t.SetStatus("src object is dir, listing objs")
|
t.SetStatus("src object is dir, listing objs")
|
||||||
objs, err := operations.List(t.Ctx, srcStorage, srcObjPath, model.ListArgs{})
|
objs, err := op.List(t.Ctx, srcStorage, srcObjPath, model.ListArgs{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessagef(err, "failed list src [%s] objs", srcObjPath)
|
return errors.WithMessagef(err, "failed list src [%s] objs", srcObjPath)
|
||||||
}
|
}
|
||||||
|
@ -80,11 +80,11 @@ func copyBetween2Storages(t *task.Task[uint64], srcStorage, dstStorage driver.Dr
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyFileBetween2Storages(tsk *task.Task[uint64], srcStorage, dstStorage driver.Driver, srcFilePath, dstDirPath string) error {
|
func copyFileBetween2Storages(tsk *task.Task[uint64], srcStorage, dstStorage driver.Driver, srcFilePath, dstDirPath string) error {
|
||||||
srcFile, err := operations.Get(tsk.Ctx, srcStorage, srcFilePath)
|
srcFile, err := op.Get(tsk.Ctx, srcStorage, srcFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessagef(err, "failed get src [%s] file", srcFilePath)
|
return errors.WithMessagef(err, "failed get src [%s] file", srcFilePath)
|
||||||
}
|
}
|
||||||
link, _, err := operations.Link(tsk.Ctx, srcStorage, srcFilePath, model.LinkArgs{})
|
link, _, err := op.Link(tsk.Ctx, srcStorage, srcFilePath, model.LinkArgs{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessagef(err, "failed get [%s] link", srcFilePath)
|
return errors.WithMessagef(err, "failed get [%s] link", srcFilePath)
|
||||||
}
|
}
|
||||||
|
@ -92,5 +92,5 @@ func copyFileBetween2Storages(tsk *task.Task[uint64], srcStorage, dstStorage dri
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessagef(err, "failed get [%s] stream", srcFilePath)
|
return errors.WithMessagef(err, "failed get [%s] stream", srcFilePath)
|
||||||
}
|
}
|
||||||
return operations.Put(tsk.Ctx, dstStorage, dstDirPath, stream, tsk.SetProgress)
|
return op.Put(tsk.Ctx, dstStorage, dstDirPath, stream, tsk.SetProgress)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@ import (
|
||||||
|
|
||||||
"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/op"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// the param named path of functions in this package is a virtual path
|
// the param named path of functions in this package is a virtual path
|
||||||
// So, the purpose of this package is to convert virtual path to actual path
|
// So, the purpose of this package is to convert virtual path to actual path
|
||||||
// then pass the actual path to the operations package
|
// then pass the actual path to the op package
|
||||||
|
|
||||||
func List(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) {
|
func List(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) {
|
||||||
res, err := list(ctx, path, refresh...)
|
res, err := list(ctx, path, refresh...)
|
||||||
|
@ -97,7 +97,7 @@ func PutAsTask(dstDirPath string, file model.FileStreamer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStorage(path string) (driver.Driver, error) {
|
func GetStorage(path string) (driver.Driver, error) {
|
||||||
storageDriver, _, err := operations.GetStorageAndActualPath(path)
|
storageDriver, _, err := op.GetStorageAndActualPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"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/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -15,14 +15,14 @@ func get(ctx context.Context, path string) (model.Obj, error) {
|
||||||
path = utils.StandardizePath(path)
|
path = utils.StandardizePath(path)
|
||||||
// maybe a virtual file
|
// maybe a virtual file
|
||||||
if path != "/" {
|
if path != "/" {
|
||||||
virtualFiles := operations.GetStorageVirtualFilesByPath(stdpath.Dir(path))
|
virtualFiles := op.GetStorageVirtualFilesByPath(stdpath.Dir(path))
|
||||||
for _, f := range virtualFiles {
|
for _, f := range virtualFiles {
|
||||||
if f.GetName() == stdpath.Base(path) {
|
if f.GetName() == stdpath.Base(path) {
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// if there are no storage prefix with path, maybe root folder
|
// if there are no storage prefix with path, maybe root folder
|
||||||
if path == "/" {
|
if path == "/" {
|
||||||
|
@ -35,5 +35,5 @@ func get(ctx context.Context, path string) (model.Obj, error) {
|
||||||
}
|
}
|
||||||
return nil, errors.WithMessage(err, "failed get storage")
|
return nil, errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
return operations.Get(ctx, storage, actualPath)
|
return op.Get(ctx, storage, actualPath)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,14 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"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/op"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, model.Obj, error) {
|
func link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, model.Obj, error) {
|
||||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, errors.WithMessage(err, "failed get storage")
|
return nil, nil, errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
return operations.Link(ctx, storage, actualPath, args)
|
return op.Link(ctx, storage, actualPath, args)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"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/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -16,15 +16,15 @@ import (
|
||||||
func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) {
|
func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) {
|
||||||
meta := ctx.Value("meta").(*model.Meta)
|
meta := ctx.Value("meta").(*model.Meta)
|
||||||
user := ctx.Value("user").(*model.User)
|
user := ctx.Value("user").(*model.User)
|
||||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
||||||
virtualFiles := operations.GetStorageVirtualFilesByPath(path)
|
virtualFiles := op.GetStorageVirtualFilesByPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if len(virtualFiles) != 0 {
|
if len(virtualFiles) != 0 {
|
||||||
return virtualFiles, nil
|
return virtualFiles, nil
|
||||||
}
|
}
|
||||||
return nil, errors.WithMessage(err, "failed get storage")
|
return nil, errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
objs, err := operations.List(ctx, storage, actualPath, model.ListArgs{
|
objs, err := op.List(ctx, storage, actualPath, model.ListArgs{
|
||||||
ReqPath: path,
|
ReqPath: path,
|
||||||
}, refresh...)
|
}, refresh...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,54 +5,54 @@ import (
|
||||||
|
|
||||||
"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/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeDir(ctx context.Context, path string) error {
|
func makeDir(ctx context.Context, path string) error {
|
||||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed get storage")
|
return errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
return operations.MakeDir(ctx, storage, actualPath)
|
return op.MakeDir(ctx, storage, actualPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func move(ctx context.Context, srcPath, dstDirPath string) error {
|
func move(ctx context.Context, srcPath, dstDirPath string) error {
|
||||||
srcStorage, srcActualPath, err := operations.GetStorageAndActualPath(srcPath)
|
srcStorage, srcActualPath, err := op.GetStorageAndActualPath(srcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed get src storage")
|
return errors.WithMessage(err, "failed get src storage")
|
||||||
}
|
}
|
||||||
dstStorage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath)
|
dstStorage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed get dst storage")
|
return errors.WithMessage(err, "failed get dst storage")
|
||||||
}
|
}
|
||||||
if srcStorage.GetStorage() != dstStorage.GetStorage() {
|
if srcStorage.GetStorage() != dstStorage.GetStorage() {
|
||||||
return errors.WithStack(errs.MoveBetweenTwoStorages)
|
return errors.WithStack(errs.MoveBetweenTwoStorages)
|
||||||
}
|
}
|
||||||
return operations.Move(ctx, srcStorage, srcActualPath, dstDirActualPath)
|
return op.Move(ctx, srcStorage, srcActualPath, dstDirActualPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rename(ctx context.Context, srcPath, dstName string) error {
|
func rename(ctx context.Context, srcPath, dstName string) error {
|
||||||
storage, srcActualPath, err := operations.GetStorageAndActualPath(srcPath)
|
storage, srcActualPath, err := op.GetStorageAndActualPath(srcPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed get storage")
|
return errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
return operations.Rename(ctx, storage, srcActualPath, dstName)
|
return op.Rename(ctx, storage, srcActualPath, dstName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func remove(ctx context.Context, path string) error {
|
func remove(ctx context.Context, path string) error {
|
||||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed get storage")
|
return errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
return operations.Remove(ctx, storage, actualPath)
|
return op.Remove(ctx, storage, actualPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func other(ctx context.Context, args model.FsOtherArgs) (interface{}, error) {
|
func other(ctx context.Context, args model.FsOtherArgs) (interface{}, error) {
|
||||||
storage, actualPath, err := operations.GetStorageAndActualPath(args.Path)
|
storage, actualPath, err := op.GetStorageAndActualPath(args.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "failed get storage")
|
return nil, errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
args.Path = actualPath
|
args.Path = actualPath
|
||||||
return operations.Other(ctx, storage, args)
|
return op.Other(ctx, storage, args)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"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/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/task"
|
"github.com/alist-org/alist/v3/pkg/task"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -19,7 +19,7 @@ var UploadTaskManager = task.NewTaskManager(3, func(tid *uint64) {
|
||||||
|
|
||||||
// putAsTask add as a put task and return immediately
|
// putAsTask add as a put task and return immediately
|
||||||
func putAsTask(dstDirPath string, file model.FileStreamer) error {
|
func putAsTask(dstDirPath string, file model.FileStreamer) error {
|
||||||
storage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath)
|
storage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed get storage")
|
return errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func putAsTask(dstDirPath string, file model.FileStreamer) error {
|
||||||
UploadTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64]{
|
UploadTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64]{
|
||||||
Name: fmt.Sprintf("upload %s to [%s](%s)", file.GetName(), storage.GetStorage().MountPath, dstDirActualPath),
|
Name: fmt.Sprintf("upload %s to [%s](%s)", file.GetName(), storage.GetStorage().MountPath, dstDirActualPath),
|
||||||
Func: func(task *task.Task[uint64]) error {
|
Func: func(task *task.Task[uint64]) error {
|
||||||
return operations.Put(task.Ctx, storage, dstDirActualPath, file, nil)
|
return op.Put(task.Ctx, storage, dstDirActualPath, file, nil)
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
return nil
|
return nil
|
||||||
|
@ -44,12 +44,12 @@ func putAsTask(dstDirPath string, file model.FileStreamer) error {
|
||||||
|
|
||||||
// putDirect put the file and return after finish
|
// putDirect put the file and return after finish
|
||||||
func putDirectly(ctx context.Context, dstDirPath string, file model.FileStreamer) error {
|
func putDirectly(ctx context.Context, dstDirPath string, file model.FileStreamer) error {
|
||||||
storage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath)
|
storage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "failed get storage")
|
return errors.WithMessage(err, "failed get storage")
|
||||||
}
|
}
|
||||||
if storage.Config().NoUpload {
|
if storage.Config().NoUpload {
|
||||||
return errors.WithStack(errs.UploadNotSupported)
|
return errors.WithStack(errs.UploadNotSupported)
|
||||||
}
|
}
|
||||||
return operations.Put(ctx, storage, dstDirActualPath, file, nil)
|
return op.Put(ctx, storage, dstDirActualPath, file, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,16 +9,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"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/op"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ClearCache(path string) {
|
func ClearCache(path string) {
|
||||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
operations.ClearCache(storage, actualPath)
|
op.ClearCache(storage, actualPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func containsByName(files []model.Obj, file model.Obj) bool {
|
func containsByName(files []model.Obj, file model.Obj) bool {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package operations
|
package op
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
|
@ -1,14 +1,14 @@
|
||||||
package operations_test
|
package op_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
_ "github.com/alist-org/alist/v3/drivers"
|
_ "github.com/alist-org/alist/v3/drivers"
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDriverItemsMap(t *testing.T) {
|
func TestDriverItemsMap(t *testing.T) {
|
||||||
itemsMap := operations.GetDriverInfoMap()
|
itemsMap := op.GetDriverInfoMap()
|
||||||
if len(itemsMap) != 0 {
|
if len(itemsMap) != 0 {
|
||||||
t.Logf("driverInfoMap: %v", itemsMap)
|
t.Logf("driverInfoMap: %v", itemsMap)
|
||||||
} else {
|
} else {
|
|
@ -1,4 +1,4 @@
|
||||||
package operations
|
package op
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -17,7 +17,7 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// In order to facilitate adding some other things before and after file operations
|
// In order to facilitate adding some other things before and after file op
|
||||||
|
|
||||||
var listCache = cache.NewMemCache(cache.WithShards[[]model.Obj](64))
|
var listCache = cache.NewMemCache(cache.WithShards[[]model.Obj](64))
|
||||||
var listG singleflight.Group[[]model.Obj]
|
var listG singleflight.Group[[]model.Obj]
|
||||||
|
@ -30,7 +30,7 @@ func ClearCache(storage driver.Driver, path string) {
|
||||||
// List files in storage, not contains virtual file
|
// List files in storage, not contains virtual file
|
||||||
func List(ctx context.Context, storage driver.Driver, path string, args model.ListArgs, refresh ...bool) ([]model.Obj, error) {
|
func List(ctx context.Context, storage driver.Driver, path string, args model.ListArgs, refresh ...bool) ([]model.Obj, error) {
|
||||||
path = utils.StandardizePath(path)
|
path = utils.StandardizePath(path)
|
||||||
log.Debugf("operations.List %s", path)
|
log.Debugf("op.List %s", path)
|
||||||
dir, err := Get(ctx, storage, path)
|
dir, err := Get(ctx, storage, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "failed get dir")
|
return nil, errors.WithMessage(err, "failed get dir")
|
||||||
|
@ -75,7 +75,7 @@ func isRoot(path, rootFolderPath string) bool {
|
||||||
// Get object from list of files
|
// Get object from list of files
|
||||||
func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, error) {
|
func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, error) {
|
||||||
path = utils.StandardizePath(path)
|
path = utils.StandardizePath(path)
|
||||||
log.Debugf("operations.Get %s", path)
|
log.Debugf("op.Get %s", path)
|
||||||
if g, ok := storage.(driver.Getter); ok {
|
if g, ok := storage.(driver.Getter); ok {
|
||||||
obj, err := g.Get(ctx, path)
|
obj, err := g.Get(ctx, path)
|
||||||
if err == nil {
|
if err == nil {
|
|
@ -1,4 +1,4 @@
|
||||||
package operations
|
package op
|
||||||
|
|
||||||
import (
|
import (
|
||||||
stdpath "path"
|
stdpath "path"
|
|
@ -1,4 +1,4 @@
|
||||||
package operations
|
package op
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package operations_test
|
package op_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/db"
|
"github.com/alist-org/alist/v3/internal/db"
|
||||||
"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/op"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
@ -30,7 +30,7 @@ func TestCreateStorage(t *testing.T) {
|
||||||
{storage: model.Storage{Driver: "None", MountPath: "/none", Addition: `{"root_folder":"."}`}, isErr: true},
|
{storage: model.Storage{Driver: "None", MountPath: "/none", Addition: `{"root_folder":"."}`}, isErr: true},
|
||||||
}
|
}
|
||||||
for _, storage := range storages {
|
for _, storage := range storages {
|
||||||
err := operations.CreateStorage(context.Background(), storage.storage)
|
err := op.CreateStorage(context.Background(), storage.storage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !storage.isErr {
|
if !storage.isErr {
|
||||||
t.Errorf("failed to create storage: %+v", err)
|
t.Errorf("failed to create storage: %+v", err)
|
||||||
|
@ -43,7 +43,7 @@ func TestCreateStorage(t *testing.T) {
|
||||||
|
|
||||||
func TestGetStorageVirtualFilesByPath(t *testing.T) {
|
func TestGetStorageVirtualFilesByPath(t *testing.T) {
|
||||||
setupStorages(t)
|
setupStorages(t)
|
||||||
virtualFiles := operations.GetStorageVirtualFilesByPath("/a")
|
virtualFiles := op.GetStorageVirtualFilesByPath("/a")
|
||||||
var names []string
|
var names []string
|
||||||
for _, virtualFile := range virtualFiles {
|
for _, virtualFile := range virtualFiles {
|
||||||
names = append(names, virtualFile.GetName())
|
names = append(names, virtualFile.GetName())
|
||||||
|
@ -58,11 +58,11 @@ func TestGetStorageVirtualFilesByPath(t *testing.T) {
|
||||||
|
|
||||||
func TestGetBalancedStorage(t *testing.T) {
|
func TestGetBalancedStorage(t *testing.T) {
|
||||||
setupStorages(t)
|
setupStorages(t)
|
||||||
storage := operations.GetBalancedStorage("/a/d/e")
|
storage := op.GetBalancedStorage("/a/d/e")
|
||||||
if storage.GetStorage().MountPath != "/a/d/e" {
|
if storage.GetStorage().MountPath != "/a/d/e" {
|
||||||
t.Errorf("expected: /a/d/e, got: %+v", storage.GetStorage().MountPath)
|
t.Errorf("expected: /a/d/e, got: %+v", storage.GetStorage().MountPath)
|
||||||
}
|
}
|
||||||
storage = operations.GetBalancedStorage("/a/d/e")
|
storage = op.GetBalancedStorage("/a/d/e")
|
||||||
if storage.GetStorage().MountPath != "/a/d/e.balance" {
|
if storage.GetStorage().MountPath != "/a/d/e.balance" {
|
||||||
t.Errorf("expected: /a/d/e.balance, got: %+v", storage.GetStorage().MountPath)
|
t.Errorf("expected: /a/d/e.balance, got: %+v", storage.GetStorage().MountPath)
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ func setupStorages(t *testing.T) {
|
||||||
{Driver: "local", MountPath: "/a/d/e.balance", Index: 4, Addition: `{"root_folder":"."}`},
|
{Driver: "local", MountPath: "/a/d/e.balance", Index: 4, Addition: `{"root_folder":"."}`},
|
||||||
}
|
}
|
||||||
for _, storage := range storages {
|
for _, storage := range storages {
|
||||||
err := operations.CreateStorage(context.Background(), storage)
|
err := op.CreateStorage(context.Background(), storage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create storage: %+v", err)
|
t.Fatalf("failed to create storage: %+v", err)
|
||||||
}
|
}
|
|
@ -3,22 +3,22 @@ package handles
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/operations"
|
"github.com/alist-org/alist/v3/internal/op"
|
||||||
"github.com/alist-org/alist/v3/server/common"
|
"github.com/alist-org/alist/v3/server/common"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ListDriverInfo(c *gin.Context) {
|
func ListDriverInfo(c *gin.Context) {
|
||||||
common.SuccessResp(c, operations.GetDriverInfoMap())
|
common.SuccessResp(c, op.GetDriverInfoMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListDriverNames(c *gin.Context) {
|
func ListDriverNames(c *gin.Context) {
|
||||||
common.SuccessResp(c, operations.GetDriverNames())
|
common.SuccessResp(c, op.GetDriverNames())
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDriverInfo(c *gin.Context) {
|
func GetDriverInfo(c *gin.Context) {
|
||||||
driverName := c.Query("driver")
|
driverName := c.Query("driver")
|
||||||
infoMap := operations.GetDriverInfoMap()
|
infoMap := op.GetDriverInfoMap()
|
||||||
items, ok := infoMap[driverName]
|
items, ok := infoMap[driverName]
|
||||||
if !ok {
|
if !ok {
|
||||||
common.ErrorStrResp(c, fmt.Sprintf("driver [%s] not found", driverName), 404)
|
common.ErrorStrResp(c, fmt.Sprintf("driver [%s] not found", driverName), 404)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/db"
|
"github.com/alist-org/alist/v3/internal/db"
|
||||||
"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/op"
|
||||||
"github.com/alist-org/alist/v3/server/common"
|
"github.com/alist-org/alist/v3/server/common"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -36,7 +36,7 @@ func CreateStorage(c *gin.Context) {
|
||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := operations.CreateStorage(c, req); err != nil {
|
if err := op.CreateStorage(c, req); err != nil {
|
||||||
common.ErrorResp(c, err, 500, true)
|
common.ErrorResp(c, err, 500, true)
|
||||||
} else {
|
} else {
|
||||||
common.SuccessResp(c)
|
common.SuccessResp(c)
|
||||||
|
@ -49,7 +49,7 @@ func UpdateStorage(c *gin.Context) {
|
||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := operations.UpdateStorage(c, req); err != nil {
|
if err := op.UpdateStorage(c, req); err != nil {
|
||||||
common.ErrorResp(c, err, 500, true)
|
common.ErrorResp(c, err, 500, true)
|
||||||
} else {
|
} else {
|
||||||
common.SuccessResp(c)
|
common.SuccessResp(c)
|
||||||
|
@ -63,7 +63,7 @@ func DeleteStorage(c *gin.Context) {
|
||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := operations.DeleteStorageById(c, uint(id)); err != nil {
|
if err := op.DeleteStorageById(c, uint(id)); err != nil {
|
||||||
common.ErrorResp(c, err, 500, true)
|
common.ErrorResp(c, err, 500, true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ func DisableStorage(c *gin.Context) {
|
||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := operations.DisableStorage(c, uint(id)); err != nil {
|
if err := op.DisableStorage(c, uint(id)); err != nil {
|
||||||
common.ErrorResp(c, err, 500, true)
|
common.ErrorResp(c, err, 500, true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ func EnableStorage(c *gin.Context) {
|
||||||
common.ErrorResp(c, err, 400)
|
common.ErrorResp(c, err, 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := operations.EnableStorage(c, uint(id)); err != nil {
|
if err := op.EnableStorage(c, uint(id)); err != nil {
|
||||||
common.ErrorResp(c, err, 500, true)
|
common.ErrorResp(c, err, 500, true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue