mirror of
https://github.com/stashapp/stash.git
synced 2025-12-08 09:23:38 +01:00
* Add funscript route to scenes Adds a /scene/:id/funscript route which serves a funscript file, if present. Current convention is that these are files stored with the same path, but with the extension ".funscript". * Look for funscript during scan This is stored in the Scene record and used to drive UI changes for funscript support. Currently, that's limited to a funscript link in the Scene's file info. * Add filtering and sorting for interactive * Add Handy connection key to interface config * Add Handy client and placeholder component. Uses defucilis/thehandy, but not thehandy-react as I had difficulty integrating the context with the existing components. Instead, the expensive calculation for the server time offset is put in localStorage for reuse. A debounce was added when scrubbing the video, as otherwise it spammed the Handy API with updates to the current offset.
217 lines
5.5 KiB
Go
217 lines
5.5 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/stashapp/stash/pkg/api/urlbuilders"
|
|
"github.com/stashapp/stash/pkg/manager/config"
|
|
"github.com/stashapp/stash/pkg/models"
|
|
"github.com/stashapp/stash/pkg/utils"
|
|
)
|
|
|
|
func (r *sceneResolver) Checksum(ctx context.Context, obj *models.Scene) (*string, error) {
|
|
if obj.Checksum.Valid {
|
|
return &obj.Checksum.String, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Oshash(ctx context.Context, obj *models.Scene) (*string, error) {
|
|
if obj.OSHash.Valid {
|
|
return &obj.OSHash.String, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Title(ctx context.Context, obj *models.Scene) (*string, error) {
|
|
if obj.Title.Valid {
|
|
return &obj.Title.String, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Details(ctx context.Context, obj *models.Scene) (*string, error) {
|
|
if obj.Details.Valid {
|
|
return &obj.Details.String, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (r *sceneResolver) URL(ctx context.Context, obj *models.Scene) (*string, error) {
|
|
if obj.URL.Valid {
|
|
return &obj.URL.String, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Date(ctx context.Context, obj *models.Scene) (*string, error) {
|
|
if obj.Date.Valid {
|
|
result := utils.GetYMDFromDatabaseDate(obj.Date.String)
|
|
return &result, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Rating(ctx context.Context, obj *models.Scene) (*int, error) {
|
|
if obj.Rating.Valid {
|
|
rating := int(obj.Rating.Int64)
|
|
return &rating, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (r *sceneResolver) File(ctx context.Context, obj *models.Scene) (*models.SceneFileType, error) {
|
|
width := int(obj.Width.Int64)
|
|
height := int(obj.Height.Int64)
|
|
bitrate := int(obj.Bitrate.Int64)
|
|
return &models.SceneFileType{
|
|
Size: &obj.Size.String,
|
|
Duration: &obj.Duration.Float64,
|
|
VideoCodec: &obj.VideoCodec.String,
|
|
AudioCodec: &obj.AudioCodec.String,
|
|
Width: &width,
|
|
Height: &height,
|
|
Framerate: &obj.Framerate.Float64,
|
|
Bitrate: &bitrate,
|
|
}, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Paths(ctx context.Context, obj *models.Scene) (*models.ScenePathsType, error) {
|
|
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
|
builder := urlbuilders.NewSceneURLBuilder(baseURL, obj.ID)
|
|
builder.APIKey = config.GetInstance().GetAPIKey()
|
|
screenshotPath := builder.GetScreenshotURL(obj.UpdatedAt.Timestamp)
|
|
previewPath := builder.GetStreamPreviewURL()
|
|
streamPath := builder.GetStreamURL()
|
|
webpPath := builder.GetStreamPreviewImageURL()
|
|
vttPath := builder.GetSpriteVTTURL()
|
|
spritePath := builder.GetSpriteURL()
|
|
chaptersVttPath := builder.GetChaptersVTTURL()
|
|
funscriptPath := builder.GetFunscriptURL()
|
|
|
|
return &models.ScenePathsType{
|
|
Screenshot: &screenshotPath,
|
|
Preview: &previewPath,
|
|
Stream: &streamPath,
|
|
Webp: &webpPath,
|
|
Vtt: &vttPath,
|
|
ChaptersVtt: &chaptersVttPath,
|
|
Sprite: &spritePath,
|
|
Funscript: &funscriptPath,
|
|
}, nil
|
|
}
|
|
|
|
func (r *sceneResolver) SceneMarkers(ctx context.Context, obj *models.Scene) (ret []*models.SceneMarker, err error) {
|
|
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
|
|
ret, err = repo.SceneMarker().FindBySceneID(obj.ID)
|
|
return err
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Galleries(ctx context.Context, obj *models.Scene) (ret []*models.Gallery, err error) {
|
|
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
|
|
ret, err = repo.Gallery().FindBySceneID(obj.ID)
|
|
return err
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Studio(ctx context.Context, obj *models.Scene) (ret *models.Studio, err error) {
|
|
if !obj.StudioID.Valid {
|
|
return nil, nil
|
|
}
|
|
|
|
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
|
|
ret, err = repo.Studio().Find(int(obj.StudioID.Int64))
|
|
return err
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Movies(ctx context.Context, obj *models.Scene) (ret []*models.SceneMovie, err error) {
|
|
if err := r.withTxn(ctx, func(repo models.Repository) error {
|
|
qb := repo.Scene()
|
|
mqb := repo.Movie()
|
|
|
|
sceneMovies, err := qb.GetMovies(obj.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, sm := range sceneMovies {
|
|
movie, err := mqb.Find(sm.MovieID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
sceneIdx := sm.SceneIndex
|
|
sceneMovie := &models.SceneMovie{
|
|
Movie: movie,
|
|
}
|
|
|
|
if sceneIdx.Valid {
|
|
var idx int
|
|
idx = int(sceneIdx.Int64)
|
|
sceneMovie.SceneIndex = &idx
|
|
}
|
|
|
|
ret = append(ret, sceneMovie)
|
|
}
|
|
|
|
return nil
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Tags(ctx context.Context, obj *models.Scene) (ret []*models.Tag, err error) {
|
|
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
|
|
ret, err = repo.Tag().FindBySceneID(obj.ID)
|
|
return err
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Performers(ctx context.Context, obj *models.Scene) (ret []*models.Performer, err error) {
|
|
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
|
|
ret, err = repo.Performer().FindBySceneID(obj.ID)
|
|
return err
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *sceneResolver) StashIds(ctx context.Context, obj *models.Scene) (ret []*models.StashID, err error) {
|
|
if err := r.withReadTxn(ctx, func(repo models.ReaderRepository) error {
|
|
ret, err = repo.Scene().GetStashIDs(obj.ID)
|
|
return err
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *sceneResolver) Phash(ctx context.Context, obj *models.Scene) (*string, error) {
|
|
if obj.Phash.Valid {
|
|
hexval := utils.PhashToString(obj.Phash.Int64)
|
|
return &hexval, nil
|
|
}
|
|
return nil, nil
|
|
}
|