diff --git a/webdav/file.go b/webdav/file.go index bfff5db..88188d5 100644 --- a/webdav/file.go +++ b/webdav/file.go @@ -760,7 +760,7 @@ type WalkFunc func(parent model.ListModel, info model.FileListModel, err error) // Allowed values for depth are 0, 1 or infiniteDepth. For each visited node, // walkFS calls walkFn. If a visited file system node is a directory and // walkFn returns filepath.SkipDir, walkFS will skip traversal of this node. -func walkFS(ctx context.Context, fs FileSystem, depth int, parent model.ListModel, info model.FileListModel, walkFn WalkFunc, token, driver, userAgent string) error { +func walkFS(ctx context.Context, fs FileSystem, depth int, parent model.ListModel, info model.FileListModel, walkFn WalkFunc, token, driver, userAgent string, cheng int) error { // This implementation is based on Walk's code in the standard path/filepath package. err := walkFn(parent, info, nil) if err != nil { @@ -769,7 +769,6 @@ func walkFS(ctx context.Context, fs FileSystem, depth int, parent model.ListMode if depth == 1 { depth = 0 } - // Read directory names. for _, fileInfo := range info.Items { @@ -782,11 +781,12 @@ func walkFS(ctx context.Context, fs FileSystem, depth int, parent model.ListMode return err } } else { - if fileInfo.Type == "folder" && !strings.Contains(userAgent, "RaiDrive") { + cheng += 1 + if fileInfo.Type == "folder" && !strings.Contains(userAgent, "RaiDrive") && cheng < 2 { info, _ := aliyun.GetList(token, driver, fileInfo.FileId) - walkFS(ctx, fs, depth, fileInfo, info, walkFn, token, driver, userAgent) + walkFS(ctx, fs, depth, fileInfo, info, walkFn, token, driver, userAgent, cheng) } else { - err = walkFS(ctx, fs, depth, fileInfo, fileList, walkFn, token, driver, userAgent) + err = walkFS(ctx, fs, depth, fileInfo, fileList, walkFn, token, driver, userAgent, cheng) if err != nil { if fileInfo.Type != "folder" || err != filepath.SkipDir { return err diff --git a/webdav/webdav.go b/webdav/webdav.go index 892883b..13f8115 100644 --- a/webdav/webdav.go +++ b/webdav/webdav.go @@ -835,7 +835,9 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status walkFn := func(parent model.ListModel, info model.FileListModel, err error) error { if reflect.DeepEqual(parent, model.ListModel{}) { - return nil + fmt.Print("dddd") + parent.Type = "folder" + parent.ParentFileId = "root" } if err != nil { return err @@ -873,7 +875,8 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status return mw.write(makePropstatResponse(href, pstats)) } userAgent := r.Header.Get("User-Agent") - walkErr := walkFS(ctx, h.FileSystem, depth, fi, list, walkFn, h.Config.Token, h.Config.DriveId, userAgent) + cheng := 1 + walkErr := walkFS(ctx, h.FileSystem, depth, fi, list, walkFn, h.Config.Token, h.Config.DriveId, userAgent, cheng) closeErr := mw.close() if walkErr != nil { return http.StatusInternalServerError, walkErr