Skip to content

Commit

Permalink
fix(lib): use username parameter in lib.List
Browse files Browse the repository at this point in the history
Also, allows fetching a dataset from the collection that is not in your own collection
  • Loading branch information
ramfox authored and Arqu committed Dec 6, 2021
1 parent 6a378ac commit e499860
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions lib/collection.go
Original file line number Diff line number Diff line change
@@ -94,7 +94,17 @@ func (collectionImpl) List(scope scope, p *ListParams) ([]dsref.VersionInfo, Cur
Offset: p.Offset,
Limit: p.Limit,
}
infos, err := s.List(scope.ctx, scope.ActiveProfile().ID, lp)

id := scope.ActiveProfile().ID
if p.Username != "" {
pro, err := getProfile(scope.Context(), scope.Profiles(), "", p.Username)
if err != nil {
return nil, nil, err
}
id = pro.ID
}

infos, err := s.List(scope.ctx, id, lp)
if err != nil {
return nil, nil, err
}
@@ -246,12 +256,28 @@ func (collectionImpl) Get(scope scope, p *CollectionGetParams) (*dsref.VersionIn
if s == nil {
return nil, fmt.Errorf("no collection")
}
if p.InitID == "" {
ref, _, err := scope.ParseAndResolveRef(scope.Context(), p.Ref)

var err error

ref := dsref.Ref{
InitID: p.InitID,
}

if ref.InitID != "" {
_, err = scope.ResolveReference(scope.Context(), &ref)
if err != nil {
return nil, err
}
} else {
ref, _, err = scope.ParseAndResolveRef(scope.Context(), p.Ref)
if err != nil {
return nil, err
}
p.InitID = ref.InitID
}
return s.Get(scope.Context(), scope.ActiveProfile().ID, p.InitID)

id, err := profile.IDB58Decode(ref.ProfileID)
if err != nil {
return nil, err
}
return s.Get(scope.Context(), id, ref.InitID)
}

0 comments on commit e499860

Please sign in to comment.