chore!: change root folder

This commit is contained in:
Noah Hsu 2022-09-04 13:07:53 +08:00
parent a4a8739748
commit a1c86b3350
19 changed files with 43 additions and 40 deletions

View File

@ -10,7 +10,7 @@ type Addition struct {
Password string `json:"password" required:"true"` Password string `json:"password" required:"true"`
OrderBy string `json:"order_by" type:"select" options:"name,fileId,updateAt,createAt" default:"name"` 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"` OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
driver.RootFolderID driver.RootID
// define other // define other
StreamUpload bool `json:"stream_upload"` StreamUpload bool `json:"stream_upload"`
//Field string `json:"field" type:"select" required:"true" options:"a,b,c" default:"a"` //Field string `json:"field" type:"select" required:"true" options:"a,b,c" default:"a"`

View File

@ -6,7 +6,7 @@ import (
) )
type Addition struct { type Addition struct {
driver.RootFolderID driver.RootID
RefreshToken string `json:"refresh_token" required:"true"` RefreshToken string `json:"refresh_token" required:"true"`
OrderBy string `json:"order_by" type:"select" options:"name,size,updated_at,created_at"` OrderBy string `json:"order_by" type:"select" options:"name,size,updated_at,created_at"`
OrderDirection string `json:"order_direction" type:"select" options:"ASC,DESC"` OrderDirection string `json:"order_direction" type:"select" options:"ASC,DESC"`

View File

@ -7,7 +7,7 @@ import (
type Addition struct { type Addition struct {
RefreshToken string `json:"refresh_token" required:"true"` RefreshToken string `json:"refresh_token" required:"true"`
driver.RootFolderPath driver.RootPath
OrderBy string `json:"order_by" type:"select" options:"name,time,size" default:"name"` 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"` OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
DownloadAPI string `json:"download_api" type:"select" options:"official,crack" default:"official"` DownloadAPI string `json:"download_api" type:"select" options:"official,crack" default:"official"`

View File

@ -9,7 +9,7 @@ type Addition struct {
Address string `json:"address" required:"true"` Address string `json:"address" required:"true"`
Username string `json:"username" required:"true"` Username string `json:"username" required:"true"`
Password string `json:"password" required:"true"` Password string `json:"password" required:"true"`
driver.RootFolderPath driver.RootPath
} }
var config = driver.Config{ var config = driver.Config{

View File

@ -6,7 +6,7 @@ import (
) )
type Addition struct { type Addition struct {
driver.RootFolderID driver.RootID
RefreshToken string `json:"refresh_token" required:"true"` RefreshToken string `json:"refresh_token" required:"true"`
OrderBy string `json:"order_by" type:"string" help:"such as: folder,name,modifiedTime"` OrderBy string `json:"order_by" type:"string" help:"such as: folder,name,modifiedTime"`
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc"` OrderDirection string `json:"order_direction" type:"select" options:"asc,desc"`

View File

@ -18,7 +18,6 @@ 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/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"
@ -39,17 +38,17 @@ func (d *Local) Init(ctx context.Context, storage model.Storage) error {
if err != nil { if err != nil {
return err return err
} }
if !utils.Exists(d.RootFolder) { if !utils.Exists(d.GetRootPath()) {
err = fmt.Errorf("root folder %s not exists", d.RootFolder) err = fmt.Errorf("root folder %s not exists", d.GetRootPath())
} else { } else {
if !filepath.IsAbs(d.RootFolder) { if !filepath.IsAbs(d.GetRootPath()) {
d.RootFolder, err = filepath.Abs(d.RootFolder) abs, err := filepath.Abs(d.GetRootPath())
if err != nil { if err != nil {
return err return err
} }
d.SetRootPath(abs)
} }
} }
op.MustSaveDriverStorage(d)
return err return err
} }

View File

@ -6,7 +6,7 @@ import (
) )
type Addition struct { type Addition struct {
driver.RootFolderPath driver.RootPath
Thumbnail bool `json:"thumbnail" required:"true" help:"enable thumbnail"` Thumbnail bool `json:"thumbnail" required:"true" help:"enable thumbnail"`
} }

View File

@ -6,7 +6,7 @@ import (
) )
type Addition struct { type Addition struct {
driver.RootFolderPath driver.RootPath
Region string `json:"region" type:"select" required:"true" options:"global,cn,us,de"` Region string `json:"region" type:"select" required:"true" options:"global,cn,us,de"`
IsSharepoint bool `json:"is_sharepoint"` IsSharepoint bool `json:"is_sharepoint"`
ClientID string `json:"client_id" required:"true"` ClientID string `json:"client_id" required:"true"`

View File

@ -6,7 +6,7 @@ import (
) )
type Addition struct { type Addition struct {
driver.RootFolderID driver.RootID
Username string `json:"username" required:"true"` Username string `json:"username" required:"true"`
Password string `json:"password" required:"true"` Password string `json:"password" required:"true"`
} }

View File

@ -7,7 +7,7 @@ import (
type Addition struct { type Addition struct {
Cookie string `json:"cookie" required:"true"` 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"` 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"` OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" default:"asc"`
} }

View File

@ -6,7 +6,7 @@ import (
) )
type Addition struct { type Addition struct {
driver.RootFolderPath driver.RootPath
Bucket string `json:"bucket" required:"true"` Bucket string `json:"bucket" required:"true"`
Endpoint string `json:"endpoint" required:"true"` Endpoint string `json:"endpoint" required:"true"`
Region string `json:"region"` Region string `json:"region"`

View File

@ -10,7 +10,7 @@ type Addition struct {
Username string `json:"username" required:"true"` Username string `json:"username" required:"true"`
PrivateKey string `json:"private_key" type:"text"` PrivateKey string `json:"private_key" type:"text"`
Password string `json:"password"` Password string `json:"password"`
driver.RootFolderPath driver.RootPath
} }
var config = driver.Config{ var config = driver.Config{

View File

@ -9,7 +9,7 @@ type Addition struct {
Region string `json:"region" type:"select" options:"china,international" required:"true"` Region string `json:"region" type:"select" options:"china,international" required:"true"`
Cookie string `json:"cookie" required:"true"` Cookie string `json:"cookie" required:"true"`
ProjectID string `json:"project_id" 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"` 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"` OrderDirection string `json:"order_direction" type:"select" options:"Asc,Desc" default:"Asc"`
} }

View File

@ -7,8 +7,8 @@ import (
type Addition struct { type Addition struct {
// Usually one of two // Usually one of two
driver.RootFolderPath driver.RootPath
driver.RootFolderID driver.RootID
// define other // define other
Field string `json:"field" type:"select" required:"true" options:"a,b,c" default:"a"` Field string `json:"field" type:"select" required:"true" options:"a,b,c" default:"a"`
} }

View File

@ -6,7 +6,7 @@ import (
) )
type Addition struct { type Addition struct {
driver.RootFolderPath driver.RootPath
Bucket string `json:"bucket" required:"true"` Bucket string `json:"bucket" required:"true"`
Endpoint string `json:"endpoint" required:"true"` Endpoint string `json:"endpoint" required:"true"`
OperatorName string `json:"operator_name" required:"true"` OperatorName string `json:"operator_name" required:"true"`

View File

@ -6,7 +6,7 @@ import (
) )
type Addition struct { type Addition struct {
driver.RootFolderPath driver.RootPath
NumFile int `json:"num_file" type:"number" default:"30" required:"true"` NumFile int `json:"num_file" type:"number" default:"30" required:"true"`
NumFolder int `json:"num_folder" 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"` MaxFileSize int64 `json:"max_file_size" type:"number" default:"1073741824" required:"true"`

View File

@ -19,26 +19,30 @@ type Info struct {
Config Config `json:"config"` Config Config `json:"config"`
} }
type IRootFolderPath interface { type IRootPath interface {
GetRootFolderPath() string GetRootPath() string
} }
type IRootFolderId interface { type IRootId interface {
GetRootFolderId() string GetRootId() string
} }
type RootFolderPath struct { type RootPath struct {
RootFolder string `json:"root_folder" required:"true" help:"Root folder path"` RootFolderPath string `json:"root_folder_path" required:"true"`
} }
type RootFolderID struct { type RootID struct {
RootFolder string `json:"root_folder" required:"true" help:"Root folder id"` RootFolderID string `json:"root_folder_id" required:"true"`
} }
func (r RootFolderPath) GetRootFolderPath() string { func (r RootPath) GetRootPath() string {
return r.RootFolder return r.RootFolderPath
} }
func (r RootFolderID) GetRootFolderId() string { func (r *RootPath) SetRootPath(path string) {
return r.RootFolder r.RootFolderPath = path
}
func (r RootID) GetRootId() string {
return r.RootFolderID
} }

View File

@ -87,18 +87,18 @@ func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, er
} }
} }
// is root folder // 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{ return &model.Object{
ID: r.GetRootFolderId(), ID: r.GetRootId(),
Name: "root", Name: "root",
Size: 0, Size: 0,
Modified: storage.GetStorage().Modified, Modified: storage.GetStorage().Modified,
IsFolder: true, IsFolder: true,
}, nil }, 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{ return &model.Object{
Path: r.GetRootFolderPath(), Path: r.GetRootPath(),
Name: "root", Name: "root",
Size: 0, Size: 0,
Modified: storage.GetStorage().Modified, Modified: storage.GetStorage().Modified,

View File

@ -14,8 +14,8 @@ import (
// ActualPath Get the actual path // ActualPath Get the actual path
// !!! maybe and \ in the path when use windows local // !!! maybe and \ in the path when use windows local
func ActualPath(storage driver.Additional, rawPath string) string { func ActualPath(storage driver.Additional, rawPath string) string {
if i, ok := storage.(driver.IRootFolderPath); ok { if i, ok := storage.(driver.IRootPath); ok {
rawPath = stdpath.Join(i.GetRootFolderPath(), rawPath) rawPath = stdpath.Join(i.GetRootPath(), rawPath)
} }
return utils.StandardizePath(rawPath) return utils.StandardizePath(rawPath)
} }