Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import (
_ "github.com/OpenListTeam/OpenList/v4/drivers/webdav"
_ "github.com/OpenListTeam/OpenList/v4/drivers/weiyun"
_ "github.com/OpenListTeam/OpenList/v4/drivers/wopan"
_ "github.com/OpenListTeam/OpenList/v4/drivers/wps"
_ "github.com/OpenListTeam/OpenList/v4/drivers/yandex_disk"
)

Expand Down
78 changes: 78 additions & 0 deletions drivers/wps/driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package wps

import (
"context"
"fmt"

"github.com/OpenListTeam/OpenList/v4/internal/driver"
"github.com/OpenListTeam/OpenList/v4/internal/errs"
"github.com/OpenListTeam/OpenList/v4/internal/model"
)

type Wps struct {
model.Storage
Addition
companyID string
}

func (d *Wps) Config() driver.Config {
return config
}

func (d *Wps) GetAddition() driver.Additional {
return &d.Addition
}

func (d *Wps) Init(ctx context.Context) error {
if d.Cookie == "" {
return fmt.Errorf("cookie is empty")
}
return d.ensureCompanyID(ctx)
}

func (d *Wps) Drop(ctx context.Context) error {
return nil
}

func (d *Wps) List(ctx context.Context, dir model.Obj, _ model.ListArgs) ([]model.Obj, error) {
basePath := "/"
if dir != nil {
if p := dir.GetPath(); p != "" {
basePath = p
}
}
return d.list(ctx, basePath)
}

func (d *Wps) Link(ctx context.Context, file model.Obj, _ model.LinkArgs) (*model.Link, error) {
if file == nil {
return nil, errs.NotSupport
}
return d.link(ctx, file.GetPath())
}

func (d *Wps) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
return d.makeDir(ctx, parentDir, dirName)
}

func (d *Wps) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
return d.move(ctx, srcObj, dstDir)
}

func (d *Wps) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
return d.rename(ctx, srcObj, newName)
}

func (d *Wps) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
return d.copy(ctx, srcObj, dstDir)
}

func (d *Wps) Remove(ctx context.Context, obj model.Obj) error {
return d.remove(ctx, obj)
}

func (d *Wps) Put(ctx context.Context, dstDir model.Obj, file model.FileStreamer, up driver.UpdateProgress) error {
return d.put(ctx, dstDir, file, up)
}

var _ driver.Driver = (*Wps)(nil)
26 changes: 26 additions & 0 deletions drivers/wps/meta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package wps

import (
"github.com/OpenListTeam/OpenList/v4/internal/driver"
"github.com/OpenListTeam/OpenList/v4/internal/op"
)

type Addition struct {
driver.RootPath
Cookie string `json:"cookie" required:"true" type:"text"`
Mode string `json:"mode" type:"select" options:"Personal,Business" default:"Business"`
}

var config = driver.Config{
Name: "WPS",
LocalSort: true,
DefaultRoot: "/",
Alert: "",
NoOverwriteUpload: true,
}

func init() {
op.RegisterDriver(func() driver.Driver {
return &Wps{}
})
}
94 changes: 94 additions & 0 deletions drivers/wps/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package wps

import (
"time"

"github.com/OpenListTeam/OpenList/v4/pkg/utils"
)

type workspaceResp struct {
Companies []struct {
ID int64 `json:"id"`
} `json:"companies"`
}

type Group struct {
CompanyID int64 `json:"company_id"`
GroupID int64 `json:"group_id"`
Name string `json:"name"`
Type string `json:"type"`
}

type groupsResp struct {
Groups []Group `json:"groups"`
}

type filePerms struct {
Download int `json:"download"`
}

type FileInfo struct {
GroupID int64 `json:"groupid"`
ParentID int64 `json:"parentid"`
Name string `json:"fname"`
Size int64 `json:"fsize"`
Type string `json:"ftype"`
Ctime int64 `json:"ctime"`
Mtime int64 `json:"mtime"`
ID int64 `json:"id"`
Deleted bool `json:"deleted"`
FilePerms filePerms `json:"file_perms_acl"`
}

type filesResp struct {
Files []FileInfo `json:"files"`
}

type downloadResp struct {
URL string `json:"url"`
Result string `json:"result"`
}

type Obj struct {
id string
name string
size int64
ctime time.Time
mtime time.Time
isDir bool
hash utils.HashInfo
path string
canDownload bool
}

func (o *Obj) GetSize() int64 {
return o.size
}

func (o *Obj) GetName() string {
return o.name
}

func (o *Obj) ModTime() time.Time {
return o.mtime
}

func (o *Obj) CreateTime() time.Time {
return o.ctime
}

func (o *Obj) IsDir() bool {
return o.isDir
}

func (o *Obj) GetHash() utils.HashInfo {
return o.hash
}

func (o *Obj) GetID() string {
return o.id
}

func (o *Obj) GetPath() string {
return o.path
}
Loading