Skip to content

Commit 5db2172

Browse files
x-spyxrgzs
andauthored
feat(driver): add personal / business wps drive support (#1802)
* feat(driver): add wps drive support * feat(driver): add wps drive support * fix(wps): update personal mode string to English Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> * fix(wps): remove trailing slash from drive origin URL Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> * fix(wps): correct order of options in mode selection Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> * fix(wps): enable local sort and upload overwrite Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> * fix(wps): resolve put bugs, fix file op problems and optimize list logic - Fix uploading bugs. Support all uploading methods based on 8825.85d3c864.js - Fix issues in delete/copy/move while opearting big folders. - Use cache to optimize performance of list, especially in a deep path. --------- Signed-off-by: MadDogOwner <xiaoran@xrgzs.top> Co-authored-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent c4c121b commit 5db2172

File tree

5 files changed

+1248
-0
lines changed

5 files changed

+1248
-0
lines changed

drivers/all.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import (
7878
_ "github.com/OpenListTeam/OpenList/v4/drivers/webdav"
7979
_ "github.com/OpenListTeam/OpenList/v4/drivers/weiyun"
8080
_ "github.com/OpenListTeam/OpenList/v4/drivers/wopan"
81+
_ "github.com/OpenListTeam/OpenList/v4/drivers/wps"
8182
_ "github.com/OpenListTeam/OpenList/v4/drivers/yandex_disk"
8283
)
8384

drivers/wps/driver.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package wps
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/OpenListTeam/OpenList/v4/internal/driver"
8+
"github.com/OpenListTeam/OpenList/v4/internal/errs"
9+
"github.com/OpenListTeam/OpenList/v4/internal/model"
10+
)
11+
12+
type Wps struct {
13+
model.Storage
14+
Addition
15+
companyID string
16+
}
17+
18+
func (d *Wps) Config() driver.Config {
19+
return config
20+
}
21+
22+
func (d *Wps) GetAddition() driver.Additional {
23+
return &d.Addition
24+
}
25+
26+
func (d *Wps) Init(ctx context.Context) error {
27+
if d.Cookie == "" {
28+
return fmt.Errorf("cookie is empty")
29+
}
30+
return d.ensureCompanyID(ctx)
31+
}
32+
33+
func (d *Wps) Drop(ctx context.Context) error {
34+
return nil
35+
}
36+
37+
func (d *Wps) List(ctx context.Context, dir model.Obj, _ model.ListArgs) ([]model.Obj, error) {
38+
basePath := "/"
39+
if dir != nil {
40+
if p := dir.GetPath(); p != "" {
41+
basePath = p
42+
}
43+
}
44+
return d.list(ctx, basePath)
45+
}
46+
47+
func (d *Wps) Link(ctx context.Context, file model.Obj, _ model.LinkArgs) (*model.Link, error) {
48+
if file == nil {
49+
return nil, errs.NotSupport
50+
}
51+
return d.link(ctx, file.GetPath())
52+
}
53+
54+
func (d *Wps) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
55+
return d.makeDir(ctx, parentDir, dirName)
56+
}
57+
58+
func (d *Wps) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
59+
return d.move(ctx, srcObj, dstDir)
60+
}
61+
62+
func (d *Wps) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
63+
return d.rename(ctx, srcObj, newName)
64+
}
65+
66+
func (d *Wps) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
67+
return d.copy(ctx, srcObj, dstDir)
68+
}
69+
70+
func (d *Wps) Remove(ctx context.Context, obj model.Obj) error {
71+
return d.remove(ctx, obj)
72+
}
73+
74+
func (d *Wps) Put(ctx context.Context, dstDir model.Obj, file model.FileStreamer, up driver.UpdateProgress) error {
75+
return d.put(ctx, dstDir, file, up)
76+
}
77+
78+
var _ driver.Driver = (*Wps)(nil)

drivers/wps/meta.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package wps
2+
3+
import (
4+
"github.com/OpenListTeam/OpenList/v4/internal/driver"
5+
"github.com/OpenListTeam/OpenList/v4/internal/op"
6+
)
7+
8+
type Addition struct {
9+
driver.RootPath
10+
Cookie string `json:"cookie" required:"true" type:"text"`
11+
Mode string `json:"mode" type:"select" options:"Personal,Business" default:"Business"`
12+
}
13+
14+
var config = driver.Config{
15+
Name: "WPS",
16+
LocalSort: true,
17+
DefaultRoot: "/",
18+
Alert: "",
19+
NoOverwriteUpload: true,
20+
}
21+
22+
func init() {
23+
op.RegisterDriver(func() driver.Driver {
24+
return &Wps{}
25+
})
26+
}

drivers/wps/types.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package wps
2+
3+
import (
4+
"time"
5+
6+
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
7+
)
8+
9+
type workspaceResp struct {
10+
Companies []struct {
11+
ID int64 `json:"id"`
12+
} `json:"companies"`
13+
}
14+
15+
type Group struct {
16+
CompanyID int64 `json:"company_id"`
17+
GroupID int64 `json:"group_id"`
18+
Name string `json:"name"`
19+
Type string `json:"type"`
20+
}
21+
22+
type groupsResp struct {
23+
Groups []Group `json:"groups"`
24+
}
25+
26+
type filePerms struct {
27+
Download int `json:"download"`
28+
}
29+
30+
type FileInfo struct {
31+
GroupID int64 `json:"groupid"`
32+
ParentID int64 `json:"parentid"`
33+
Name string `json:"fname"`
34+
Size int64 `json:"fsize"`
35+
Type string `json:"ftype"`
36+
Ctime int64 `json:"ctime"`
37+
Mtime int64 `json:"mtime"`
38+
ID int64 `json:"id"`
39+
Deleted bool `json:"deleted"`
40+
FilePerms filePerms `json:"file_perms_acl"`
41+
}
42+
43+
type filesResp struct {
44+
Files []FileInfo `json:"files"`
45+
}
46+
47+
type downloadResp struct {
48+
URL string `json:"url"`
49+
Result string `json:"result"`
50+
}
51+
52+
type Obj struct {
53+
id string
54+
name string
55+
size int64
56+
ctime time.Time
57+
mtime time.Time
58+
isDir bool
59+
hash utils.HashInfo
60+
path string
61+
canDownload bool
62+
}
63+
64+
func (o *Obj) GetSize() int64 {
65+
return o.size
66+
}
67+
68+
func (o *Obj) GetName() string {
69+
return o.name
70+
}
71+
72+
func (o *Obj) ModTime() time.Time {
73+
return o.mtime
74+
}
75+
76+
func (o *Obj) CreateTime() time.Time {
77+
return o.ctime
78+
}
79+
80+
func (o *Obj) IsDir() bool {
81+
return o.isDir
82+
}
83+
84+
func (o *Obj) GetHash() utils.HashInfo {
85+
return o.hash
86+
}
87+
88+
func (o *Obj) GetID() string {
89+
return o.id
90+
}
91+
92+
func (o *Obj) GetPath() string {
93+
return o.path
94+
}

0 commit comments

Comments
 (0)