2019-02-09 12:30:49 +00:00
|
|
|
package jsonschema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2020-07-07 00:35:43 +00:00
|
|
|
|
|
|
|
jsoniter "github.com/json-iterator/go"
|
2019-02-09 12:30:49 +00:00
|
|
|
)
|
|
|
|
|
2020-10-12 23:12:46 +00:00
|
|
|
type PathNameMapping struct {
|
|
|
|
Path string `json:"path,omitempty"`
|
|
|
|
Name string `json:"name,omitempty"`
|
2019-02-09 12:30:49 +00:00
|
|
|
Checksum string `json:"checksum"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Mappings struct {
|
2020-10-12 23:12:46 +00:00
|
|
|
Tags []PathNameMapping `json:"tags"`
|
|
|
|
Performers []PathNameMapping `json:"performers"`
|
|
|
|
Studios []PathNameMapping `json:"studios"`
|
|
|
|
Movies []PathNameMapping `json:"movies"`
|
|
|
|
Galleries []PathNameMapping `json:"galleries"`
|
|
|
|
Scenes []PathNameMapping `json:"scenes"`
|
|
|
|
Images []PathNameMapping `json:"images"`
|
2019-02-09 12:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadMappingsFile(filePath string) (*Mappings, error) {
|
|
|
|
var mappings Mappings
|
|
|
|
file, err := os.Open(filePath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-05-24 21:52:55 +00:00
|
|
|
defer file.Close()
|
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(&mappings)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &mappings, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func SaveMappingsFile(filePath string, mappings *Mappings) error {
|
|
|
|
if mappings == nil {
|
|
|
|
return fmt.Errorf("mappings must not be nil")
|
|
|
|
}
|
|
|
|
return marshalToFile(filePath, mappings)
|
|
|
|
}
|