2019-02-09 12:30:49 +00:00
|
|
|
package jsonschema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2020-06-15 11:34:39 +00:00
|
|
|
|
|
|
|
jsoniter "github.com/json-iterator/go"
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
2019-02-09 12:30:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Studio struct {
|
2020-06-15 11:34:39 +00:00
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
ParentStudio string `json:"parent_studio,omitempty"`
|
|
|
|
Image string `json:"image,omitempty"`
|
|
|
|
CreatedAt models.JSONTime `json:"created_at,omitempty"`
|
|
|
|
UpdatedAt models.JSONTime `json:"updated_at,omitempty"`
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadStudioFile(filePath string) (*Studio, error) {
|
|
|
|
var studio Studio
|
|
|
|
file, err := os.Open(filePath)
|
|
|
|
defer file.Close()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-04-24 02:52:21 +00:00
|
|
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
2019-02-09 12:30:49 +00:00
|
|
|
jsonParser := json.NewDecoder(file)
|
|
|
|
err = jsonParser.Decode(&studio)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &studio, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func SaveStudioFile(filePath string, studio *Studio) error {
|
|
|
|
if studio == nil {
|
|
|
|
return fmt.Errorf("studio must not be nil")
|
|
|
|
}
|
|
|
|
return marshalToFile(filePath, studio)
|
2019-02-14 22:53:32 +00:00
|
|
|
}
|