mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
* Treat empty image input as null * Add validation to models.Date * Allow zero dates in database * Make scene_markers.scene_id non-nullable * Drop scraped_items table * Remove movie/studio checksum * Add migration notes --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
156 lines
4.4 KiB
Go
156 lines
4.4 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/stashapp/stash/internal/api/loaders"
|
|
"github.com/stashapp/stash/internal/api/urlbuilders"
|
|
"github.com/stashapp/stash/pkg/gallery"
|
|
"github.com/stashapp/stash/pkg/hash/md5"
|
|
"github.com/stashapp/stash/pkg/image"
|
|
"github.com/stashapp/stash/pkg/models"
|
|
"github.com/stashapp/stash/pkg/movie"
|
|
"github.com/stashapp/stash/pkg/performer"
|
|
"github.com/stashapp/stash/pkg/scene"
|
|
)
|
|
|
|
func (r *studioResolver) Checksum(ctx context.Context, obj *models.Studio) (string, error) {
|
|
// generate checksum from studio name
|
|
return md5.FromString(obj.Name), nil
|
|
}
|
|
|
|
func (r *studioResolver) ImagePath(ctx context.Context, obj *models.Studio) (*string, error) {
|
|
var hasImage bool
|
|
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
|
|
var err error
|
|
hasImage, err = r.repository.Studio.HasImage(ctx, obj.ID)
|
|
return err
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
baseURL, _ := ctx.Value(BaseURLCtxKey).(string)
|
|
imagePath := urlbuilders.NewStudioURLBuilder(baseURL, obj).GetStudioImageURL(hasImage)
|
|
return &imagePath, nil
|
|
}
|
|
|
|
func (r *studioResolver) Aliases(ctx context.Context, obj *models.Studio) (ret []string, err error) {
|
|
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
|
|
ret, err = r.repository.Studio.GetAliases(ctx, obj.ID)
|
|
return err
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ret, err
|
|
}
|
|
|
|
func (r *studioResolver) SceneCount(ctx context.Context, obj *models.Studio, depth *int) (ret int, err error) {
|
|
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
|
|
ret, err = scene.CountByStudioID(ctx, r.repository.Scene, obj.ID, depth)
|
|
return err
|
|
}); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *studioResolver) ImageCount(ctx context.Context, obj *models.Studio, depth *int) (ret int, err error) {
|
|
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
|
|
ret, err = image.CountByStudioID(ctx, r.repository.Image, obj.ID, depth)
|
|
return err
|
|
}); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *studioResolver) GalleryCount(ctx context.Context, obj *models.Studio, depth *int) (ret int, err error) {
|
|
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
|
|
ret, err = gallery.CountByStudioID(ctx, r.repository.Gallery, obj.ID, depth)
|
|
return err
|
|
}); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *studioResolver) PerformerCount(ctx context.Context, obj *models.Studio, depth *int) (ret int, err error) {
|
|
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
|
|
ret, err = performer.CountByStudioID(ctx, r.repository.Performer, obj.ID, depth)
|
|
return err
|
|
}); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *studioResolver) MovieCount(ctx context.Context, obj *models.Studio, depth *int) (ret int, err error) {
|
|
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
|
|
ret, err = movie.CountByStudioID(ctx, r.repository.Movie, obj.ID, depth)
|
|
return err
|
|
}); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *studioResolver) ParentStudio(ctx context.Context, obj *models.Studio) (ret *models.Studio, err error) {
|
|
if obj.ParentID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return loaders.From(ctx).StudioByID.Load(*obj.ParentID)
|
|
}
|
|
|
|
func (r *studioResolver) ChildStudios(ctx context.Context, obj *models.Studio) (ret []*models.Studio, err error) {
|
|
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
|
|
ret, err = r.repository.Studio.FindChildren(ctx, obj.ID)
|
|
return err
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
func (r *studioResolver) StashIds(ctx context.Context, obj *models.Studio) ([]*models.StashID, error) {
|
|
var ret []models.StashID
|
|
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
|
|
var err error
|
|
ret, err = r.repository.Studio.GetStashIDs(ctx, obj.ID)
|
|
return err
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return stashIDsSliceToPtrSlice(ret), nil
|
|
}
|
|
|
|
func (r *studioResolver) Rating(ctx context.Context, obj *models.Studio) (*int, error) {
|
|
if obj.Rating != nil {
|
|
rating := models.Rating100To5(*obj.Rating)
|
|
return &rating, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (r *studioResolver) Rating100(ctx context.Context, obj *models.Studio) (*int, error) {
|
|
return obj.Rating, nil
|
|
}
|
|
|
|
func (r *studioResolver) Movies(ctx context.Context, obj *models.Studio) (ret []*models.Movie, err error) {
|
|
if err := r.withReadTxn(ctx, func(ctx context.Context) error {
|
|
ret, err = r.repository.Movie.FindByStudioID(ctx, obj.ID)
|
|
return err
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ret, nil
|
|
}
|