mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +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:
@@ -4,9 +4,11 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -30,6 +32,67 @@ import (
|
||||
"github.com/stashapp/stash/ui"
|
||||
)
|
||||
|
||||
type SystemStatus struct {
|
||||
DatabaseSchema *int `json:"databaseSchema"`
|
||||
DatabasePath *string `json:"databasePath"`
|
||||
ConfigPath *string `json:"configPath"`
|
||||
AppSchema int `json:"appSchema"`
|
||||
Status SystemStatusEnum `json:"status"`
|
||||
}
|
||||
|
||||
type SystemStatusEnum string
|
||||
|
||||
const (
|
||||
SystemStatusEnumSetup SystemStatusEnum = "SETUP"
|
||||
SystemStatusEnumNeedsMigration SystemStatusEnum = "NEEDS_MIGRATION"
|
||||
SystemStatusEnumOk SystemStatusEnum = "OK"
|
||||
)
|
||||
|
||||
var AllSystemStatusEnum = []SystemStatusEnum{
|
||||
SystemStatusEnumSetup,
|
||||
SystemStatusEnumNeedsMigration,
|
||||
SystemStatusEnumOk,
|
||||
}
|
||||
|
||||
func (e SystemStatusEnum) IsValid() bool {
|
||||
switch e {
|
||||
case SystemStatusEnumSetup, SystemStatusEnumNeedsMigration, SystemStatusEnumOk:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e SystemStatusEnum) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e *SystemStatusEnum) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = SystemStatusEnum(str)
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid SystemStatusEnum", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e SystemStatusEnum) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||
}
|
||||
|
||||
type SetupInput struct {
|
||||
// Empty to indicate $HOME/.stash/config.yml default
|
||||
ConfigLocation string `json:"configLocation"`
|
||||
Stashes []*config.StashConfigInput `json:"stashes"`
|
||||
// Empty to indicate default
|
||||
DatabaseFile string `json:"databaseFile"`
|
||||
// Empty to indicate default
|
||||
GeneratedLocation string `json:"generatedLocation"`
|
||||
}
|
||||
|
||||
type Manager struct {
|
||||
Config *config.Instance
|
||||
Logger *log.Logger
|
||||
@@ -354,7 +417,7 @@ func (s *Manager) RefreshScraperCache() {
|
||||
s.ScraperCache = s.initScraperCache()
|
||||
}
|
||||
|
||||
func setSetupDefaults(input *models.SetupInput) {
|
||||
func setSetupDefaults(input *SetupInput) {
|
||||
if input.ConfigLocation == "" {
|
||||
input.ConfigLocation = filepath.Join(fsutil.GetHomeDirectory(), ".stash", "config.yml")
|
||||
}
|
||||
@@ -369,7 +432,7 @@ func setSetupDefaults(input *models.SetupInput) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Manager) Setup(ctx context.Context, input models.SetupInput) error {
|
||||
func (s *Manager) Setup(ctx context.Context, input SetupInput) error {
|
||||
setSetupDefaults(&input)
|
||||
c := s.Config
|
||||
|
||||
@@ -433,7 +496,11 @@ func (s *Manager) validateFFMPEG() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Manager) Migrate(ctx context.Context, input models.MigrateInput) error {
|
||||
type MigrateInput struct {
|
||||
BackupPath string `json:"backupPath"`
|
||||
}
|
||||
|
||||
func (s *Manager) Migrate(ctx context.Context, input MigrateInput) error {
|
||||
// always backup so that we can roll back to the previous version if
|
||||
// migration fails
|
||||
backupPath := input.BackupPath
|
||||
@@ -473,20 +540,20 @@ func (s *Manager) Migrate(ctx context.Context, input models.MigrateInput) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Manager) GetSystemStatus() *models.SystemStatus {
|
||||
status := models.SystemStatusEnumOk
|
||||
func (s *Manager) GetSystemStatus() *SystemStatus {
|
||||
status := SystemStatusEnumOk
|
||||
dbSchema := int(database.Version())
|
||||
dbPath := database.DatabasePath()
|
||||
appSchema := int(database.AppSchemaVersion())
|
||||
configFile := s.Config.GetConfigFile()
|
||||
|
||||
if s.Config.IsNewSystem() {
|
||||
status = models.SystemStatusEnumSetup
|
||||
status = SystemStatusEnumSetup
|
||||
} else if dbSchema < appSchema {
|
||||
status = models.SystemStatusEnumNeedsMigration
|
||||
status = SystemStatusEnumNeedsMigration
|
||||
}
|
||||
|
||||
return &models.SystemStatus{
|
||||
return &SystemStatus{
|
||||
DatabaseSchema: &dbSchema,
|
||||
DatabasePath: &dbPath,
|
||||
AppSchema: appSchema,
|
||||
|
||||
Reference in New Issue
Block a user