Skip to content

Commit

Permalink
Merge branch 'release/v1.0.28'
Browse files Browse the repository at this point in the history
  • Loading branch information
SheltonZhu committed Sep 1, 2024
2 parents 3844105 + 08b90cd commit 8ace8be
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
* [X] Stat File
* [x] Download by share code
* [x] Offline Download
* Recycle Bin
* [x] List
* [x] Revert
* [x] Clean

## Example

Expand Down
5 changes: 5 additions & 0 deletions pkg/driver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ const (
ApiQrcodeLogin = "https://passportapi.115.com/app/1.0/web/1.0/login/qrcode"
ApiQrcodeLoginWithApp = "https://passportapi.115.com/app/1.0/%s/1.0/login/qrcode"
ApiQrcodeImage = "https://qrcodeapi.115.com/api/1.0/mac/1.0/qrcode?uid=%s"

// recycle
ApiRecycleList = "https://webapi.115.com/rb"
ApiRecycleClean = "https://webapi.115.com/rb/clean"
ApiRecycleRevert = "https://webapi.115.com/rb/revert"
)
21 changes: 21 additions & 0 deletions pkg/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,34 @@ func teardown(t *testing.T) func(t *testing.T) {
return func(t *testing.T) {}
}

func TestListRecycleBin(t *testing.T) {
down := teardown(t)
defer down(t)
_, err := client.ListRecycleBin(0, 40)
assert.Nil(t, err)
}

func TestCleanRecycleBin(t *testing.T) {
down := teardown(t)
defer down(t)
err := client.CleanRecycleBin("xx", "1", "2")
assert.NotNil(t, err)
}

func TestListOfflineTasks(t *testing.T) {
down := teardown(t)
defer down(t)
_, err := client.ListOfflineTask(1)
assert.Nil(t, err)
}

func TestRevertRecycleBin(t *testing.T) {
down := teardown(t)
defer down(t)
err := client.RevertRecycleBin("xx", "1", "2")
assert.NotNil(t, err)
}

func TestOfflineAddUri(t *testing.T) {
down := teardown(t)
defer down(t)
Expand Down
12 changes: 7 additions & 5 deletions pkg/driver/qrcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ const (
LoginAppWeb LoginApp = "web"
LoginAppAndroid LoginApp = "android"
LoginAppIOS LoginApp = "ios"
LoginAppLinux LoginApp = "linux"
LoginAppMac LoginApp = "mac"
LoginAppWindows LoginApp = "windows"
LoginAppTV LoginApp = "tv"
// LoginAppIPad LoginApp = "ipad"
// LoginAppLinux LoginApp = "linux" // disabled
// LoginAppMac LoginApp = "mac" // disabled
// LoginAppWindows LoginApp = "windows" // disabled
LoginAppTV LoginApp = "tv"
LoginAppAlipayMini LoginApp = "alipaymini"
LoginAppWechatMini LoginApp = "wechatmini"
LoginQAppAndroid LoginApp = "qandroid"
)

// QRCodeLoginWithApp logins user through QRCode with specified app.
Expand Down
76 changes: 76 additions & 0 deletions pkg/driver/recylcle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package driver

import (
"fmt"
"net/url"
"strconv"
)

// CleanRecycleBin clean the recycle bin
func (c *Pan115Client) CleanRecycleBin(password string, rIDs ...string) error {
form := url.Values{}
form.Set("password", password)
for idx, rID := range rIDs {
form.Add(fmt.Sprintf("rid[%d]", idx), rID)
}
result := BasicResp{}
req := c.NewRequest().
SetFormDataFromValues(form).
SetResult(&result).
ForceContentType("application/json;charset=UTF-8")

resp, err := req.Post(ApiRecycleClean)
return CheckErr(err, &result, resp)
}

// ListRecycleBin list the recycle bin
func (c *Pan115Client) ListRecycleBin(offset, limit int) ([]RecycleBinItem, error) {
result := RecycleListResponse{}
req := c.NewRequest().
SetQueryParams(map[string]string{
"aid": "7",
"cid": "0",
"format": "json",
"offset": strconv.Itoa(offset),
"limit": strconv.Itoa(limit),
}).
SetResult(&result).
ForceContentType("application/json;charset=UTF-8")

resp, err := req.Get(ApiRecycleList)
err = CheckErr(err, &result, resp)
if err != nil {
return nil, err
}
return result.Data, nil
}

type RecycleListResponse struct {
BasicResp
Data []RecycleBinItem `json:"data"`
}

type RecycleBinItem struct {
FileId string `json:"id"`
FileName string `json:"file_name"`
FileSize StringInt64 `json:"file_size"`
ParentId IntString `json:"cid"`
ParentName string `json:"parent_name"`
DeleteTime StringInt64 `json:"dtime"`
}

// RevertRecycleBin revert the recycle bin
func (c *Pan115Client) RevertRecycleBin(rIDs ...string) error {
form := url.Values{}
for idx, rID := range rIDs {
form.Add(fmt.Sprintf("rid[%d]", idx), rID)
}
result := BasicResp{}
req := c.NewRequest().
SetFormDataFromValues(form).
SetResult(&result).
ForceContentType("application/json;charset=UTF-8")

resp, err := req.Post(ApiRecycleRevert)
return CheckErr(err, &result, resp)
}

0 comments on commit 8ace8be

Please sign in to comment.