feat: add Reference
interface to driver (#7805)
* feat: add `Reference` interface to driver * feat(123_share): support reference 123pan
This commit is contained in:
@ -144,3 +144,7 @@ func NewProgress(total int64, up UpdateProgress) *Progress {
|
||||
up: up,
|
||||
}
|
||||
}
|
||||
|
||||
type Reference interface {
|
||||
InitReference(storage Driver) error
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
"github.com/alist-org/alist/v3/internal/errs"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/pkg/generic_sync"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
@ -106,6 +107,29 @@ func initStorage(ctx context.Context, storage model.Storage, storageDriver drive
|
||||
}()
|
||||
// Unmarshal Addition
|
||||
err = utils.Json.UnmarshalFromString(driverStorage.Addition, storageDriver.GetAddition())
|
||||
if err == nil {
|
||||
if ref, ok := storageDriver.(driver.Reference); ok {
|
||||
if strings.HasPrefix(driverStorage.Remark, "ref:/") {
|
||||
refMountPath := driverStorage.Remark
|
||||
i := strings.Index(refMountPath, "\n")
|
||||
if i > 0 {
|
||||
refMountPath = refMountPath[4:i]
|
||||
} else {
|
||||
refMountPath = refMountPath[4:]
|
||||
}
|
||||
var refStorage driver.Driver
|
||||
refStorage, err = GetStorageByMountPath(refMountPath)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("ref: %w", err)
|
||||
} else {
|
||||
err = ref.InitReference(refStorage)
|
||||
if err != nil && errs.IsNotSupportError(err) {
|
||||
err = fmt.Errorf("ref: storage is not %s", storageDriver.Config().Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
err = storageDriver.Init(ctx)
|
||||
}
|
||||
|
Reference in New Issue
Block a user