All checks were successful
check / check (push) Successful in 1m0s
## Summary Fixes IRC client SPA issues reported in [issue #57](#57). ## Changes ### Server-side - **Default MOTD**: Added figlet-style ASCII art MOTD for "neoirc" as the default when no MOTD is configured via environment/config - **MOTD command handler**: Added `MOTD` case to `dispatchCommand` so clients can re-request the MOTD at any time (proper IRC behavior) ### SPA (web client) - **`/motd` command**: Sends MOTD request to server, displays 375/372/376 numerics in server window - **`/query nick [message]`**: Opens a DM tab with the specified user, optionally sends a message - **`/clear`**: Clears messages in the current tab - **Firefox `/` key fix**: Added global `keydown` listener that captures `/` when input is not focused, preventing Firefox quick search and redirecting focus to the input element. Also auto-focuses input on SPA init. - **MOTD on resumed sessions**: When restoring from a saved token, the MOTD is re-requested so it always appears in the server window - **Updated `/help`**: Shows all new commands with descriptions - **Login screen MOTD styling**: Improved for ASCII art display (monospace, proper line height) ## Testing - `docker build .` passes (includes `make check` with tests, lint, fmt-check) - All existing tests pass with no modifications closes #57 <!-- session: agent:sdlc-manager:subagent:7c880fec-f818-49ff-a548-2d3c26758bb6 --> Co-authored-by: user <user@Mac.lan guest wan> Reviewed-on: #58 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org>
112 lines
3.1 KiB
Go
112 lines
3.1 KiB
Go
// Package config provides application configuration via environment and files.
|
|
package config
|
|
|
|
import (
|
|
"errors"
|
|
"log/slog"
|
|
|
|
"git.eeqj.de/sneak/neoirc/internal/globals"
|
|
"git.eeqj.de/sneak/neoirc/internal/logger"
|
|
"github.com/spf13/viper"
|
|
"go.uber.org/fx"
|
|
|
|
_ "github.com/joho/godotenv/autoload" // loads .env file
|
|
)
|
|
|
|
const defaultMOTD = ` _ __ ___ ___ (_)_ __ ___
|
|
| '_ \ / _ \/ _ \ | | '__/ __|
|
|
| | | | __/ (_) || | | | (__
|
|
|_| |_|\___|\___/ |_|_| \___|
|
|
|
|
Welcome to NeoIRC — IRC semantics over HTTP.
|
|
Type /help for available commands.`
|
|
|
|
// Params defines the dependencies for creating a Config.
|
|
type Params struct {
|
|
fx.In
|
|
|
|
Globals *globals.Globals
|
|
Logger *logger.Logger
|
|
}
|
|
|
|
// Config holds all application configuration values.
|
|
type Config struct {
|
|
DBURL string
|
|
Debug bool
|
|
MaintenanceMode bool
|
|
MetricsPassword string
|
|
MetricsUsername string
|
|
Port int
|
|
SentryDSN string
|
|
MaxHistory int
|
|
MaxMessageSize int
|
|
MOTD string
|
|
ServerName string
|
|
FederationKey string
|
|
SessionIdleTimeout string
|
|
params *Params
|
|
log *slog.Logger
|
|
}
|
|
|
|
// New creates a new Config by reading from files and environment variables.
|
|
func New(
|
|
_ fx.Lifecycle, params Params,
|
|
) (*Config, error) {
|
|
log := params.Logger.Get()
|
|
name := params.Globals.Appname
|
|
|
|
viper.SetConfigName(name)
|
|
viper.SetConfigType("yaml")
|
|
viper.AddConfigPath("/etc/" + name)
|
|
viper.AddConfigPath("$HOME/.config/" + name)
|
|
viper.AutomaticEnv()
|
|
|
|
viper.SetDefault("DEBUG", "false")
|
|
viper.SetDefault("MAINTENANCE_MODE", "false")
|
|
viper.SetDefault("PORT", "8080")
|
|
viper.SetDefault("DBURL", "file:///var/lib/neoirc/state.db?_journal_mode=WAL")
|
|
viper.SetDefault("SENTRY_DSN", "")
|
|
viper.SetDefault("METRICS_USERNAME", "")
|
|
viper.SetDefault("METRICS_PASSWORD", "")
|
|
viper.SetDefault("MAX_HISTORY", "10000")
|
|
viper.SetDefault("MAX_MESSAGE_SIZE", "4096")
|
|
viper.SetDefault("MOTD", defaultMOTD)
|
|
viper.SetDefault("SERVER_NAME", "")
|
|
viper.SetDefault("FEDERATION_KEY", "")
|
|
viper.SetDefault("SESSION_IDLE_TIMEOUT", "24h")
|
|
|
|
err := viper.ReadInConfig()
|
|
if err != nil {
|
|
var notFound viper.ConfigFileNotFoundError
|
|
if !errors.As(err, ¬Found) {
|
|
log.Error("config file malformed", "error", err)
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
cfg := &Config{
|
|
DBURL: viper.GetString("DBURL"),
|
|
Debug: viper.GetBool("DEBUG"),
|
|
Port: viper.GetInt("PORT"),
|
|
SentryDSN: viper.GetString("SENTRY_DSN"),
|
|
MaintenanceMode: viper.GetBool("MAINTENANCE_MODE"),
|
|
MetricsUsername: viper.GetString("METRICS_USERNAME"),
|
|
MetricsPassword: viper.GetString("METRICS_PASSWORD"),
|
|
MaxHistory: viper.GetInt("MAX_HISTORY"),
|
|
MaxMessageSize: viper.GetInt("MAX_MESSAGE_SIZE"),
|
|
MOTD: viper.GetString("MOTD"),
|
|
ServerName: viper.GetString("SERVER_NAME"),
|
|
FederationKey: viper.GetString("FEDERATION_KEY"),
|
|
SessionIdleTimeout: viper.GetString("SESSION_IDLE_TIMEOUT"),
|
|
log: log,
|
|
params: ¶ms,
|
|
}
|
|
|
|
if cfg.Debug {
|
|
params.Logger.EnableDebugLogging()
|
|
cfg.log = params.Logger.Get()
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|