stash/internal/dlna/paging.go
WithoutPants f69bd8a94f
Restructure go project (#2356)
* Move main to cmd
* Move api to internal
* Move logger and manager to internal
* Move shell hiding code to separate package
* Decouple job from desktop and utils
* Decouple session from config
* Move static into internal
* Decouple config from dlna
* Move desktop to internal
* Move dlna to internal
* Decouple remaining packages from config
* Move config into internal
* Move jsonschema and paths to models
* Make ffmpeg functions private
* Move file utility methods into fsutil package
* Move symwalk into fsutil
* Move single-use util functions into client package
* Move slice functions to separate packages
* Add env var to suppress windowsgui arg
* Move hash functions into separate package
* Move identify to internal
* Move autotag to internal
* Touch UI when generating backend
2022-03-17 11:33:59 +11:00

81 lines
1.8 KiB
Go

package dlna
import (
"fmt"
"math"
"strconv"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene"
)
type scenePager struct {
sceneFilter *models.SceneFilterType
parentID string
}
func (p *scenePager) getPageID(page int) string {
return p.parentID + "/page/" + strconv.Itoa(page)
}
func (p *scenePager) getPages(r models.ReaderRepository, total int) ([]interface{}, error) {
var objs []interface{}
// get the first scene of each page to set an appropriate title
pages := int(math.Ceil(float64(total) / float64(pageSize)))
singlePageSize := 1
sort := "title"
findFilter := &models.FindFilterType{
PerPage: &singlePageSize,
Sort: &sort,
}
for page := 1; page <= pages; page++ {
// TODO - this is really slow. Not sure if there's a better way
title := fmt.Sprintf("Page %d", page)
if pages <= 10 || (page-1)%(pages/10) == 0 {
thisPage := ((page - 1) * pageSize) + 1
findFilter.Page = &thisPage
scenes, err := scene.Query(r.Scene(), p.sceneFilter, findFilter)
if err != nil {
return nil, err
}
sceneTitle := scenes[0].GetTitle()
// use the first three letters as a prefix
if len(sceneTitle) > 3 {
sceneTitle = sceneTitle[0:3]
}
title += fmt.Sprintf(" (%s...)", sceneTitle)
}
objs = append(objs, makeStorageFolder(p.getPageID(page), title, p.parentID))
}
return objs, nil
}
func (p *scenePager) getPageVideos(r models.ReaderRepository, page int, host string) ([]interface{}, error) {
var objs []interface{}
sort := "title"
findFilter := &models.FindFilterType{
PerPage: &pageSize,
Page: &page,
Sort: &sort,
}
scenes, err := scene.Query(r.Scene(), p.sceneFilter, findFilter)
if err != nil {
return nil, err
}
for _, s := range scenes {
objs = append(objs, sceneToContainer(s, p.parentID, host))
}
return objs, nil
}