From 1dff84accf73638b1e5804d11fee64bd47d9fd01 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 1 Mar 2024 23:28:05 -0500 Subject: [PATCH] refactor: make resolveDirCid a utility function --- api/s5/fs_dir.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/api/s5/fs_dir.go b/api/s5/fs_dir.go index a909c1c..6495a1f 100644 --- a/api/s5/fs_dir.go +++ b/api/s5/fs_dir.go @@ -5,6 +5,8 @@ import ( "io/fs" "strings" + "git.lumeweb.com/LumeWeb/libs5-go/node" + "git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/libs5-go/metadata" ) @@ -92,11 +94,21 @@ func (w dirFs) openNestedDir(name string, remainingPath string, dir *metadata.Di } func (w *dirFs) resolveDirCid(dir *metadata.DirectoryReference) (*encoding.CID, error) { + return resolveDirCid(dir, w.s5.getNode()) +} + +func newDirFs(root *encoding.CID, s5 *S5API) *dirFs { + return &dirFs{ + root: root, + s5: s5, + } +} +func resolveDirCid(dir *metadata.DirectoryReference, node *node.Node) (*encoding.CID, error) { if len(dir.PublicKey) == 0 { return nil, errors.New("missing public key") } - entry, err := w.s5.getNode().Services().Registry().Get(dir.PublicKey) + entry, err := node.Services().Registry().Get(dir.PublicKey) if err != nil { return nil, err } @@ -109,10 +121,3 @@ func (w *dirFs) resolveDirCid(dir *metadata.DirectoryReference) (*encoding.CID, return cid, nil } - -func newDirFs(root *encoding.CID, s5 *S5API) *dirFs { - return &dirFs{ - root: root, - s5: s5, - } -}