mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-28 03:06:38 +08:00
b0fe40142a
* Rebrand MMTL to MeBox across codebase and assets Rename the project display name, Go module path, environment variable prefix (MEBOX_*), Docker image references, and UI branding from MMTL/mmtl to MeBox/mebox. Replace logo assets with the new MeBox icon and keep legacy SQLite migration support for existing mmtl.db deployments. Co-authored-by: truewhile <truewhile@users.noreply.github.com> * Fix logo icons: use cube-only crop without truncated text Previous icon generation cropped too much of the source image, including partial MeBox wordmark text that was cut off in square icon containers. Regenerate logo-64/192/512, favicon, and SVG from cube-only region. Co-authored-by: truewhile <truewhile@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: truewhile <truewhile@users.noreply.github.com>
79 lines
2.7 KiB
Go
79 lines
2.7 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/truewhile/MeBox/internal/model"
|
|
"github.com/truewhile/MeBox/internal/repository"
|
|
)
|
|
|
|
// SearchMedia performs a simple LIKE search across titles.
|
|
func (s *MediaService) SearchMedia(ctx context.Context, query string, limit int) ([]model.Media, error) {
|
|
return s.SearchMediaVisible(ctx, query, limit, MediaVisibility{IncludeNSFW: true})
|
|
}
|
|
|
|
func (s *MediaService) SearchMediaVisible(ctx context.Context, query string, limit int, visibility MediaVisibility) ([]model.Media, error) {
|
|
if limit <= 0 {
|
|
limit = 50
|
|
} else if limit > maxMediaSearchLimit {
|
|
limit = maxMediaSearchLimit
|
|
}
|
|
visibility = ExpandMediaVisibilityForMergedCloudLibraries(ctx, s.repo, visibility)
|
|
items, err := s.repo.Media.SearchFiltered(ctx, query, limit, repository.MediaQueryFilter{
|
|
IncludeNSFW: visibility.IncludeNSFW,
|
|
AllowedLibraryIDs: visibility.AllowedLibraryIDs,
|
|
HiddenLibraryIDs: visibility.HiddenLibraryIDs,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
s.attachLibraryMetadata(ctx, items)
|
|
return items, nil
|
|
}
|
|
|
|
func (s *MediaService) SearchMediaVisibleGrouped(ctx context.Context, query string, limit int, visibility MediaVisibility) ([]MediaItem, error) {
|
|
if limit <= 0 {
|
|
limit = 50
|
|
} else if limit > maxMediaSearchLimit {
|
|
limit = maxMediaSearchLimit
|
|
}
|
|
items, err := s.SearchMediaVisible(ctx, query, maxMediaSearchLimit, visibility)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return firstMediaItems(groupMediaVersions(items), limit), nil
|
|
}
|
|
|
|
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)
|
|
items, total, err := s.repo.Media.SearchFilteredPage(ctx, query, (page-1)*pageSize, pageSize, repository.MediaQueryFilter{
|
|
IncludeNSFW: visibility.IncludeNSFW,
|
|
AllowedLibraryIDs: visibility.AllowedLibraryIDs,
|
|
HiddenLibraryIDs: visibility.HiddenLibraryIDs,
|
|
})
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
s.attachLibraryMetadata(ctx, items)
|
|
return items, total, nil
|
|
}
|
|
|
|
func (s *MediaService) SearchMediaVisiblePageGrouped(ctx context.Context, query string, page, pageSize int, visibility MediaVisibility) ([]MediaItem, int64, error) {
|
|
page, pageSize = normalizeGroupedMediaPage(page, pageSize)
|
|
items, err := s.SearchMediaVisible(ctx, query, maxMediaSearchLimit, visibility)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
grouped := groupMediaVersions(items)
|
|
return paginateMediaItems(grouped, page, pageSize), int64(len(grouped)), nil
|
|
}
|