mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-05 21:58:07 -06:00
[feature] Allow user to show instead of landing page on / (#922)
* configurable user instead of landing page * rename DefaultUser to LandingPageUser * code review changes and fix tests * try to fix pipeline error * code review changes * code review changes * code review changes * remove unnecessary line
This commit is contained in:
parent
c4c713988a
commit
f3fc040c2e
10 changed files with 56 additions and 13 deletions
|
|
@ -47,6 +47,7 @@ type Configuration struct {
|
|||
LogLevel string `name:"log-level" usage:"Log level to run at: [trace, debug, info, warn, fatal]"`
|
||||
LogDbQueries bool `name:"log-db-queries" usage:"Log database queries verbosely when log-level is trace or debug"`
|
||||
ApplicationName string `name:"application-name" usage:"Name of the application, used in various places internally"`
|
||||
LandingPageUser string `name:"landing-page-user" usage:"the user that should be shown on the instance's landing page"`
|
||||
ConfigPath string `name:"config-path" usage:"Path to a file containing gotosocial configuration. Values set in this file will be overwritten by values set as env vars or arguments"`
|
||||
Host string `name:"host" usage:"Hostname to use for the server (eg., example.org, gotosocial.whatever.com). DO NOT change this on a server that's already run!"`
|
||||
AccountDomain string `name:"account-domain" usage:"Domain to use in account names (eg., example.org, whatever.com). If not set, will default to the setting for host. DO NOT change this on a server that's already run!"`
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ var Defaults = Configuration{
|
|||
LogLevel: "info",
|
||||
LogDbQueries: false,
|
||||
ApplicationName: "gotosocial",
|
||||
LandingPageUser: "",
|
||||
ConfigPath: "",
|
||||
Host: "",
|
||||
AccountDomain: "",
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ func AddGlobalFlags(cmd *cobra.Command) {
|
|||
Config(func(cfg *Configuration) {
|
||||
// General
|
||||
cmd.PersistentFlags().String(ApplicationNameFlag(), cfg.ApplicationName, fieldtag("ApplicationName", "usage"))
|
||||
cmd.PersistentFlags().String(LandingPageUserFlag(), cfg.LandingPageUser, fieldtag("LandingPageUser", "usage"))
|
||||
cmd.PersistentFlags().String(HostFlag(), cfg.Host, fieldtag("Host", "usage"))
|
||||
cmd.PersistentFlags().String(AccountDomainFlag(), cfg.AccountDomain, fieldtag("AccountDomain", "usage"))
|
||||
cmd.PersistentFlags().String(ProtocolFlag(), cfg.Protocol, fieldtag("Protocol", "usage"))
|
||||
|
|
|
|||
|
|
@ -1794,3 +1794,29 @@ func GetAdvancedCookiesSamesite() string { return global.GetAdvancedCookiesSames
|
|||
|
||||
// SetAdvancedCookiesSamesite safely sets the value for global configuration 'AdvancedCookiesSamesite' field
|
||||
func SetAdvancedCookiesSamesite(v string) { global.SetAdvancedCookiesSamesite(v) }
|
||||
|
||||
// GetLandingPageUser safely fetches the Configuration value for state's 'LandingPageUser' field
|
||||
func (st *ConfigState) GetLandingPageUser() (v string) {
|
||||
st.mutex.Lock()
|
||||
v = st.config.LandingPageUser
|
||||
st.mutex.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
// SetLandingPageUser safely sets the Configuration value for state's 'LandingPageUser' field
|
||||
func (st *ConfigState) SetLandingPageUser(v string) {
|
||||
st.mutex.Lock()
|
||||
defer st.mutex.Unlock()
|
||||
st.config.LandingPageUser = v
|
||||
st.reloadToViper()
|
||||
}
|
||||
|
||||
// LandingPageUserFlag returns the flag name for the 'LandingPageUser' field
|
||||
func LandingPageUserFlag() string { return "landing-page-user" }
|
||||
|
||||
// GetLandingPageUser safely fetches the value for global configuration 'LandingPageUser' field
|
||||
func GetLandingPageUser() string { return global.GetLandingPageUser() }
|
||||
|
||||
// SetLandingPageUser safely sets the value for global configuration 'LandingPageUser' field
|
||||
func SetLandingPageUser(v string) { global.SetLandingPageUser(v) }
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package web
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api"
|
||||
|
|
@ -28,6 +29,13 @@ import (
|
|||
)
|
||||
|
||||
func (m *Module) baseHandler(c *gin.Context) {
|
||||
|
||||
// if a landingPageUser is set in the config, redirect to that user's profile
|
||||
if landingPageUser := config.GetLandingPageUser(); landingPageUser != "" {
|
||||
c.Redirect(http.StatusFound, "/@"+c.Param(strings.ToLower(landingPageUser)))
|
||||
return
|
||||
}
|
||||
|
||||
host := config.GetHost()
|
||||
instance, err := m.processor.InstanceGet(c.Request.Context(), host)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ func (m *Module) profileGETHandler(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
// usernames on our instance will always be lowercase
|
||||
username := strings.ToLower(c.Param(usernameKey))
|
||||
if username == "" {
|
||||
err := errors.New("no account username specified")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue