Files
MeBox/internal/service/emby_counts.go
T
truewhile b0fe40142a Rebrand MMTL to MeBox (name, logo, Docker image) (#17)
* 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>
2026-09-02 16:26:28 +08:00

68 lines
1.7 KiB
Go

package service
import (
"context"
"strings"
"github.com/truewhile/MeBox/internal/model"
"gorm.io/gorm"
)
func (e *EmbyService) ItemCounts(ctx context.Context, userID string) (map[string]any, error) {
base := func() *gorm.DB {
q := e.repo.DB.WithContext(ctx).Model(&model.Media{}).Where("deleted_at IS NULL")
return e.applyUserMediaVisibility(ctx, q, userID)
}
var itemCount int64
if err := base().Count(&itemCount).Error; err != nil {
return nil, err
}
var movieCount int64
if err := e.filterMovieItems(ctx, base()).Count(&movieCount).Error; err != nil {
return nil, err
}
var episodeCount int64
if err := e.filterEpisodeItems(ctx, base()).Count(&episodeCount).Error; err != nil {
return nil, err
}
seriesCount, err := e.countVisibleSeries(ctx, userID)
if err != nil {
return nil, err
}
return map[string]any{
"MovieCount": movieCount,
"SeriesCount": seriesCount,
"EpisodeCount": episodeCount,
"ItemCount": itemCount,
}, nil
}
func (e *EmbyService) countVisibleSeries(ctx context.Context, userID string) (int, error) {
q := e.repo.DB.WithContext(ctx).Model(&model.Media{}).
Select("id, library_id, series_id, title, original_name, path, season_num, episode_num").
Where("season_num > 0 OR episode_num > 0")
q = e.applyUserMediaVisibility(ctx, q, userID)
seen := map[string]struct{}{}
var rows []model.Media
err := q.Order("media.id asc").FindInBatches(&rows, 1000, func(tx *gorm.DB, batch int) error {
for i := range rows {
key := strings.TrimSpace(rows[i].SeriesID)
if key == "" {
key = stableEmbyID(embyVirtualSeriesPrefix, rows[i].LibraryID, e.seriesNameForMedia(&rows[i]))
}
seen[key] = struct{}{}
}
return nil
}).Error
if err != nil {
return 0, err
}
return len(seen), nil
}