Skip to content

Commit 44ca8f9

Browse files
committed
fix(driver/139): refactor RootPath handling
Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent 89ea694 commit 44ca8f9

2 files changed

Lines changed: 22 additions & 28 deletions

File tree

drivers/139/driver.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ type Yun139 struct {
3232
PersonalCloudHost string
3333
FamilyCloudHost string
3434
GroupCloudHost string
35-
RootPath string
3635
}
3736

3837
func (d *Yun139) Config() driver.Config {
@@ -226,7 +225,7 @@ func (d *Yun139) MakeDir(ctx context.Context, parentDir model.Obj, dirName strin
226225
"accountType": 1,
227226
},
228227
"docLibName": dirName,
229-
"path": path.Join(parentDir.GetPath(), parentDir.GetID()),
228+
"path": d.dirPath(parentDir),
230229
}
231230
pathname := "/orchestration/familyCloud-rebuild/cloudCatalog/v1.0/createCloudDoc"
232231
_, err = d.post(pathname, data, nil)
@@ -239,7 +238,7 @@ func (d *Yun139) MakeDir(ctx context.Context, parentDir model.Obj, dirName strin
239238
},
240239
"groupID": d.CloudID,
241240
"parentFileId": parentDir.GetID(),
242-
"path": path.Join(parentDir.GetPath(), parentDir.GetID()),
241+
"path": d.dirPath(parentDir),
243242
}
244243
pathname := "/orchestration/group-rebuild/catalog/v1.0/createGroupCatalog"
245244
_, err = d.post(pathname, data, nil)
@@ -324,9 +323,9 @@ func (d *Yun139) Move(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj,
324323
var contentList []string
325324
var catalogList []string
326325
if srcObj.IsDir() {
327-
catalogList = append(catalogList, path.Join(srcObj.GetPath(), srcObj.GetID()))
326+
catalogList = append(catalogList, d.dirPath(srcObj))
328327
} else {
329-
contentList = append(contentList, path.Join(srcObj.GetPath(), srcObj.GetID()))
328+
contentList = append(contentList, d.dirPath(srcObj))
330329
}
331330

332331
body := base.Json{
@@ -338,7 +337,7 @@ func (d *Yun139) Move(ctx context.Context, srcObj, dstDir model.Obj) (model.Obj,
338337
"contentList": contentList,
339338
"destCatalogID": dstDir.GetID(),
340339
"destGroupID": d.CloudID,
341-
"destPath": path.Join(dstDir.GetPath(), dstDir.GetID()),
340+
"destPath": d.dirPath(dstDir),
342341
"destType": 0,
343342
"srcGroupID": d.CloudID,
344343
"srcType": 0,
@@ -439,7 +438,7 @@ func (d *Yun139) Rename(ctx context.Context, srcObj model.Obj, newName string) e
439438
},
440439
"docLibName": newName,
441440
"docLibraryID": srcObj.GetID(),
442-
"path": path.Join(srcObj.GetPath(), srcObj.GetID()),
441+
"path": d.dirPath(srcObj),
443442
}
444443
var resp ModifyCloudDocV2Resp
445444
_, err = d.andAlbumRequest(pathname, data, &resp)
@@ -845,11 +844,7 @@ func (d *Yun139) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
845844
}
846845
pathname := "/orchestration/personalCloud/uploadAndDownload/v1.0/pcUploadFileRequest"
847846
if d.isFamily() || d.isGroup() {
848-
uploadPath := path.Join(dstDir.GetPath(), dstDir.GetID())
849-
// if dstDir is root folder
850-
if dstDir.GetID() == d.RootFolderID {
851-
uploadPath = d.RootPath
852-
}
847+
uploadPath := d.dirPath(dstDir)
853848
data = d.newJson(base.Json{
854849
"fileCount": 1,
855850
"manualRename": 2,

drivers/139/util.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,6 @@ func (d *Yun139) familyGetFiles(catalogID string) ([]model.Obj, error) {
357357
}
358358
// 返回的是完整的Path: root:/<UserRootID>/<CatalogID>/.../<CatalogID>
359359
path := resp.Data.Path
360-
if catalogID == d.RootFolderID {
361-
path = ensureRootPath(d.RootPath)
362-
d.RootPath = path
363-
}
364360
for _, catalog := range resp.Data.CloudCatalogList {
365361
f := model.Object{
366362
ID: catalog.CatalogID,
@@ -416,9 +412,6 @@ func (d *Yun139) groupGetFiles(catalogID string) ([]model.Obj, error) {
416412
return nil, err
417413
}
418414
path := resp.Data.GetGroupContentResult.ParentCatalogID
419-
if catalogID == d.RootFolderID {
420-
d.RootPath = path
421-
}
422415
for _, catalog := range resp.Data.GetGroupContentResult.CatalogList {
423416
f := model.Object{
424417
ID: catalog.CatalogID,
@@ -1371,6 +1364,21 @@ func (d *Yun139) getGroupRootByCloudID(cloudID string) (string, error) {
13711364
return "", fmt.Errorf("no root found in group response")
13721365
}
13731366

1367+
// dirPath returns the full path for a directory object.
1368+
// For family root (Path="" from framework), needs "root:/"+id prefix.
1369+
// Non-root objects already have their API path in GetPath() from List responses.
1370+
func (d *Yun139) dirPath(dir model.Obj) string {
1371+
p := dir.GetPath()
1372+
id := dir.GetID()
1373+
if p == "" {
1374+
if d.isFamily() {
1375+
return "root:/" + id
1376+
}
1377+
return id
1378+
}
1379+
return path.Join(p, id)
1380+
}
1381+
13741382
// helper to strip "root:/" or "root:" prefix
13751383
func stripRootPath(s string) string {
13761384
s = strings.TrimSpace(s)
@@ -1379,15 +1387,6 @@ func stripRootPath(s string) string {
13791387
return s
13801388
}
13811389

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-
13911390
// getFamilyRootPath 查询 family 的上层 path(data.path)
13921391
// 返回值已去除前缀 "root:/"(或 "root:"),直接返回纯 ID 或 path 部分,便于持久化为 RootFolderID。
13931392
func (d *Yun139) getFamilyRootPath(cloudID string) (string, error) {

0 commit comments

Comments
 (0)