mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
Fix Synopsis json string in movie jsonschema (#2664)
* Fix Synopsis json string in movie jsonschema * backwards compatible movie synopsis import
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
|
||||||
|
"github.com/stashapp/stash/pkg/logger"
|
||||||
"github.com/stashapp/stash/pkg/models/json"
|
"github.com/stashapp/stash/pkg/models/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -15,7 +17,7 @@ type Movie struct {
|
|||||||
Date string `json:"date,omitempty"`
|
Date string `json:"date,omitempty"`
|
||||||
Rating int `json:"rating,omitempty"`
|
Rating int `json:"rating,omitempty"`
|
||||||
Director string `json:"director,omitempty"`
|
Director string `json:"director,omitempty"`
|
||||||
Synopsis string `json:"sypnopsis,omitempty"`
|
Synopsis string `json:"synopsis,omitempty"`
|
||||||
FrontImage string `json:"front_image,omitempty"`
|
FrontImage string `json:"front_image,omitempty"`
|
||||||
BackImage string `json:"back_image,omitempty"`
|
BackImage string `json:"back_image,omitempty"`
|
||||||
URL string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
@@ -24,6 +26,11 @@ type Movie struct {
|
|||||||
UpdatedAt json.JSONTime `json:"updated_at,omitempty"`
|
UpdatedAt json.JSONTime `json:"updated_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backwards Compatible synopsis for the movie
|
||||||
|
type MovieSynopsisBC struct {
|
||||||
|
Synopsis string `json:"sypnopsis,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
func LoadMovieFile(filePath string) (*Movie, error) {
|
func LoadMovieFile(filePath string) (*Movie, error) {
|
||||||
var movie Movie
|
var movie Movie
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
@@ -37,6 +44,22 @@ func LoadMovieFile(filePath string) (*Movie, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if movie.Synopsis == "" {
|
||||||
|
// keep backwards compatibility with pre #2664 builds
|
||||||
|
// attempt to get the synopsis from the alternate (sypnopsis) key
|
||||||
|
|
||||||
|
_, err = file.Seek(0, 0) // seek to start of file
|
||||||
|
if err == nil {
|
||||||
|
var synopsis MovieSynopsisBC
|
||||||
|
err = jsonParser.Decode(&synopsis)
|
||||||
|
if err == nil {
|
||||||
|
movie.Synopsis = synopsis.Synopsis
|
||||||
|
if movie.Synopsis != "" {
|
||||||
|
logger.Debug("Movie synopsis retrieved from alternate key")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return &movie, nil
|
return &movie, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user