mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Images section (#813)
* Add new configuration options * Refactor scan/clean * Schema changes * Add details to galleries * Remove redundant code * Refine thumbnail generation * Gallery overhaul * Don't allow modifying zip gallery images * Show gallery card overlays * Hide zoom slider when not in grid mode
This commit is contained in:
81
pkg/image/export.go
Normal file
81
pkg/image/export.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"github.com/stashapp/stash/pkg/manager/jsonschema"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
// ToBasicJSON converts a image object into its JSON object equivalent. It
|
||||
// does not convert the relationships to other objects, with the exception
|
||||
// of cover image.
|
||||
func ToBasicJSON(image *models.Image) *jsonschema.Image {
|
||||
newImageJSON := jsonschema.Image{
|
||||
Checksum: image.Checksum,
|
||||
CreatedAt: models.JSONTime{Time: image.CreatedAt.Timestamp},
|
||||
UpdatedAt: models.JSONTime{Time: image.UpdatedAt.Timestamp},
|
||||
}
|
||||
|
||||
if image.Title.Valid {
|
||||
newImageJSON.Title = image.Title.String
|
||||
}
|
||||
|
||||
if image.Rating.Valid {
|
||||
newImageJSON.Rating = int(image.Rating.Int64)
|
||||
}
|
||||
|
||||
newImageJSON.OCounter = image.OCounter
|
||||
|
||||
newImageJSON.File = getImageFileJSON(image)
|
||||
|
||||
return &newImageJSON
|
||||
}
|
||||
|
||||
func getImageFileJSON(image *models.Image) *jsonschema.ImageFile {
|
||||
ret := &jsonschema.ImageFile{}
|
||||
|
||||
if image.Size.Valid {
|
||||
ret.Size = int(image.Size.Int64)
|
||||
}
|
||||
|
||||
if image.Width.Valid {
|
||||
ret.Width = int(image.Width.Int64)
|
||||
}
|
||||
|
||||
if image.Height.Valid {
|
||||
ret.Height = int(image.Height.Int64)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// GetStudioName returns the name of the provided image's studio. It returns an
|
||||
// empty string if there is no studio assigned to the image.
|
||||
func GetStudioName(reader models.StudioReader, image *models.Image) (string, error) {
|
||||
if image.StudioID.Valid {
|
||||
studio, err := reader.Find(int(image.StudioID.Int64))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if studio != nil {
|
||||
return studio.Name.String, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// GetGalleryChecksum returns the checksum of the provided image. It returns an
|
||||
// empty string if there is no gallery assigned to the image.
|
||||
// func GetGalleryChecksum(reader models.GalleryReader, image *models.Image) (string, error) {
|
||||
// gallery, err := reader.FindByImageID(image.ID)
|
||||
// if err != nil {
|
||||
// return "", fmt.Errorf("error getting image gallery: %s", err.Error())
|
||||
// }
|
||||
|
||||
// if gallery != nil {
|
||||
// return gallery.Checksum, nil
|
||||
// }
|
||||
|
||||
// return "", nil
|
||||
// }
|
||||
Reference in New Issue
Block a user