@@ -5,12 +5,14 @@ import (
5
5
"fmt"
6
6
"io"
7
7
"net/http"
8
+ "net/url"
8
9
"path"
9
10
"strings"
10
11
11
12
"github.com/alist-org/alist/v3/drivers/base"
12
13
"github.com/alist-org/alist/v3/internal/conf"
13
14
"github.com/alist-org/alist/v3/internal/driver"
15
+ "github.com/alist-org/alist/v3/internal/errs"
14
16
"github.com/alist-org/alist/v3/internal/model"
15
17
"github.com/alist-org/alist/v3/pkg/utils"
16
18
"github.com/alist-org/alist/v3/server/common"
@@ -34,7 +36,7 @@ func (d *AListV3) GetAddition() driver.Additional {
34
36
func (d * AListV3 ) Init (ctx context.Context ) error {
35
37
d .Addition .Address = strings .TrimSuffix (d .Addition .Address , "/" )
36
38
var resp common.Resp [MeResp ]
37
- _ , err := d .request ("/me" , http .MethodGet , func (req * resty.Request ) {
39
+ _ , _ , err := d .request ("/me" , http .MethodGet , func (req * resty.Request ) {
38
40
req .SetResult (& resp )
39
41
})
40
42
if err != nil {
@@ -48,15 +50,15 @@ func (d *AListV3) Init(ctx context.Context) error {
48
50
}
49
51
}
50
52
// re-get the user info
51
- _ , err = d .request ("/me" , http .MethodGet , func (req * resty.Request ) {
53
+ _ , _ , err = d .request ("/me" , http .MethodGet , func (req * resty.Request ) {
52
54
req .SetResult (& resp )
53
55
})
54
56
if err != nil {
55
57
return err
56
58
}
57
59
if resp .Data .Role == model .GUEST {
58
- url := d .Address + "/api/public/settings"
59
- res , err := base .RestyClient .R ().Get (url )
60
+ u := d .Address + "/api/public/settings"
61
+ res , err := base .RestyClient .R ().Get (u )
60
62
if err != nil {
61
63
return err
62
64
}
@@ -74,7 +76,7 @@ func (d *AListV3) Drop(ctx context.Context) error {
74
76
75
77
func (d * AListV3 ) List (ctx context.Context , dir model.Obj , args model.ListArgs ) ([]model.Obj , error ) {
76
78
var resp common.Resp [FsListResp ]
77
- _ , err := d .request ("/fs/list" , http .MethodPost , func (req * resty.Request ) {
79
+ _ , _ , err := d .request ("/fs/list" , http .MethodPost , func (req * resty.Request ) {
78
80
req .SetResult (& resp ).SetBody (ListReq {
79
81
PageReq : model.PageReq {
80
82
Page : 1 ,
@@ -116,7 +118,7 @@ func (d *AListV3) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
116
118
userAgent = base .UserAgent
117
119
}
118
120
}
119
- _ , err := d .request ("/fs/get" , http .MethodPost , func (req * resty.Request ) {
121
+ _ , _ , err := d .request ("/fs/get" , http .MethodPost , func (req * resty.Request ) {
120
122
req .SetResult (& resp ).SetBody (FsGetReq {
121
123
Path : file .GetPath (),
122
124
Password : d .MetaPassword ,
@@ -131,7 +133,7 @@ func (d *AListV3) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
131
133
}
132
134
133
135
func (d * AListV3 ) MakeDir (ctx context.Context , parentDir model.Obj , dirName string ) error {
134
- _ , err := d .request ("/fs/mkdir" , http .MethodPost , func (req * resty.Request ) {
136
+ _ , _ , err := d .request ("/fs/mkdir" , http .MethodPost , func (req * resty.Request ) {
135
137
req .SetBody (MkdirOrLinkReq {
136
138
Path : path .Join (parentDir .GetPath (), dirName ),
137
139
})
@@ -140,7 +142,7 @@ func (d *AListV3) MakeDir(ctx context.Context, parentDir model.Obj, dirName stri
140
142
}
141
143
142
144
func (d * AListV3 ) Move (ctx context.Context , srcObj , dstDir model.Obj ) error {
143
- _ , err := d .request ("/fs/move" , http .MethodPost , func (req * resty.Request ) {
145
+ _ , _ , err := d .request ("/fs/move" , http .MethodPost , func (req * resty.Request ) {
144
146
req .SetBody (MoveCopyReq {
145
147
SrcDir : path .Dir (srcObj .GetPath ()),
146
148
DstDir : dstDir .GetPath (),
@@ -151,7 +153,7 @@ func (d *AListV3) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
151
153
}
152
154
153
155
func (d * AListV3 ) Rename (ctx context.Context , srcObj model.Obj , newName string ) error {
154
- _ , err := d .request ("/fs/rename" , http .MethodPost , func (req * resty.Request ) {
156
+ _ , _ , err := d .request ("/fs/rename" , http .MethodPost , func (req * resty.Request ) {
155
157
req .SetBody (RenameReq {
156
158
Path : srcObj .GetPath (),
157
159
Name : newName ,
@@ -161,7 +163,7 @@ func (d *AListV3) Rename(ctx context.Context, srcObj model.Obj, newName string)
161
163
}
162
164
163
165
func (d * AListV3 ) Copy (ctx context.Context , srcObj , dstDir model.Obj ) error {
164
- _ , err := d .request ("/fs/copy" , http .MethodPost , func (req * resty.Request ) {
166
+ _ , _ , err := d .request ("/fs/copy" , http .MethodPost , func (req * resty.Request ) {
165
167
req .SetBody (MoveCopyReq {
166
168
SrcDir : path .Dir (srcObj .GetPath ()),
167
169
DstDir : dstDir .GetPath (),
@@ -172,7 +174,7 @@ func (d *AListV3) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
172
174
}
173
175
174
176
func (d * AListV3 ) Remove (ctx context.Context , obj model.Obj ) error {
175
- _ , err := d .request ("/fs/remove" , http .MethodPost , func (req * resty.Request ) {
177
+ _ , _ , err := d .request ("/fs/remove" , http .MethodPost , func (req * resty.Request ) {
176
178
req .SetBody (RemoveReq {
177
179
Dir : path .Dir (obj .GetPath ()),
178
180
Names : []string {obj .GetName ()},
@@ -232,6 +234,127 @@ func (d *AListV3) Put(ctx context.Context, dstDir model.Obj, s model.FileStreame
232
234
return nil
233
235
}
234
236
237
+ func (d * AListV3 ) GetArchiveMeta (ctx context.Context , obj model.Obj , args model.ArchiveArgs ) (model.ArchiveMeta , error ) {
238
+ if ! d .ForwardArchiveReq {
239
+ return nil , errs .NotImplement
240
+ }
241
+ var resp common.Resp [ArchiveMetaResp ]
242
+ _ , code , err := d .request ("/fs/archive/meta" , http .MethodPost , func (req * resty.Request ) {
243
+ req .SetResult (& resp ).SetBody (ArchiveMetaReq {
244
+ ArchivePass : args .Password ,
245
+ Password : d .MetaPassword ,
246
+ Path : obj .GetPath (),
247
+ Refresh : false ,
248
+ })
249
+ })
250
+ if code == 202 {
251
+ return nil , errs .WrongArchivePassword
252
+ }
253
+ if err != nil {
254
+ return nil , err
255
+ }
256
+ var tree []model.ObjTree
257
+ if resp .Data .Content != nil {
258
+ tree = make ([]model.ObjTree , 0 , len (resp .Data .Content ))
259
+ for _ , content := range resp .Data .Content {
260
+ tree = append (tree , & content )
261
+ }
262
+ }
263
+ return & model.ArchiveMetaInfo {
264
+ Comment : resp .Data .Comment ,
265
+ Encrypted : resp .Data .Encrypted ,
266
+ Tree : tree ,
267
+ }, nil
268
+ }
269
+
270
+ func (d * AListV3 ) ListArchive (ctx context.Context , obj model.Obj , args model.ArchiveInnerArgs ) ([]model.Obj , error ) {
271
+ if ! d .ForwardArchiveReq {
272
+ return nil , errs .NotImplement
273
+ }
274
+ var resp common.Resp [ArchiveListResp ]
275
+ _ , code , err := d .request ("/fs/archive/list" , http .MethodPost , func (req * resty.Request ) {
276
+ req .SetResult (& resp ).SetBody (ArchiveListReq {
277
+ ArchiveMetaReq : ArchiveMetaReq {
278
+ ArchivePass : args .Password ,
279
+ Password : d .MetaPassword ,
280
+ Path : obj .GetPath (),
281
+ Refresh : false ,
282
+ },
283
+ PageReq : model.PageReq {
284
+ Page : 1 ,
285
+ PerPage : 0 ,
286
+ },
287
+ InnerPath : args .InnerPath ,
288
+ })
289
+ })
290
+ if code == 202 {
291
+ return nil , errs .WrongArchivePassword
292
+ }
293
+ if err != nil {
294
+ return nil , err
295
+ }
296
+ var files []model.Obj
297
+ for _ , f := range resp .Data .Content {
298
+ file := model.ObjThumb {
299
+ Object : model.Object {
300
+ Name : f .Name ,
301
+ Modified : f .Modified ,
302
+ Ctime : f .Created ,
303
+ Size : f .Size ,
304
+ IsFolder : f .IsDir ,
305
+ HashInfo : utils .FromString (f .HashInfo ),
306
+ },
307
+ Thumbnail : model.Thumbnail {Thumbnail : f .Thumb },
308
+ }
309
+ files = append (files , & file )
310
+ }
311
+ return files , nil
312
+ }
313
+
314
+ func (d * AListV3 ) Extract (ctx context.Context , obj model.Obj , args model.ArchiveInnerArgs ) (* model.Link , error ) {
315
+ if ! d .ForwardArchiveReq {
316
+ return nil , errs .NotSupport
F438
span>
317
+ }
318
+ var resp common.Resp [ArchiveMetaResp ]
319
+ _ , _ , err := d .request ("/fs/archive/meta" , http .MethodPost , func (req * resty.Request ) {
320
+ req .SetResult (& resp ).SetBody (ArchiveMetaReq {
321
+ ArchivePass : args .Password ,
322
+ Password : d .MetaPassword ,
323
+ Path : obj .GetPath (),
324
+ Refresh : false ,
325
+ })
326
+ })
327
+ if err != nil {
328
+ return nil , err
329
+ }
330
+ return & model.Link {
331
+ URL : fmt .Sprintf ("%s?inner=%s&pass=%s&sign=%s" ,
332
+ resp .Data .RawURL ,
333
+ utils .EncodePath (args .InnerPath , true ),
334
+ url .QueryEscape (args .Password ),
335
+ resp .Data .Sign ),
336
+ }, nil
337
+ }
338
+
339
+ func (d * AListV3 ) ArchiveDecompress (ctx context.Context , srcObj , dstDir model.Obj , args model.ArchiveDecompressArgs ) error {
340
+ if ! d .ForwardArchiveReq {
341
+ return errs .NotImplement
342
+ }
343
+ dir , name := path .Split (srcObj .GetPath ())
344
+ _ , _ , err := d .request ("/fs/archive/decompress" , http .MethodPost , func (req * resty.Request ) {
345
+ req .SetBody (DecompressReq {
346
+ ArchivePass : args .Password ,
347
+ CacheFull : args .CacheFull ,
348
+ DstDir : dstDir .GetPath (),
349
+ InnerPath : args .InnerPath ,
350
+ Name : []string {name },
351
+ PutIntoNewDir : args .PutIntoNewDir ,
352
+ SrcDir : dir ,
353
+ })
354
+ })
355
+ return err
356
+ }
357
+
235
358
//func (d *AList) Other(ctx context.Context, args model.OtherArgs) (interface{}, error) {
236
359
// return nil, errs.NotSupport
237
360
//}
0 commit comments