aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2023-01-05 19:32:29 -0500
committerpg9182 <96569817+pg9182@users.noreply.github.com>2023-01-05 21:29:18 -0500
commit440acd2442215f4edc9f82e881adcf10be728879 (patch)
tree52916d0c1b5630109888462189a8e488f37ac1ab
parentdac5f7e0a513d8cebe8ad2f4161a4c73ba72bee7 (diff)
downloadAtlas-440acd2442215f4edc9f82e881adcf10be728879.tar.gz
Atlas-440acd2442215f4edc9f82e881adcf10be728879.zip
pkg/atlas: Implement mainmenupromos override for outdated clients
-rw-r--r--pkg/atlas/config.go5
-rw-r--r--pkg/atlas/server.go36
2 files changed, 41 insertions, 0 deletions
diff --git a/pkg/atlas/config.go b/pkg/atlas/config.go
index 4300d04..a416ff7 100644
--- a/pkg/atlas/config.go
+++ b/pkg/atlas/config.go
@@ -145,6 +145,11 @@ type Config struct {
// - file:/path/to/mainmenupromos.json
API0_MainMenuPromos string `env:"ATLAS_API0_MAINMENUPROMOS=none"`
+ // If provided, the mainmenupromos will be merged with the provided source
+ // (same syntax as API0_MAINEMENUPROMOS) if the client is older than the
+ // API0_MinimumLauncherVersion.
+ API0_MainMenuPromos_UpdateNeeded string `env:"ATLAS_API0_MAINMENUPROMOS_UPDATENEEDED"`
+
// The email address to use for Origin login. If not provided, usernames are
// not resolved during authentication. If it begins with @, it is treated
// as the name of a systemd credential to load.
diff --git a/pkg/atlas/server.go b/pkg/atlas/server.go
index e780b87..d1f7c7d 100644
--- a/pkg/atlas/server.go
+++ b/pkg/atlas/server.go
@@ -299,6 +299,9 @@ func NewServer(c *Config) (*Server, error) {
} else {
return nil, fmt.Errorf("initialize main menu promos: %w", err)
}
+ if err := configureMainMenuPromosUpdateNeeded(c, s.API0); err != nil {
+ return nil, fmt.Errorf("configure main menu promos when update needed: %w", err)
+ }
if ip2l, err := configureIP2Location(c); err == nil {
if ip2l != nil {
s.reload = append(s.reload, func() {
@@ -685,6 +688,39 @@ func configureMainMenuPromos(c *Config) (func(*http.Request) api0.MainMenuPromos
}
}
+func configureMainMenuPromosUpdateNeeded(c *Config, h *api0.Handler) error {
+ switch typ, arg, _ := strings.Cut(c.API0_MainMenuPromos_UpdateNeeded, ":"); typ {
+ case "none":
+ return nil
+ case "file":
+ p, err := filepath.Abs(arg)
+ if err != nil {
+ return fmt.Errorf("file: resolve %q: %w", arg, err)
+ }
+ fn1 := h.MainMenuPromos
+ h.MainMenuPromos = func(r *http.Request) api0.MainMenuPromos {
+ var mmp api0.MainMenuPromos
+ if fn1 != nil {
+ mmp = fn1(r)
+ }
+ if r == nil || !h.CheckLauncherVersion(r) {
+ if buf, err1 := os.ReadFile(p); err1 != nil {
+ err = err1
+ } else if err = json.Unmarshal(buf, &mmp); err != nil {
+ err = err1
+ }
+ }
+ return mmp
+ }
+ if h.MainMenuPromos(nil); err != nil {
+ return fmt.Errorf("file: %w", err)
+ }
+ return nil
+ default:
+ return fmt.Errorf("unknown source %q", typ)
+ }
+}
+
func configureIP2Location(c *Config) (*ip2xMgr, error) {
if c.IP2Location == "" {
return nil, nil