mirror of https://github.com/stashapp/stash.git
Added support for import / export of scene cover images
This commit is contained in:
parent
9766071815
commit
653406efd1
|
@ -60,6 +60,9 @@ func (r *mutationResolver) ScenesUpdate(ctx context.Context, input []*models.Sce
|
|||
func (r *mutationResolver) sceneUpdate(input models.SceneUpdateInput, tx *sqlx.Tx) (*models.Scene, error) {
|
||||
// Populate scene from the input
|
||||
sceneID, _ := strconv.Atoi(input.ID)
|
||||
|
||||
var coverImageData []byte
|
||||
|
||||
updatedTime := time.Now()
|
||||
updatedScene := models.ScenePartial{
|
||||
ID: sceneID,
|
||||
|
@ -77,6 +80,14 @@ func (r *mutationResolver) sceneUpdate(input models.SceneUpdateInput, tx *sqlx.T
|
|||
if input.Date != nil {
|
||||
updatedScene.Date = &models.SQLiteDate{String: *input.Date, Valid: true}
|
||||
}
|
||||
if input.CoverImage != nil && *input.CoverImage != "" {
|
||||
var err error
|
||||
_, coverImageData, err = utils.ProcessBase64Image(*input.CoverImage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updatedScene.Cover = &coverImageData
|
||||
}
|
||||
|
||||
if input.Rating != nil {
|
||||
updatedScene.Rating = &sql.NullInt64{Int64: int64(*input.Rating), Valid: true}
|
||||
|
@ -151,18 +162,13 @@ func (r *mutationResolver) sceneUpdate(input models.SceneUpdateInput, tx *sqlx.T
|
|||
}
|
||||
|
||||
// only update the cover image if provided and everything else was successful
|
||||
if input.CoverImage != nil && *input.CoverImage != "" {
|
||||
_, imageData, err := utils.ProcessBase64Image(*input.CoverImage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if coverImageData != nil {
|
||||
scene, err := qb.Find(sceneID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = manager.SetSceneScreenshot(scene.Checksum, imageData)
|
||||
err = manager.SetSceneScreenshot(scene.Checksum, coverImageData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
)
|
||||
|
||||
var DB *sqlx.DB
|
||||
var appSchemaVersion uint = 1
|
||||
var appSchemaVersion uint = 2
|
||||
|
||||
const sqlite3Driver = "sqlite3_regexp"
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE `scenes` ADD COLUMN `cover` blob;
|
|
@ -39,6 +39,7 @@ type Scene struct {
|
|||
Tags []string `json:"tags,omitempty"`
|
||||
Markers []SceneMarker `json:"markers,omitempty"`
|
||||
File *SceneFile `json:"file,omitempty"`
|
||||
Cover string `json:"cover,omitempty"`
|
||||
CreatedAt models.JSONTime `json:"created_at,omitempty"`
|
||||
UpdatedAt models.JSONTime `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
|
|
@ -161,6 +161,10 @@ func (t *ExportTask) ExportScenes(ctx context.Context) {
|
|||
newSceneJSON.File.Bitrate = int(scene.Bitrate.Int64)
|
||||
}
|
||||
|
||||
if len(scene.Cover) > 0 {
|
||||
newSceneJSON.Cover = utils.GetBase64StringFromData(scene.Cover)
|
||||
}
|
||||
|
||||
sceneJSON, err := instance.JSON.getScene(scene.Checksum)
|
||||
if err != nil {
|
||||
logger.Debugf("[scenes] error reading scene json: %s", err.Error())
|
||||
|
|
|
@ -382,6 +382,19 @@ func (t *ImportTask) ImportScenes(ctx context.Context) {
|
|||
continue
|
||||
}
|
||||
|
||||
// Process the base 64 encoded cover image string
|
||||
if sceneJSON.Cover != "" {
|
||||
_, coverImageData, err := utils.ProcessBase64Image(sceneJSON.Cover)
|
||||
if err != nil {
|
||||
logger.Warnf("[scenes] <%s> invalid cover image: %s", mappingJSON.Checksum, err.Error())
|
||||
}
|
||||
if len(coverImageData) > 0 {
|
||||
if err = SetSceneScreenshot(mappingJSON.Checksum, coverImageData); err != nil {
|
||||
logger.Warnf("[scenes] <%s> failed to create cover image: %s", mappingJSON.Checksum, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Populate scene fields
|
||||
if sceneJSON != nil {
|
||||
if sceneJSON.Title != "" {
|
||||
|
|
|
@ -9,6 +9,7 @@ type Scene struct {
|
|||
ID int `db:"id" json:"id"`
|
||||
Checksum string `db:"checksum" json:"checksum"`
|
||||
Path string `db:"path" json:"path"`
|
||||
Cover []byte `db:"cover" json:"cover"`
|
||||
Title sql.NullString `db:"title" json:"title"`
|
||||
Details sql.NullString `db:"details" json:"details"`
|
||||
URL sql.NullString `db:"url" json:"url"`
|
||||
|
@ -31,6 +32,7 @@ type ScenePartial struct {
|
|||
ID int `db:"id" json:"id"`
|
||||
Checksum *string `db:"checksum" json:"checksum"`
|
||||
Path *string `db:"path" json:"path"`
|
||||
Cover *[]byte `db:"cover" json:"cover"`
|
||||
Title *sql.NullString `db:"title" json:"title"`
|
||||
Details *sql.NullString `db:"details" json:"details"`
|
||||
URL *sql.NullString `db:"url" json:"url"`
|
||||
|
|
Loading…
Reference in New Issue