Skip to content

Commit 89ea694

Browse files
committed
fix(driver/139): do not use path in id
Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent 2ce65ad commit 89ea694

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

drivers/139/driver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func (d *Yun139) Init(ctx context.Context) error {
123123
case MetaFamily:
124124
if len(d.Addition.RootFolderID) == 0 {
125125
// Attempt to obtain data.path as the root via a query and persist it.
126+
d.RootFolderID = stripRootPath(d.RootFolderID)
126127
if root, err := d.getFamilyRootPath(d.CloudID); err == nil && root != "" {
127128
d.RootFolderID = root
128129
op.MustSaveDriverStorage(d)
@@ -843,7 +844,7 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
843844
},
844845
}
845846
pathname := "/orchestration/personalCloud/uploadAndDownload/v1.0/pcUploadFileRequest"
846-
if d.isFamily() || d.Addition.Type == MetaGroup {
847+
if d.isFamily() || d.isGroup() {
847848
uploadPath := path.Join(dstDir.GetPath(), dstDir.GetID())
848849
// if dstDir is root folder
849850
if dstDir.GetID() == d.RootFolderID {

drivers/139/util.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ const (
4141

4242
// do others that not defined in Driver interface
4343
func (d *Yun139) isFamily() bool {
44-
return d.Type == "family"
44+
return d.Type == MetaFamily
45+
}
46+
47+
func (d *Yun139) isGroup() bool {
48+
return d.Type == MetaGroup
4549
}
4650

4751
func encodeURIComponent(str string) string {
@@ -353,6 +357,10 @@ func (d *Yun139) familyGetFiles(catalogID string) ([]model.Obj, error) {
353357
}
354358
// 返回的是完整的Path: root:/<UserRootID>/<CatalogID>/.../<CatalogID>
355359
path := resp.Data.Path
360+
if catalogID == d.RootFolderID {
361+
path = ensureRootPath(d.RootPath)
362+
d.RootPath = path
363+
}
356364
for _, catalog := range resp.Data.CloudCatalogList {
357365
f := model.Object{
358366
ID: catalog.CatalogID,
@@ -1363,8 +1371,25 @@ func (d *Yun139) getGroupRootByCloudID(cloudID string) (string, error) {
13631371
return "", fmt.Errorf("no root found in group response")
13641372
}
13651373

1374+
// helper to strip "root:/" or "root:" prefix
1375+
func stripRootPath(s string) string {
1376+
s = strings.TrimSpace(s)
1377+
s = strings.TrimPrefix(s, "root:/")
1378+
s = strings.TrimPrefix(s, "root:")
1379+
return s
1380+
}
1381+
1382+
// helper to ensure "root:/" prefix
1383+
func ensureRootPath(s string) string {
1384+
s = strings.TrimSpace(s)
1385+
if !strings.HasPrefix(s, "root:") {
1386+
s = "root:/" + s
1387+
}
1388+
return s
1389+
}
1390+
13661391
// getFamilyRootPath 查询 family 的上层 path(data.path)
1367-
// 返回值为完整Path
1392+
// 返回值已去除前缀 "root:/"(或 "root:"),直接返回纯 ID 或 path 部分,便于持久化为 RootFolderID。
13681393
func (d *Yun139) getFamilyRootPath(cloudID string) (string, error) {
13691394
// 使用 v1.2 接口(代码日志中已有该请求),pageSize 取 1 足够获取 path 字段
13701395
pathname := "/orchestration/familyCloud-rebuild/content/v1.2/queryContentList"
@@ -1394,13 +1419,13 @@ func (d *Yun139) getFamilyRootPath(cloudID string) (string, error) {
13941419
return "", fmt.Errorf("invalid family response data")
13951420
}
13961421
if p, ok := dataObj["path"].(string); ok && p != "" {
1397-
return p, nil
1422+
return stripRootPath(p), nil
13981423
}
13991424
// 回退:有时 path 在 cloudCatalogList.catalogList 中
14001425
if cl, ok := dataObj["cloudCatalogList"].([]interface{}); ok && len(cl) > 0 {
14011426
if first, ok := cl[0].(map[string]interface{}); ok {
14021427
if p, ok := first["path"].(string); ok && p != "" {
1403-
return p, nil
1428+
return stripRootPath(p), nil
14041429
}
14051430
}
14061431
}

0 commit comments

Comments
 (0)