Skip to content

Commit

Permalink
chore!: change root folder
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 4, 2022
1 parent a4a8739 commit a1c86b3
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion drivers/123/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Addition struct {
Password string `json:"password" required:"true"`
OrderBy string `json:"order_by" type:"select" options:"name,fileId,updateAt,createAt" default:"name"`
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
driver.RootFolderID
driver.RootID
// define other
StreamUpload bool `json:"stream_upload"`
//Field string `json:"field" type:"select" required:"true" options:"a,b,c" default:"a"`
Expand Down
2 changes: 1 addition & 1 deletion drivers/aliyundrive/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Addition struct {
driver.RootFolderID
driver.RootID
RefreshToken string `json:"refresh_token" required:"true"`
OrderBy string `json:"order_by" type:"select" options:"name,size,updated_at,created_at"`
OrderDirection string `json:"order_direction" type:"select" options:"ASC,DESC"`
Expand Down
2 changes: 1 addition & 1 deletion drivers/baidu_netdisk/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type Addition struct {
RefreshToken string `json:"refresh_token" required:"true"`
driver.RootFolderPath
driver.RootPath
OrderBy string `json:"order_by" type:"select" options:"name,time,size" default:"name"`
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
DownloadAPI string `json:"download_api" type:"select" options:"official,crack" default:"official"`
Expand Down
2 changes: 1 addition & 1 deletion drivers/ftp/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Addition struct {
Address string `json:"address" required:"true"`
Username string `json:"username" required:"true"`
Password string `json:"password" required:"true"`
driver.RootFolderPath
driver.RootPath
}

var config = driver.Config{
Expand Down
2 changes: 1 addition & 1 deletion drivers/google_drive/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Addition struct {
driver.RootFolderID
driver.RootID
RefreshToken string `json:"refresh_token" required:"true"`
OrderBy string `json:"order_by" type:"string" help:"such as: folder,name,modifiedTime"`
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc"`
Expand Down
11 changes: 5 additions & 6 deletions drivers/local/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"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/internal/op"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/alist-org/alist/v3/server/common"
"github.com/disintegration/imaging"
Expand All @@ -39,17 +38,17 @@ func (d *Local) Init(ctx context.Context, storage model.Storage) error {
if err != nil {
return err
}
if !utils.Exists(d.RootFolder) {
err = fmt.Errorf("root folder %s not exists", d.RootFolder)
if !utils.Exists(d.GetRootPath()) {
err = fmt.Errorf("root folder %s not exists", d.GetRootPath())
} else {
if !filepath.IsAbs(d.RootFolder) {
d.RootFolder, err = filepath.Abs(d.RootFolder)
if !filepath.IsAbs(d.GetRootPath()) {
abs, err := filepath.Abs(d.GetRootPath())
if err != nil {
return err
}
d.SetRootPath(abs)
}
}
op.MustSaveDriverStorage(d)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/local/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Addition struct {
driver.RootFolderPath
driver.RootPath
Thumbnail bool `json:"thumbnail" required:"true" help:"enable thumbnail"`
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/onedrive/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Addition struct {
driver.RootFolderPath
driver.RootPath
Region string `json:"region" type:"select" required:"true" options:"global,cn,us,de"`
IsSharepoint bool `json:"is_sharepoint"`
ClientID string `json:"client_id" required:"true"`
Expand Down
2 changes: 1 addition & 1 deletion drivers/pikpak/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Addition struct {
driver.RootFolderID
driver.RootID
Username string `json:"username" required:"true"`
Password string `json:"password" required:"true"`
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/quark/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type Addition struct {
Cookie string `json:"cookie" required:"true"`
driver.RootFolderID
driver.RootID
OrderBy string `json:"order_by" type:"select" options:"file_type,file_name,updated_at" default:"file_name"`
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/s3/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Addition struct {
driver.RootFolderPath
driver.RootPath
Bucket string `json:"bucket" required:"true"`
Endpoint string `json:"endpoint" required:"true"`
Region string `json:"region"`
Expand Down
2 changes: 1 addition & 1 deletion drivers/sftp/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Addition struct {
Username string `json:"username" required:"true"`
PrivateKey string `json:"private_key" type:"text"`
Password string `json:"password"`
driver.RootFolderPath
driver.RootPath
}

var config = driver.Config{
Expand Down
2 changes: 1 addition & 1 deletion drivers/teambition/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Addition struct {
Region string `json:"region" type:"select" options:"china,international" required:"true"`
Cookie string `json:"cookie" required:"true"`
ProjectID string `json:"project_id" required:"true"`
driver.RootFolderID
driver.RootID
OrderBy string `json:"order_by" type:"select" options:"fileName,fileSize,updated,created" default:"fileName"`
OrderDirection string `json:"order_direction" type:"select" options:"Asc,Desc" default:"Asc"`
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/template/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

type Addition struct {
// Usually one of two
driver.RootFolderPath
driver.RootFolderID
driver.RootPath
driver.RootID
// define other
Field string `json:"field" type:"select" required:"true" options:"a,b,c" default:"a"`
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/uss/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Addition struct {
driver.RootFolderPath
driver.RootPath
Bucket string `json:"bucket" required:"true"`
Endpoint string `json:"endpoint" required:"true"`
OperatorName string `json:"operator_name" required:"true"`
Expand Down
2 changes: 1 addition & 1 deletion drivers/virtual/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Addition struct {
driver.RootFolderPath
driver.RootPath
NumFile int `json:"num_file" type:"number" default:"30" required:"true"`
NumFolder int `json:"num_folder" type:"number" default:"30" required:"true"`
MaxFileSize int64 `json:"max_file_size" type:"number" default:"1073741824" required:"true"`
Expand Down
28 changes: 16 additions & 12 deletions internal/driver/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,30 @@ type Info struct {
Config Config `json:"config"`
}

type IRootFolderPath interface {
GetRootFolderPath() string
type IRootPath interface {
GetRootPath() string
}

type IRootFolderId interface {
GetRootFolderId() string
type IRootId interface {
GetRootId() string
}

type RootFolderPath struct {
RootFolder string `json:"root_folder" required:"true" help:"Root folder path"`
type RootPath struct {
RootFolderPath string `json:"root_folder_path" required:"true"`
}

type RootFolderID struct {
RootFolder string `json:"root_folder" required:"true" help:"Root folder id"`
type RootID struct {
RootFolderID string `json:"root_folder_id" required:"true"`
}

func (r RootFolderPath) GetRootFolderPath() string {
return r.RootFolder
func (r RootPath) GetRootPath() string {
return r.RootFolderPath
}

func (r RootFolderID) GetRootFolderId() string {
return r.RootFolder
func (r *RootPath) SetRootPath(path string) {
r.RootFolderPath = path
}

func (r RootID) GetRootId() string {
return r.RootFolderID
}
8 changes: 4 additions & 4 deletions internal/op/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, er
}
}
// is root folder
if r, ok := storage.GetAddition().(driver.IRootFolderId); ok && utils.PathEqual(path, "/") {
if r, ok := storage.GetAddition().(driver.IRootId); ok && utils.PathEqual(path, "/") {
return &model.Object{
ID: r.GetRootFolderId(),
ID: r.GetRootId(),
Name: "root",
Size: 0,
Modified: storage.GetStorage().Modified,
IsFolder: true,
}, nil
}
if r, ok := storage.GetAddition().(driver.IRootFolderPath); ok && isRoot(path, r.GetRootFolderPath()) {
if r, ok := storage.GetAddition().(driver.IRootPath); ok && isRoot(path, r.GetRootPath()) {
return &model.Object{
Path: r.GetRootFolderPath(),
Path: r.GetRootPath(),
Name: "root",
Size: 0,
Modified: storage.GetStorage().Modified,
Expand Down
4 changes: 2 additions & 2 deletions internal/op/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
// ActualPath Get the actual path
// !!! maybe and \ in the path when use windows local
func ActualPath(storage driver.Additional, rawPath string) string {
if i, ok := storage.(driver.IRootFolderPath); ok {
rawPath = stdpath.Join(i.GetRootFolderPath(), rawPath)
if i, ok := storage.(driver.IRootPath); ok {
rawPath = stdpath.Join(i.GetRootPath(), rawPath)
}
return utils.StandardizePath(rawPath)
}
Expand Down

0 comments on commit a1c86b3

Please sign in to comment.