Skip to content

Commit 59ec1db

Browse files
authored
feat(lenovonas_share): add option to not show root directory (OpenListTeam#772)
1 parent 6bb28d1 commit 59ec1db

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

drivers/lenovonas_share/driver.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package LenovoNasShare
33
import (
44
"context"
55
"net/http"
6+
"strings"
67
"time"
78

89
"github.com/go-resty/resty/v2"
@@ -32,6 +33,10 @@ func (d *LenovoNasShare) Init(ctx context.Context) error {
3233
if err := d.getStoken(); err != nil {
3334
return err
3435
}
36+
if !d.ShowRootFolder && d.RootFolderPath == "" {
37+
list, _ := d.List(ctx, File{}, model.ListArgs{})
38+
d.RootFolderPath = list[0].GetPath()
39+
}
3540
return nil
3641
}
3742

@@ -43,19 +48,26 @@ func (d *LenovoNasShare) List(ctx context.Context, dir model.Obj, args model.Lis
4348
d.checkStoken() // 检查stoken是否过期
4449
files := make([]File, 0)
4550

51+
path := dir.GetPath()
52+
if path == "" && !d.ShowRootFolder && d.RootFolderPath != "" {
53+
path = d.RootFolderPath
54+
}
55+
4656
var resp Files
4757
query := map[string]string{
4858
"code": d.ShareId,
4959
"num": "5000",
5060
"stoken": d.stoken,
51-
"path": dir.GetPath(),
61+
"path": path,
5262
}
5363
_, err := d.request(d.Host+"/oneproxy/api/share/v1/files", http.MethodGet, func(req *resty.Request) {
5464
req.SetQueryParams(query)
5565
}, &resp)
66+
5667
if err != nil {
5768
return nil, err
5869
}
70+
5971
files = append(files, resp.Data.List...)
6072

6173
return utils.SliceConvert(files, func(src File) (model.Obj, error) {
@@ -73,6 +85,10 @@ func (d *LenovoNasShare) getStoken() error { // 获取stoken
7385
if d.Host == "" {
7486
d.Host = "https://siot-share.lenovo.com.cn"
7587
}
88+
89+
parts := strings.Split(d.ShareId, "/")
90+
d.ShareId = parts[len(parts)-1]
91+
7692
query := map[string]string{
7793
"code": d.ShareId,
7894
"password": d.SharePwd,

drivers/lenovonas_share/meta.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77

88
type Addition struct {
99
driver.RootPath
10-
ShareId string `json:"share_id" required:"true" help:"The part after the last / in the shared link"`
11-
SharePwd string `json:"share_pwd" required:"true" help:"The password of the shared link"`
12-
Host string `json:"host" required:"true" default:"https://siot-share.lenovo.com.cn" help:"You can change it to your local area network"`
10+
ShareId string `json:"share_id" required:"true" help:"The part after the last / in the shared link"`
11+
SharePwd string `json:"share_pwd" required:"true" help:"The password of the shared link"`
12+
Host string `json:"host" required:"true" default:"https://siot-share.lenovo.com.cn" help:"You can change it to your local area network"`
13+
ShowRootFolder bool `json:"show_root_folder" default:"true"`
1314
}
1415

1516
var config = driver.Config{

0 commit comments

Comments
 (0)