// Copyright 2026 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package setting import ( "time" "git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/setting/config" ) // WebBannerType fields are directly used in templates, // do remember to update the template if you change the fields type WebBannerType struct { DisplayEnabled bool ContentMessage string StartTimeUnix int64 EndTimeUnix int64 } func (b WebBannerType) ShouldDisplay() bool { if !b.DisplayEnabled || b.ContentMessage == "" { return false } now := time.Now().Unix() if b.StartTimeUnix > 0 && now < b.StartTimeUnix { return false } if b.EndTimeUnix > 0 && now > b.EndTimeUnix { return false } return true } type MaintenanceModeType struct { AdminWebAccessOnly bool StartTimeUnix int64 EndTimeUnix int64 } func (m MaintenanceModeType) IsActive() bool { if !m.AdminWebAccessOnly { return false } now := time.Now().Unix() if m.StartTimeUnix > 0 && now < m.StartTimeUnix { return false } if m.EndTimeUnix > 0 && now > m.EndTimeUnix { return false } return true } // LandingPageType configures the default page for unauthenticated visitors. // Mode values: "home", "explore", "organizations", "login", or "custom". // When Mode is "custom", CustomPath holds the redirect target (e.g. "/MokoConsulting"). type LandingPageType struct { Mode string // home, explore, organizations, login, custom CustomPath string // only used when Mode == "custom" } // URL returns the redirect path for the configured landing page. func (lp LandingPageType) URL() string { switch lp.Mode { case "explore": return "/explore" case "organizations": return "/explore/organizations" case "login": return "/user/login" case "custom": if lp.CustomPath != "" { return lp.CustomPath } return "/" default: return "/" } } type InstanceStruct struct { WebBanner *config.Option[WebBannerType] MaintenanceMode *config.Option[MaintenanceModeType] LandingPage *config.Option[LandingPageType] }