-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(registry): add preview support to registry fetching
- Loading branch information
Showing
14 changed files
with
295 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package base | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/qri-io/dataset" | ||
"github.com/qri-io/qri/base/dsfs" | ||
"github.com/qri-io/qri/dsref" | ||
"github.com/qri-io/qri/repo" | ||
) | ||
|
||
// CreatePreview generates a preview for a dataset version | ||
func CreatePreview(ctx context.Context, r repo.Repo, ref dsref.Ref) (ds *dataset.Dataset, err error) { | ||
if ref.Path == "" { | ||
return nil, fmt.Errorf("path is required") | ||
} | ||
|
||
ds, err = dsfs.LoadDataset(ctx, r.Store(), ref.Path) | ||
if err != nil { | ||
log.Errorf("CreatePreview loading dataset: %s", err.Error()) | ||
return nil, err | ||
} | ||
|
||
if err = ds.OpenBodyFile(ctx, r.Store()); err != nil { | ||
log.Errorf("CreatePreview opening body file: %s", err.Error()) | ||
return nil, err | ||
} | ||
|
||
st := &dataset.Structure{ | ||
Format: "json", | ||
Schema: ds.Structure.Schema, | ||
} | ||
|
||
data, err := ConvertBodyFile(ds.BodyFile(), ds.Structure, st, 100, 0, false) | ||
if err != nil { | ||
log.Errorf("CreatePreview converting body file: %s", err.Error()) | ||
return nil, err | ||
} | ||
|
||
ds.Peername = ref.Username | ||
ds.Name = ref.Name | ||
ds.Path = ref.Path | ||
ds.Body = json.RawMessage(data) | ||
return ds, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.