-
-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into postgres-support-2
- Loading branch information
Showing
38 changed files
with
1,619 additions
and
828 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package jsonschema | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
jsoniter "github.com/json-iterator/go" | ||
) | ||
|
||
func loadFile[T any](filePath string) (*T, error) { | ||
var ret T | ||
file, err := os.Open(filePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer file.Close() | ||
var json = jsoniter.ConfigCompatibleWithStandardLibrary | ||
jsonParser := json.NewDecoder(file) | ||
err = jsonParser.Decode(&ret) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &ret, nil | ||
} | ||
|
||
func saveFile[T any](filePath string, obj *T) error { | ||
if obj == nil { | ||
return fmt.Errorf("object must not be nil") | ||
} | ||
return marshalToFile(filePath, obj) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package jsonschema | ||
|
||
import ( | ||
"github.com/stashapp/stash/pkg/fsutil" | ||
"github.com/stashapp/stash/pkg/models" | ||
) | ||
|
||
type SavedFilter struct { | ||
Mode models.FilterMode `db:"mode" json:"mode"` | ||
Name string `db:"name" json:"name"` | ||
FindFilter *models.FindFilterType `json:"find_filter"` | ||
ObjectFilter map[string]interface{} `json:"object_filter"` | ||
UIOptions map[string]interface{} `json:"ui_options"` | ||
} | ||
|
||
func (s SavedFilter) Filename() string { | ||
ret := fsutil.SanitiseBasename(s.Name + "_" + s.Mode.String()) | ||
return ret + ".json" | ||
} | ||
|
||
func LoadSavedFilterFile(filePath string) (*SavedFilter, error) { | ||
return loadFile[SavedFilter](filePath) | ||
} | ||
|
||
func SaveSavedFilterFile(filePath string, image *SavedFilter) error { | ||
return saveFile[SavedFilter](filePath, image) | ||
} |
Oops, something went wrong.