mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
feat(global-search): add filtering options by starred and bookmarked (#1336)
Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
@@ -224,6 +224,14 @@ func AcceptedByFilter(filter repodb.Filter, data repodb.FilterData) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if filter.IsBookmarked != nil && *filter.IsBookmarked != data.IsBookmarked {
|
||||
return false
|
||||
}
|
||||
|
||||
if filter.IsStarred != nil && *filter.IsStarred != data.IsStarred {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -916,7 +916,7 @@ func (bdw *DBWrapper) SearchRepos(ctx context.Context, searchText string, filter
|
||||
repoMeta.IsBookmarked = zcommon.Contains(userBookmarks, repoMeta.Name)
|
||||
repoMeta.IsStarred = zcommon.Contains(userStars, repoMeta.Name)
|
||||
|
||||
rank := common.RankRepoName(searchText, string(repoName))
|
||||
rank := common.RankRepoName(searchText, repoMeta.Name)
|
||||
if rank == -1 {
|
||||
continue
|
||||
}
|
||||
@@ -1013,6 +1013,8 @@ func (bdw *DBWrapper) SearchRepos(ctx context.Context, searchText string, filter
|
||||
LastUpdated: repoLastUpdated,
|
||||
DownloadCount: repoDownloads,
|
||||
IsSigned: isSigned,
|
||||
IsBookmarked: repoMeta.IsBookmarked,
|
||||
IsStarred: repoMeta.IsStarred,
|
||||
}
|
||||
|
||||
if !common.AcceptedByFilter(filter, repoFilterData) {
|
||||
|
||||
@@ -406,6 +406,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
repoMeta := repodb.RepoMetadata{
|
||||
Name: "repo1",
|
||||
Tags: map[string]repodb.Descriptor{
|
||||
"tag1": {Digest: "dig1", MediaType: ispec.MediaTypeImageManifest},
|
||||
},
|
||||
@@ -420,6 +421,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
repoMeta = repodb.RepoMetadata{
|
||||
Name: "repo2",
|
||||
Tags: map[string]repodb.Descriptor{
|
||||
"tag2": {Digest: "dig2", MediaType: ispec.MediaTypeImageManifest},
|
||||
},
|
||||
@@ -459,6 +461,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
repoMeta = repodb.RepoMetadata{
|
||||
Name: "repo1",
|
||||
Tags: map[string]repodb.Descriptor{
|
||||
"tag1": {Digest: "dig1", MediaType: ispec.MediaTypeImageManifest},
|
||||
},
|
||||
@@ -593,6 +596,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
|
||||
// manifest data doesn't exist
|
||||
repoMeta = repodb.RepoMetadata{
|
||||
Name: "repo1",
|
||||
Tags: map[string]repodb.Descriptor{
|
||||
"tag2": {Digest: "dig2", MediaType: ispec.MediaTypeImageManifest},
|
||||
},
|
||||
@@ -608,6 +612,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
|
||||
// manifest data is wrong
|
||||
repoMeta = repodb.RepoMetadata{
|
||||
Name: "repo2",
|
||||
Tags: map[string]repodb.Descriptor{
|
||||
"tag2": {Digest: "wrongManifestData", MediaType: ispec.MediaTypeImageManifest},
|
||||
},
|
||||
@@ -622,6 +627,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
repoMeta = repodb.RepoMetadata{
|
||||
Name: "repo3",
|
||||
Tags: map[string]repodb.Descriptor{
|
||||
"tag1": {Digest: "dig1", MediaType: ispec.MediaTypeImageManifest},
|
||||
},
|
||||
|
||||
@@ -234,6 +234,8 @@ type Filter struct {
|
||||
Os []*string
|
||||
Arch []*string
|
||||
HasToBeSigned *bool
|
||||
IsBookmarked *bool
|
||||
IsStarred *bool
|
||||
}
|
||||
|
||||
type FilterData struct {
|
||||
@@ -242,4 +244,6 @@ type FilterData struct {
|
||||
OsList []string
|
||||
ArchList []string
|
||||
IsSigned bool
|
||||
IsStarred bool
|
||||
IsBookmarked bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user