mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Persist lightbox settings (#2406)
* Persist lightbox settings in local forage * Add lightbox settings to backend * Add lightbox settings to interface settings page
This commit is contained in:
@@ -286,6 +286,12 @@ func (r *mutationResolver) ConfigureInterface(ctx context.Context, input models.
|
||||
}
|
||||
}
|
||||
|
||||
setString := func(key string, v *string) {
|
||||
if v != nil {
|
||||
c.Set(key, *v)
|
||||
}
|
||||
}
|
||||
|
||||
if input.MenuItems != nil {
|
||||
c.Set(config.MenuItems, input.MenuItems)
|
||||
}
|
||||
@@ -316,8 +322,22 @@ func (r *mutationResolver) ConfigureInterface(ctx context.Context, input models.
|
||||
c.Set(config.Language, *input.Language)
|
||||
}
|
||||
|
||||
// deprecated field
|
||||
if input.SlideshowDelay != nil {
|
||||
c.Set(config.SlideshowDelay, *input.SlideshowDelay)
|
||||
c.Set(config.ImageLightboxSlideshowDelay, *input.SlideshowDelay)
|
||||
}
|
||||
|
||||
if input.ImageLightbox != nil {
|
||||
options := input.ImageLightbox
|
||||
|
||||
if options.SlideshowDelay != nil {
|
||||
c.Set(config.ImageLightboxSlideshowDelay, *options.SlideshowDelay)
|
||||
}
|
||||
|
||||
setString(config.ImageLightboxDisplayMode, (*string)(options.DisplayMode))
|
||||
setBool(config.ImageLightboxScaleUp, options.ScaleUp)
|
||||
setBool(config.ImageLightboxResetZoomOnNav, options.ResetZoomOnNav)
|
||||
setString(config.ImageLightboxScrollMode, (*string)(options.ScrollMode))
|
||||
}
|
||||
|
||||
if input.CSS != nil {
|
||||
|
||||
@@ -140,9 +140,9 @@ func makeConfigInterfaceResult() *models.ConfigInterfaceResult {
|
||||
css := config.GetCSS()
|
||||
cssEnabled := config.GetCSSEnabled()
|
||||
language := config.GetLanguage()
|
||||
slideshowDelay := config.GetSlideshowDelay()
|
||||
handyKey := config.GetHandyKey()
|
||||
scriptOffset := config.GetFunscriptOffset()
|
||||
imageLightboxOptions := config.GetImageLightboxOptions()
|
||||
|
||||
// FIXME - misnamed output field means we have redundant fields
|
||||
disableDropdownCreate := config.GetDisableDropdownCreate()
|
||||
@@ -163,7 +163,8 @@ func makeConfigInterfaceResult() *models.ConfigInterfaceResult {
|
||||
CSS: &css,
|
||||
CSSEnabled: &cssEnabled,
|
||||
Language: &language,
|
||||
SlideshowDelay: &slideshowDelay,
|
||||
|
||||
ImageLightbox: &imageLightboxOptions,
|
||||
|
||||
// FIXME - see above
|
||||
DisabledDropdownCreate: disableDropdownCreate,
|
||||
|
||||
@@ -142,8 +142,15 @@ const (
|
||||
WallPlayback = "wall_playback"
|
||||
defaultWallPlayback = "video"
|
||||
|
||||
SlideshowDelay = "slideshow_delay"
|
||||
defaultSlideshowDelay = 5000
|
||||
// Image lightbox options
|
||||
legacyImageLightboxSlideshowDelay = "slideshow_delay"
|
||||
ImageLightboxSlideshowDelay = "image_lightbox.slideshow_delay"
|
||||
ImageLightboxDisplayMode = "image_lightbox.display_mode"
|
||||
ImageLightboxScaleUp = "image_lightbox.scale_up"
|
||||
ImageLightboxResetZoomOnNav = "image_lightbox.reset_zoom_on_nav"
|
||||
ImageLightboxScrollMode = "image_lightbox.scroll_mode"
|
||||
|
||||
defaultImageLightboxSlideshowDelay = 5000
|
||||
|
||||
DisableDropdownCreatePerformer = "disable_dropdown_create.performer"
|
||||
DisableDropdownCreateStudio = "disable_dropdown_create.studio"
|
||||
@@ -364,6 +371,18 @@ func (i *Instance) viper(key string) *viper.Viper {
|
||||
return v
|
||||
}
|
||||
|
||||
// viper returns the viper instance that has the key set. Returns nil
|
||||
// if no instance has the key. Assumes read lock held.
|
||||
func (i *Instance) viperWith(key string) *viper.Viper {
|
||||
v := i.viper(key)
|
||||
|
||||
if v.IsSet(key) {
|
||||
return v
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Instance) HasOverride(key string) bool {
|
||||
i.RLock()
|
||||
defer i.RUnlock()
|
||||
@@ -886,14 +905,49 @@ func (i *Instance) GetShowStudioAsText() bool {
|
||||
return i.getBool(ShowStudioAsText)
|
||||
}
|
||||
|
||||
func (i *Instance) GetSlideshowDelay() int {
|
||||
func (i *Instance) getSlideshowDelay() int {
|
||||
// assume have lock
|
||||
|
||||
ret := defaultImageLightboxSlideshowDelay
|
||||
v := i.viper(ImageLightboxSlideshowDelay)
|
||||
if v.IsSet(ImageLightboxSlideshowDelay) {
|
||||
ret = v.GetInt(ImageLightboxSlideshowDelay)
|
||||
} else {
|
||||
// fallback to old location
|
||||
v := i.viper(legacyImageLightboxSlideshowDelay)
|
||||
if v.IsSet(legacyImageLightboxSlideshowDelay) {
|
||||
ret = v.GetInt(legacyImageLightboxSlideshowDelay)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (i *Instance) GetImageLightboxOptions() models.ConfigImageLightboxResult {
|
||||
i.RLock()
|
||||
defer i.RUnlock()
|
||||
|
||||
ret := defaultSlideshowDelay
|
||||
v := i.viper(SlideshowDelay)
|
||||
if v.IsSet(SlideshowDelay) {
|
||||
ret = v.GetInt(SlideshowDelay)
|
||||
delay := i.getSlideshowDelay()
|
||||
|
||||
ret := models.ConfigImageLightboxResult{
|
||||
SlideshowDelay: &delay,
|
||||
}
|
||||
|
||||
if v := i.viperWith(ImageLightboxDisplayMode); v != nil {
|
||||
mode := models.ImageLightboxDisplayMode(v.GetString(ImageLightboxDisplayMode))
|
||||
ret.DisplayMode = &mode
|
||||
}
|
||||
if v := i.viperWith(ImageLightboxScaleUp); v != nil {
|
||||
value := v.GetBool(ImageLightboxScaleUp)
|
||||
ret.ScaleUp = &value
|
||||
}
|
||||
if v := i.viperWith(ImageLightboxResetZoomOnNav); v != nil {
|
||||
value := v.GetBool(ImageLightboxResetZoomOnNav)
|
||||
ret.ResetZoomOnNav = &value
|
||||
}
|
||||
if v := i.viperWith(ImageLightboxScrollMode); v != nil {
|
||||
mode := models.ImageLightboxScrollMode(v.GetString(ImageLightboxScrollMode))
|
||||
ret.ScrollMode = &mode
|
||||
}
|
||||
|
||||
return ret
|
||||
|
||||
@@ -81,7 +81,8 @@ func TestConcurrentConfigAccess(t *testing.T) {
|
||||
i.Set(MaximumLoopDuration, i.GetMaximumLoopDuration())
|
||||
i.Set(AutostartVideo, i.GetAutostartVideo())
|
||||
i.Set(ShowStudioAsText, i.GetShowStudioAsText())
|
||||
i.Set(SlideshowDelay, i.GetSlideshowDelay())
|
||||
i.Set(legacyImageLightboxSlideshowDelay, *i.GetImageLightboxOptions().SlideshowDelay)
|
||||
i.Set(ImageLightboxSlideshowDelay, *i.GetImageLightboxOptions().SlideshowDelay)
|
||||
i.GetCSSPath()
|
||||
i.GetCSS()
|
||||
i.Set(CSSEnabled, i.GetCSSEnabled())
|
||||
|
||||
Reference in New Issue
Block a user