mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Separate graphql API from rest of the system (#2503)
* Move graphql generated files to api * Refactor identify options * Remove models.StashBoxes * Move ScraperSource to scraper package * Rename field strategy enums * Rename identify.TaskOptions to Options
This commit is contained in:
@@ -2,11 +2,55 @@ package manager
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
type ImportDuplicateEnum string
|
||||
|
||||
const (
|
||||
ImportDuplicateEnumIgnore ImportDuplicateEnum = "IGNORE"
|
||||
ImportDuplicateEnumOverwrite ImportDuplicateEnum = "OVERWRITE"
|
||||
ImportDuplicateEnumFail ImportDuplicateEnum = "FAIL"
|
||||
)
|
||||
|
||||
var AllImportDuplicateEnum = []ImportDuplicateEnum{
|
||||
ImportDuplicateEnumIgnore,
|
||||
ImportDuplicateEnumOverwrite,
|
||||
ImportDuplicateEnumFail,
|
||||
}
|
||||
|
||||
func (e ImportDuplicateEnum) IsValid() bool {
|
||||
switch e {
|
||||
case ImportDuplicateEnumIgnore, ImportDuplicateEnumOverwrite, ImportDuplicateEnumFail:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e ImportDuplicateEnum) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e *ImportDuplicateEnum) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = ImportDuplicateEnum(str)
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid ImportDuplicateEnum", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e ImportDuplicateEnum) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||
}
|
||||
|
||||
type importer interface {
|
||||
PreImport() error
|
||||
PostImport(id int) error
|
||||
@@ -16,7 +60,7 @@ type importer interface {
|
||||
Update(id int) error
|
||||
}
|
||||
|
||||
func performImport(i importer, duplicateBehaviour models.ImportDuplicateEnum) error {
|
||||
func performImport(i importer, duplicateBehaviour ImportDuplicateEnum) error {
|
||||
if err := i.PreImport(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -31,9 +75,9 @@ func performImport(i importer, duplicateBehaviour models.ImportDuplicateEnum) er
|
||||
var id int
|
||||
|
||||
if existing != nil {
|
||||
if duplicateBehaviour == models.ImportDuplicateEnumFail {
|
||||
if duplicateBehaviour == ImportDuplicateEnumFail {
|
||||
return fmt.Errorf("existing object with name '%s'", name)
|
||||
} else if duplicateBehaviour == models.ImportDuplicateEnumIgnore {
|
||||
} else if duplicateBehaviour == ImportDuplicateEnumIgnore {
|
||||
logger.Info("Skipping existing object")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user