Skip to content

Commit ee5238c

Browse files
committed
feat(115_share): support 115_share
1 parent ce11f78 commit ee5238c

File tree

2 files changed

+50
-29
lines changed

2 files changed

+50
-29
lines changed

drivers/115_share/driver.go

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package _115_share
33
import (
44
"context"
55

6+
"github.com/OpenListTeam/OpenList/v4/drivers/virtual_file"
67
"github.com/OpenListTeam/OpenList/v4/internal/driver"
78
"github.com/OpenListTeam/OpenList/v4/internal/errs"
89
"github.com/OpenListTeam/OpenList/v4/internal/model"
@@ -46,38 +47,54 @@ func (d *Pan115Share) Drop(ctx context.Context) error {
4647
}
4748

4849
func (d *Pan115Share) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
49-
if err := d.WaitLimit(ctx); err != nil {
50-
return nil, err
51-
}
5250

53-
files := make([]driver115.ShareFile, 0)
54-
fileResp, err := d.client.GetShareSnap(d.ShareCode, d.ReceiveCode, dir.GetID(), driver115.QueryLimit(int(d.PageSize)))
55-
if err != nil {
56-
return nil, err
57-
}
58-
files = append(files, fileResp.Data.List...)
59-
total := fileResp.Data.Count
60-
count := len(fileResp.Data.List)
61-
for total > count {
62-
fileResp, err := d.client.GetShareSnap(
63-
d.ShareCode, d.ReceiveCode, dir.GetID(),
64-
driver115.QueryLimit(int(d.PageSize)), driver115.QueryOffset(count),
65-
)
51+
return virtual_file.List(d.ID, dir, func(virtualFile model.VirtualFile, dir model.Obj) ([]model.Obj, error) {
52+
53+
if err := d.WaitLimit(ctx); err != nil {
54+
return nil, err
55+
}
56+
57+
parentId := ""
58+
if virDir, ok := dir.(*model.ObjVirtualDir); ok {
59+
parentId = virDir.VirtualFile.ParentDir
60+
} else {
61+
parentId = dir.GetID()
62+
}
63+
64+
files := make([]driver115.ShareFile, 0)
65+
fileResp, err := d.client.GetShareSnap(virtualFile.ShareID, virtualFile.SharePwd, parentId, driver115.QueryLimit(int(d.PageSize)))
6666
if err != nil {
6767
return nil, err
6868
}
6969
files = append(files, fileResp.Data.List...)
70-
count += len(fileResp.Data.List)
71-
}
70+
total := fileResp.Data.Count
71+
count := len(fileResp.Data.List)
72+
for total > count {
73+
fileResp, err := d.client.GetShareSnap(
74+
virtualFile.ShareID, virtualFile.SharePwd, dir.GetID(),
75+
driver115.QueryLimit(int(d.PageSize)), driver115.QueryOffset(count),
76+
)
77+
if err != nil {
78+
return nil, err
79+
}
80+
files = append(files, fileResp.Data.List...)
81+
count += len(fileResp.Data.List)
82+
}
83+
84+
return utils.SliceConvert(files, func(src driver115.ShareFile) (model.Obj, error) {
85+
return transFunc(dir, src)
86+
})
87+
})
7288

73-
return utils.SliceConvert(files, transFunc)
7489
}
7590

7691
func (d *Pan115Share) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
7792
if err := d.WaitLimit(ctx); err != nil {
7893
return nil, err
7994
}
80-
downloadInfo, err := d.client.DownloadByShareCode(d.ShareCode, d.ReceiveCode, file.GetID())
95+
96+
virtualFile := virtual_file.GetSubscription(d.ID, file.GetPath())
97+
downloadInfo, err := d.client.DownloadByShareCode(virtualFile.ShareID, virtualFile.SharePwd, file.GetID())
8198
if err != nil {
8299
return nil, err
83100
}
@@ -86,27 +103,31 @@ func (d *Pan115Share) Link(ctx context.Context, file model.Obj, args model.LinkA
86103
}
87104

88105
func (d *Pan115Share) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
89-
return errs.NotSupport
106+
return virtual_file.MakeDir(d.ID, parentDir, dirName)
90107
}
91108

92109
func (d *Pan115Share) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
93-
return errs.NotSupport
110+
return virtual_file.Move(d.ID, srcObj, dstDir)
94111
}
95112

96113
func (d *Pan115Share) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
97-
return errs.NotSupport
114+
return virtual_file.Rename(d.ID, srcObj, newName)
98115
}
99116

100117
func (d *Pan115Share) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
101118
return errs.NotSupport
102119
}
103120

104121
func (d *Pan115Share) Remove(ctx context.Context, obj model.Obj) error {
105-
return errs.NotSupport
122+
return virtual_file.DeleteVirtualFile(d.ID, obj)
106123
}
107124

108125
func (d *Pan115Share) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
109126
return errs.NotSupport
110127
}
111128

129+
func (d *Pan115Share) MkdirConfig() []driver.Item {
130+
return virtual_file.GetMkdirConfig()
131+
}
132+
112133
var _ driver.Driver = (*Pan115Share)(nil)

drivers/115_share/utils.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package _115_share
22

33
import (
44
"fmt"
5+
"path/filepath"
56
"strconv"
67
"time"
78

@@ -20,6 +21,7 @@ type FileObj struct {
2021
FileName string
2122
isDir bool
2223
FileID string
24+
Path string
2325
}
2426

2527
func (f *FileObj) CreateTime() time.Time {
@@ -51,10 +53,10 @@ func (f *FileObj) GetID() string {
5153
}
5254

5355
func (f *FileObj) GetPath() string {
54-
return ""
56+
return f.Path
5557
}
5658

57-
func transFunc(sf driver115.ShareFile) (model.Obj, error) {
59+
func transFunc(parent model.Obj, sf driver115.ShareFile) (model.Obj, error) {
5860
timeInt, err := strconv.ParseInt(sf.UpdateTime, 10, 64)
5961
if err != nil {
6062
return nil, err
@@ -74,6 +76,7 @@ func transFunc(sf driver115.ShareFile) (model.Obj, error) {
7476
FileName: string(sf.FileName),
7577
isDir: isDir,
7678
FileID: fileID,
79+
Path: filepath.Join(parent.GetPath(), sf.FileID),
7780
}, nil
7881
}
7982

@@ -85,9 +88,6 @@ func (d *Pan115Share) login() error {
8588
driver115.UA(UserAgent),
8689
}
8790
d.client = driver115.New(opts...)
88-
if _, err := d.client.GetShareSnap(d.ShareCode, d.ReceiveCode, ""); err != nil {
89-
return errors.Wrap(err, "failed to get share snap")
90-
}
9191
cr := &driver115.Credential{}
9292
if d.QRCodeToken != "" {
9393
s := &driver115.QRCodeSession{

0 commit comments

Comments
 (0)