-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package alist_v2 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/alist-org/alist/v3/drivers/base" | ||
"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/utils" | ||
"github.com/alist-org/alist/v3/server/common" | ||
) | ||
|
||
type AListV2 struct { | ||
model.Storage | ||
Addition | ||
} | ||
|
||
func (d *AListV2) Config() driver.Config { | ||
return config | ||
} | ||
|
||
func (d *AListV2) GetAddition() driver.Additional { | ||
return d.Addition | ||
} | ||
|
||
func (d *AListV2) Init(ctx context.Context, storage model.Storage) error { | ||
d.Storage = storage | ||
err := utils.Json.UnmarshalFromString(d.Storage.Addition, &d.Addition) | ||
if err != nil { | ||
return err | ||
} | ||
// TODO login / refresh token | ||
//op.MustSaveDriverStorage(d) | ||
return err | ||
} | ||
|
||
func (d *AListV2) Drop(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
func (d *AListV2) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) { | ||
url := d.Address + "/api/public/path" | ||
var resp common.Resp[PathResp] | ||
_, err := base.RestyClient.R(). | ||
SetResult(&resp). | ||
SetHeader("Authorization", d.AccessToken). | ||
SetBody(PathReq{ | ||
PageNum: 0, | ||
PageSize: 0, | ||
Path: dir.GetPath(), | ||
Password: d.Password, | ||
}).Post(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var files []model.Obj | ||
for _, f := range resp.Data.Files { | ||
file := model.ObjThumb{ | ||
Object: model.Object{ | ||
Name: f.Name, | ||
Modified: *f.UpdatedAt, | ||
Size: f.Size, | ||
IsFolder: f.Type == 1, | ||
}, | ||
Thumbnail: model.Thumbnail{Thumbnail: f.Thumbnail}, | ||
} | ||
files = append(files, &file) | ||
} | ||
return files, nil | ||
} | ||
|
||
//func (d *AList) Get(ctx context.Context, path string) (model.Obj, error) { | ||
// // this is optional | ||
// return nil, errs.NotImplement | ||
//} | ||
|
||
func (d *AListV2) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) { | ||
url := d.Address + "/api/public/path" | ||
var resp common.Resp[PathResp] | ||
_, err := base.RestyClient.R(). | ||
SetResult(&resp). | ||
SetHeader("Authorization", d.AccessToken). | ||
SetBody(PathReq{ | ||
PageNum: 0, | ||
PageSize: 0, | ||
Path: file.GetPath(), | ||
Password: d.Password, | ||
}).Post(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &model.Link{ | ||
URL: resp.Data.Files[0].Url, | ||
}, nil | ||
} | ||
|
||
func (d *AListV2) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error { | ||
return errs.NotImplement | ||
} | ||
|
||
func (d *AListV2) Move(ctx context.Context, srcObj, dstDir model.Obj) error { | ||
return errs.NotImplement | ||
} | ||
|
||
func (d *AListV2) Rename(ctx context.Context, srcObj model.Obj, newName string) error { | ||
return errs.NotImplement | ||
} | ||
|
||
func (d *AListV2) Copy(ctx context.Context, srcObj, dstDir model.Obj) error { | ||
return errs.NotImplement | ||
} | ||
|
||
func (d *AListV2) Remove(ctx context.Context, obj model.Obj) error { | ||
return errs.NotImplement | ||
} | ||
|
||
func (d *AListV2) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error { | ||
return errs.NotImplement | ||
} | ||
|
||
//func (d *AList) Other(ctx context.Context, args model.OtherArgs) (interface{}, error) { | ||
// return nil, errs.NotSupport | ||
//} | ||
|
||
var _ driver.Driver = (*AListV2)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package alist_v2 | ||
|
||
import ( | ||
"github.com/alist-org/alist/v3/internal/driver" | ||
"github.com/alist-org/alist/v3/internal/op" | ||
) | ||
|
||
type Addition struct { | ||
driver.RootPath | ||
Address string `json:"url" required:"true"` | ||
Password string `json:"password"` | ||
AccessToken string `json:"access_token"` | ||
} | ||
|
||
var config = driver.Config{ | ||
Name: "AList V2", | ||
LocalSort: true, | ||
NoUpload: true, | ||
DefaultRoot: "/", | ||
} | ||
|
||
func init() { | ||
op.RegisterDriver(config, func() driver.Driver { | ||
return &AListV2{} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package alist_v2 | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type File struct { | ||
Id string `json:"-"` | ||
Name string `json:"name"` | ||
Size int64 `json:"size"` | ||
Type int `json:"type"` | ||
Driver string `json:"driver"` | ||
UpdatedAt *time.Time `json:"updated_at"` | ||
Thumbnail string `json:"thumbnail"` | ||
Url string `json:"url"` | ||
SizeStr string `json:"size_str"` | ||
TimeStr string `json:"time_str"` | ||
} | ||
|
||
type PathResp struct { | ||
Type string `json:"type"` | ||
//Meta Meta `json:"meta"` | ||
Files []File `json:"files"` | ||
} | ||
|
||
type PathReq struct { | ||
PageNum int `json:"page_num"` | ||
PageSize int `json:"page_size"` | ||
Password string `json:"password"` | ||
Path string `json:"path"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package alist_v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters