mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-12 08:16:37 +08:00
fix full library display and cloud search visibility
This commit is contained in:
@@ -29,6 +29,9 @@ type MediaVisibility struct {
|
||||
HiddenLibraryIDs []string
|
||||
}
|
||||
|
||||
const maxMediaSearchLimit = 50000
|
||||
const maxMediaSearchPageSize = 2000
|
||||
|
||||
func (v MediaVisibility) Allows(media *model.Media) bool {
|
||||
if media == nil {
|
||||
return false
|
||||
@@ -281,8 +284,8 @@ func (s *MediaService) SearchMedia(ctx context.Context, query string, limit int)
|
||||
func (s *MediaService) SearchMediaVisible(ctx context.Context, query string, limit int, visibility MediaVisibility) ([]model.Media, error) {
|
||||
if limit <= 0 {
|
||||
limit = 50
|
||||
} else if limit > 2000 {
|
||||
limit = 2000
|
||||
} else if limit > maxMediaSearchLimit {
|
||||
limit = maxMediaSearchLimit
|
||||
}
|
||||
visibility = ExpandMediaVisibilityForMergedCloudLibraries(ctx, s.repo, visibility)
|
||||
return s.repo.Media.SearchFiltered(ctx, query, limit, repository.MediaQueryFilter{
|
||||
@@ -292,6 +295,24 @@ func (s *MediaService) SearchMediaVisible(ctx context.Context, query string, lim
|
||||
})
|
||||
}
|
||||
|
||||
func (s *MediaService) SearchMediaVisiblePage(ctx context.Context, query string, page, pageSize int, visibility MediaVisibility) ([]model.Media, int64, error) {
|
||||
if pageSize <= 0 {
|
||||
pageSize = 50
|
||||
}
|
||||
if pageSize > maxMediaSearchPageSize {
|
||||
pageSize = maxMediaSearchPageSize
|
||||
}
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
visibility = ExpandMediaVisibilityForMergedCloudLibraries(ctx, s.repo, visibility)
|
||||
return s.repo.Media.SearchFilteredPage(ctx, query, (page-1)*pageSize, pageSize, repository.MediaQueryFilter{
|
||||
IncludeNSFW: visibility.IncludeNSFW,
|
||||
AllowedLibraryIDs: visibility.AllowedLibraryIDs,
|
||||
HiddenLibraryIDs: visibility.HiddenLibraryIDs,
|
||||
})
|
||||
}
|
||||
|
||||
// GetMedia returns a single media row.
|
||||
func (s *MediaService) GetMedia(ctx context.Context, id string) (*model.Media, error) {
|
||||
return s.repo.Media.FindByID(ctx, id)
|
||||
|
||||
Reference in New Issue
Block a user