2019-03-23 14:56:59 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-08-06 01:21:14 +00:00
|
|
|
"errors"
|
2019-03-23 14:56:59 +00:00
|
|
|
"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)
|
|
|
|
}
|
|
|
|
|
2020-05-11 07:20:08 +00:00
|
|
|
if input.CachePath != nil {
|
|
|
|
if err := utils.EnsureDir(*input.CachePath); err != nil {
|
|
|
|
return makeConfigGeneralResult(), err
|
|
|
|
}
|
|
|
|
config.Set(config.Cache, input.CachePath)
|
|
|
|
}
|
|
|
|
|
2020-08-06 01:21:14 +00:00
|
|
|
if !input.CalculateMd5 && input.VideoFileNamingAlgorithm == models.HashAlgorithmMd5 {
|
|
|
|
return makeConfigGeneralResult(), errors.New("calculateMD5 must be true if using MD5")
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.VideoFileNamingAlgorithm != config.GetVideoFileNamingAlgorithm() {
|
|
|
|
// validate changing VideoFileNamingAlgorithm
|
|
|
|
if err := manager.ValidateVideoFileNamingAlgorithm(input.VideoFileNamingAlgorithm); err != nil {
|
|
|
|
return makeConfigGeneralResult(), err
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Set(config.VideoFileNamingAlgorithm, input.VideoFileNamingAlgorithm)
|
|
|
|
}
|
|
|
|
|
|
|
|
config.Set(config.CalculateMD5, input.CalculateMd5)
|
|
|
|
|
2020-07-23 02:51:35 +00:00
|
|
|
if input.PreviewSegments != nil {
|
|
|
|
config.Set(config.PreviewSegments, *input.PreviewSegments)
|
|
|
|
}
|
|
|
|
if input.PreviewSegmentDuration != nil {
|
|
|
|
config.Set(config.PreviewSegmentDuration, *input.PreviewSegmentDuration)
|
|
|
|
}
|
|
|
|
if input.PreviewExcludeStart != nil {
|
|
|
|
config.Set(config.PreviewExcludeStart, *input.PreviewExcludeStart)
|
|
|
|
}
|
|
|
|
if input.PreviewExcludeEnd != nil {
|
|
|
|
config.Set(config.PreviewExcludeEnd, *input.PreviewExcludeEnd)
|
|
|
|
}
|
2020-07-19 01:59:18 +00:00
|
|
|
if input.PreviewPreset != nil {
|
|
|
|
config.Set(config.PreviewPreset, input.PreviewPreset.String())
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 02:51:12 +00:00
|
|
|
if input.MaxSessionAge != nil {
|
|
|
|
config.Set(config.MaxSessionAge, *input.MaxSessionAge)
|
|
|
|
}
|
|
|
|
|
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-12-17 14:26:16 +00:00
|
|
|
if input.Excludes != nil {
|
|
|
|
config.Set(config.Exclude, input.Excludes)
|
|
|
|
}
|
|
|
|
|
2020-08-04 00:42:40 +00:00
|
|
|
refreshScraperCache := false
|
2020-03-20 21:55:15 +00:00
|
|
|
if input.ScraperUserAgent != nil {
|
|
|
|
config.Set(config.ScraperUserAgent, input.ScraperUserAgent)
|
2020-08-04 00:42:40 +00:00
|
|
|
refreshScraperCache = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.ScraperCDPPath != nil {
|
|
|
|
config.Set(config.ScraperCDPPath, input.ScraperCDPPath)
|
|
|
|
refreshScraperCache = true
|
2020-03-20 21:55:15 +00:00
|
|
|
}
|
|
|
|
|
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()
|
2020-08-04 00:42:40 +00:00
|
|
|
if refreshScraperCache {
|
|
|
|
manager.GetInstance().RefreshScraperCache()
|
|
|
|
}
|
2019-11-17 21:42:24 +00:00
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-05-26 23:33:49 +00:00
|
|
|
if input.WallPlayback != nil {
|
|
|
|
config.Set(config.WallPlayback, *input.WallPlayback)
|
|
|
|
}
|
|
|
|
|
2019-11-29 01:41:17 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-02-06 21:42:29 +00:00
|
|
|
if input.Language != nil {
|
|
|
|
config.Set(config.Language, *input.Language)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|