Files
Watcharr/server/middleware.go
stignarnia c5d817c68c Ability to set a country, both in server and user settings, to have the correct streaming provider (but doesn't affect language) (#463)
* Country support for watch providers (#1, not functional)

* frontend dropdowns now actually read and write the correct setting

* user country setting now respects the server side default when creating a new user

* watch providers correctly show based on country, but changing the coutnry requires restarting the container to take effect

* flushing cache when updating user settings

* non functional, initial support for getting all the countries of which tmdb has streaming providers for to let users pick one

* users get shown a list of country codes to pick from and the selection gets saved and used, but the dropdown menu doesn't allow for scrolling

* limited dropdown height and auto scroll to the letter the user hits

* simplified auto scroll code

* the dropdown to choose countries now shows their full english name

* server/user region improvements

* DropDown: remove console log

used to test

* DropDown: Add keypress event listener on main div

instead of document body, so only triggered when key pressed whilst focused on dropdown.

---------

Co-authored-by: Stig <stig.narnia@gmail.com>
Co-authored-by: IRHM <37304121+IRHM@users.noreply.github.com>
2024-04-14 02:57:51 +00:00

32 lines
787 B
Go

package main
import (
"log/slog"
"github.com/gin-gonic/gin"
)
// Location middleware
func WhereaboutsRequired() gin.HandlerFunc {
return func(c *gin.Context) {
region := c.Query("region")
slog.Debug("WhereaboutsRequired: middleware hit", "region", region)
if region == "" {
// If no region is passed, default to server region.
if Config.DEFAULT_COUNTRY != "" {
slog.Debug("WhereaboutsRequired: Using server default country.", "default_country", Config.DEFAULT_COUNTRY)
c.Set("userCountry", Config.DEFAULT_COUNTRY)
c.Next()
return
}
// If no server region set, default to US.
slog.Debug("WhereaboutsRequired: Using hard coded default (US).")
c.Set("userCountry", "US")
c.Next()
return
}
c.Set("userCountry", region)
c.Next()
}
}