From a1c86b335007349ca65d2308f061a9ef8c9ce575 Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Sun, 4 Sep 2022 13:07:53 +0800 Subject: [PATCH] chore!: change root folder --- drivers/123/meta.go | 2 +- drivers/aliyundrive/meta.go | 2 +- drivers/baidu_netdisk/meta.go | 2 +- drivers/ftp/meta.go | 2 +- drivers/google_drive/meta.go | 2 +- drivers/local/driver.go | 11 +++++------ drivers/local/meta.go | 2 +- drivers/onedrive/meta.go | 2 +- drivers/pikpak/meta.go | 2 +- drivers/quark/meta.go | 2 +- drivers/s3/meta.go | 2 +- drivers/sftp/meta.go | 2 +- drivers/teambition/meta.go | 2 +- drivers/template/meta.go | 4 ++-- drivers/uss/meta.go | 2 +- drivers/virtual/meta.go | 2 +- internal/driver/item.go | 28 ++++++++++++++++------------ internal/op/fs.go | 8 ++++---- internal/op/path.go | 4 ++-- 19 files changed, 43 insertions(+), 40 deletions(-) diff --git a/drivers/123/meta.go b/drivers/123/meta.go index e6d9fa100ad..dfb3175cad5 100644 --- a/drivers/123/meta.go +++ b/drivers/123/meta.go @@ -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"` diff --git a/drivers/aliyundrive/meta.go b/drivers/aliyundrive/meta.go index 785ebe891e3..403e62f5b89 100644 --- a/drivers/aliyundrive/meta.go +++ b/drivers/aliyundrive/meta.go @@ -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"` diff --git a/drivers/baidu_netdisk/meta.go b/drivers/baidu_netdisk/meta.go index 859adc5f9ba..e5db359a2e6 100644 --- a/drivers/baidu_netdisk/meta.go +++ b/drivers/baidu_netdisk/meta.go @@ -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"` diff --git a/drivers/ftp/meta.go b/drivers/ftp/meta.go index bb21267f2cd..c4694c5efab 100644 --- a/drivers/ftp/meta.go +++ b/drivers/ftp/meta.go @@ -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{ diff --git a/drivers/google_drive/meta.go b/drivers/google_drive/meta.go index 71f5379c459..cb8f274e64f 100644 --- a/drivers/google_drive/meta.go +++ b/drivers/google_drive/meta.go @@ -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"` diff --git a/drivers/local/driver.go b/drivers/local/driver.go index b089dc7cfd9..fee00bdd349 100644 --- a/drivers/local/driver.go +++ b/drivers/local/driver.go @@ -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" @@ -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 } diff --git a/drivers/local/meta.go b/drivers/local/meta.go index 0d0482a1f42..8d0033b826e 100644 --- a/drivers/local/meta.go +++ b/drivers/local/meta.go @@ -6,7 +6,7 @@ import ( ) type Addition struct { - driver.RootFolderPath + driver.RootPath Thumbnail bool `json:"thumbnail" required:"true" help:"enable thumbnail"` } diff --git a/drivers/onedrive/meta.go b/drivers/onedrive/meta.go index c831c67d5b6..ea2284f720f 100644 --- a/drivers/onedrive/meta.go +++ b/drivers/onedrive/meta.go @@ -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"` diff --git a/drivers/pikpak/meta.go b/drivers/pikpak/meta.go index 1e8ea4d8b62..dc9712ca040 100644 --- a/drivers/pikpak/meta.go +++ b/drivers/pikpak/meta.go @@ -6,7 +6,7 @@ import ( ) type Addition struct { - driver.RootFolderID + driver.RootID Username string `json:"username" required:"true"` Password string `json:"password" required:"true"` } diff --git a/drivers/quark/meta.go b/drivers/quark/meta.go index 52a55ed103e..f294e5999e7 100644 --- a/drivers/quark/meta.go +++ b/drivers/quark/meta.go @@ -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"` } diff --git a/drivers/s3/meta.go b/drivers/s3/meta.go index c483738657d..45029ee8eac 100644 --- a/drivers/s3/meta.go +++ b/drivers/s3/meta.go @@ -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"` diff --git a/drivers/sftp/meta.go b/drivers/sftp/meta.go index e5c056a80ac..b0211b61d4f 100644 --- a/drivers/sftp/meta.go +++ b/drivers/sftp/meta.go @@ -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{ diff --git a/drivers/teambition/meta.go b/drivers/teambition/meta.go index 79d4ec288bf..2b4a103b03a 100644 --- a/drivers/teambition/meta.go +++ b/drivers/teambition/meta.go @@ -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"` } diff --git a/drivers/template/meta.go b/drivers/template/meta.go index ca0c8c1974a..02f15306a87 100644 --- a/drivers/template/meta.go +++ b/drivers/template/meta.go @@ -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"` } diff --git a/drivers/uss/meta.go b/drivers/uss/meta.go index 4108c814a3a..6f9d1e275a7 100644 --- a/drivers/uss/meta.go +++ b/drivers/uss/meta.go @@ -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"` diff --git a/drivers/virtual/meta.go b/drivers/virtual/meta.go index 0322c5400ea..0ecafb1f65d 100644 --- a/drivers/virtual/meta.go +++ b/drivers/virtual/meta.go @@ -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"` diff --git a/internal/driver/item.go b/internal/driver/item.go index f511ecd7871..b0bc5636935 100644 --- a/internal/driver/item.go +++ b/internal/driver/item.go @@ -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 } diff --git a/internal/op/fs.go b/internal/op/fs.go index c32728ea4f0..80cf4f96738 100644 --- a/internal/op/fs.go +++ b/internal/op/fs.go @@ -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, diff --git a/internal/op/path.go b/internal/op/path.go index ae8440a489a..c0322915f45 100644 --- a/internal/op/path.go +++ b/internal/op/path.go @@ -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) }