2019-03-23 14:56:59 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2019-07-28 09:36:52 +00:00
|
|
|
"path/filepath"
|
|
|
|
|
2019-10-25 00:13:44 +00:00
|
|
|
"github.com/stashapp/stash/pkg/logger"
|
2019-11-17 21:42:24 +00:00
|
|
|
"github.com/stashapp/stash/pkg/manager"
|
2019-11-04 21:38:33 +00:00
|
|
|
"github.com/stashapp/stash/pkg/manager/config"
|
2019-03-23 14:56:59 +00:00
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
|
|
"github.com/stashapp/stash/pkg/utils"
|
|
|
|
)
|
|
|
|
|
2019-03-26 15:35:06 +00:00
|
|
|
func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input models.ConfigGeneralInput) (*models.ConfigGeneralResult, error) {
|
2019-03-23 14:56:59 +00:00
|
|
|
if len(input.Stashes) > 0 {
|
|
|
|
for _, stashPath := range input.Stashes {
|
|
|
|
exists, err := utils.DirExists(stashPath)
|
|
|
|
if !exists {
|
|
|
|
return makeConfigGeneralResult(), err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
config.Set(config.Stash, input.Stashes)
|
|
|
|
}
|
|
|
|
|
2019-03-24 17:04:31 +00:00
|
|
|
if input.DatabasePath != nil {
|
|
|
|
ext := filepath.Ext(*input.DatabasePath)
|
|
|
|
if ext != ".db" && ext != ".sqlite" && ext != ".sqlite3" {
|
|
|
|
return makeConfigGeneralResult(), fmt.Errorf("invalid database path, use extension db, sqlite, or sqlite3")
|
|
|
|
}
|
|
|
|
config.Set(config.Database, input.DatabasePath)
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.GeneratedPath != nil {
|
|
|
|
if err := utils.EnsureDir(*input.GeneratedPath); err != nil {
|
|
|
|
return makeConfigGeneralResult(), err
|
|
|
|
}
|
|
|
|
config.Set(config.Generated, input.GeneratedPath)
|
|
|
|
}
|
|
|
|
|
2019-11-04 21:38:33 +00:00
|
|
|
if input.MaxTranscodeSize != nil {
|
|
|
|
config.Set(config.MaxTranscodeSize, input.MaxTranscodeSize.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.MaxStreamingTranscodeSize != nil {
|
|
|
|
config.Set(config.MaxStreamingTranscodeSize, input.MaxStreamingTranscodeSize.String())
|
|
|
|
}
|
|
|
|
|
2019-07-28 09:36:52 +00:00
|
|
|
if input.Username != nil {
|
|
|
|
config.Set(config.Username, input.Username)
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.Password != nil {
|
|
|
|
// bit of a hack - check if the passed in password is the same as the stored hash
|
|
|
|
// and only set if they are different
|
|
|
|
currentPWHash := config.GetPasswordHash()
|
|
|
|
|
|
|
|
if *input.Password != currentPWHash {
|
|
|
|
config.SetPassword(*input.Password)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 00:13:44 +00:00
|
|
|
if input.LogFile != nil {
|
|
|
|
config.Set(config.LogFile, input.LogFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Set(config.LogOut, input.LogOut)
|
|
|
|
config.Set(config.LogAccess, input.LogAccess)
|
|
|
|
|
|
|
|
if input.LogLevel != config.GetLogLevel() {
|
|
|
|
config.Set(config.LogLevel, input.LogLevel)
|
|
|
|
logger.SetLogLevel(input.LogLevel)
|
|
|
|
}
|
|
|
|
|
2019-03-23 14:56:59 +00:00
|
|
|
if err := config.Write(); err != nil {
|
|
|
|
return makeConfigGeneralResult(), err
|
|
|
|
}
|
|
|
|
|
2019-11-17 21:42:24 +00:00
|
|
|
manager.GetInstance().RefreshConfig()
|
|
|
|
|
2019-03-23 14:56:59 +00:00
|
|
|
return makeConfigGeneralResult(), nil
|
|
|
|
}
|
2019-08-22 22:24:14 +00:00
|
|
|
|
|
|
|
func (r *mutationResolver) ConfigureInterface(ctx context.Context, input models.ConfigInterfaceInput) (*models.ConfigInterfaceResult, error) {
|
2019-11-29 01:41:17 +00:00
|
|
|
if input.SoundOnPreview != nil {
|
|
|
|
config.Set(config.SoundOnPreview, *input.SoundOnPreview)
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.WallShowTitle != nil {
|
|
|
|
config.Set(config.WallShowTitle, *input.WallShowTitle)
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.MaximumLoopDuration != nil {
|
|
|
|
config.Set(config.MaximumLoopDuration, *input.MaximumLoopDuration)
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.AutostartVideo != nil {
|
|
|
|
config.Set(config.AutostartVideo, *input.AutostartVideo)
|
|
|
|
}
|
|
|
|
|
2019-12-05 17:24:22 +00:00
|
|
|
if input.ShowStudioAsText != nil {
|
|
|
|
config.Set(config.ShowStudioAsText, *input.ShowStudioAsText)
|
|
|
|
}
|
|
|
|
|
2019-08-22 22:24:14 +00:00
|
|
|
css := ""
|
|
|
|
|
|
|
|
if input.CSS != nil {
|
|
|
|
css = *input.CSS
|
|
|
|
}
|
|
|
|
|
|
|
|
config.SetCSS(css)
|
|
|
|
|
|
|
|
if input.CSSEnabled != nil {
|
|
|
|
config.Set(config.CSSEnabled, *input.CSSEnabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := config.Write(); err != nil {
|
|
|
|
return makeConfigInterfaceResult(), err
|
|
|
|
}
|
|
|
|
|
|
|
|
return makeConfigInterfaceResult(), nil
|
|
|
|
}
|