Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/drivers/alist_v2/driver.go
1986 views
1
package alist_v2
2
3
import (
4
"context"
5
6
"github.com/alist-org/alist/v3/drivers/base"
7
"github.com/alist-org/alist/v3/internal/driver"
8
"github.com/alist-org/alist/v3/internal/errs"
9
"github.com/alist-org/alist/v3/internal/model"
10
"github.com/alist-org/alist/v3/server/common"
11
)
12
13
type AListV2 struct {
14
model.Storage
15
Addition
16
}
17
18
func (d *AListV2) Config() driver.Config {
19
return config
20
}
21
22
func (d *AListV2) GetAddition() driver.Additional {
23
return &d.Addition
24
}
25
26
func (d *AListV2) Init(ctx context.Context) error {
27
if len(d.Addition.Address) > 0 && string(d.Addition.Address[len(d.Addition.Address)-1]) == "/" {
28
d.Addition.Address = d.Addition.Address[0 : len(d.Addition.Address)-1]
29
}
30
// TODO login / refresh token
31
//op.MustSaveDriverStorage(d)
32
return nil
33
}
34
35
func (d *AListV2) Drop(ctx context.Context) error {
36
return nil
37
}
38
39
func (d *AListV2) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
40
url := d.Address + "/api/public/path"
41
var resp common.Resp[PathResp]
42
_, err := base.RestyClient.R().
43
SetResult(&resp).
44
SetHeader("Authorization", d.AccessToken).
45
SetBody(PathReq{
46
PageNum: 0,
47
PageSize: 0,
48
Path: dir.GetPath(),
49
Password: d.Password,
50
}).Post(url)
51
if err != nil {
52
return nil, err
53
}
54
var files []model.Obj
55
for _, f := range resp.Data.Files {
56
file := model.ObjThumb{
57
Object: model.Object{
58
Name: f.Name,
59
Modified: *f.UpdatedAt,
60
Size: f.Size,
61
IsFolder: f.Type == 1,
62
},
63
Thumbnail: model.Thumbnail{Thumbnail: f.Thumbnail},
64
}
65
files = append(files, &file)
66
}
67
return files, nil
68
}
69
70
func (d *AListV2) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
71
url := d.Address + "/api/public/path"
72
var resp common.Resp[PathResp]
73
_, err := base.RestyClient.R().
74
SetResult(&resp).
75
SetHeader("Authorization", d.AccessToken).
76
SetBody(PathReq{
77
PageNum: 0,
78
PageSize: 0,
79
Path: file.GetPath(),
80
Password: d.Password,
81
}).Post(url)
82
if err != nil {
83
return nil, err
84
}
85
return &model.Link{
86
URL: resp.Data.Files[0].Url,
87
}, nil
88
}
89
90
func (d *AListV2) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
91
return errs.NotImplement
92
}
93
94
func (d *AListV2) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
95
return errs.NotImplement
96
}
97
98
func (d *AListV2) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
99
return errs.NotImplement
100
}
101
102
func (d *AListV2) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
103
return errs.NotImplement
104
}
105
106
func (d *AListV2) Remove(ctx context.Context, obj model.Obj) error {
107
return errs.NotImplement
108
}
109
110
func (d *AListV2) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
111
return errs.NotImplement
112
}
113
114
//func (d *AList) Other(ctx context.Context, args model.OtherArgs) (interface{}, error) {
115
// return nil, errs.NotSupport
116
//}
117
118
var _ driver.Driver = (*AListV2)(nil)
119
120