Merge pull request 'Add MOZHI_DEFAULT_ENGINE environment variable' (#109) from Steve-Tech/mozhi:master into master

Reviewed-on: https://codeberg.org/aryak/mozhi/pulls/109
This commit is contained in:
2025-06-25 07:08:44 +02:00
2 changed files with 10 additions and 1 deletions

View File

@@ -59,6 +59,7 @@ Features of Mozhi can be customized and toggled on/off using Environment Variabl
- `MOZHI_DEFAULT_SOURCE_LANG`: Language to default to if no source language is set by user. Defaults to Auto-Detect (or first available language in engines which dont support it)
- `MOZHI_DEFAULT_PREFER_AUTODETECT`: Prefer autodetect if available instead of specified/default source language. Defaults to false
- `MOZHI_DEFAULT_TARGET_LANG`: Language to default to if no target language is set by user. Defaults to English
- `MOZHI_DEFAULT_ENGINE`: Engine to default to if no engine is set by user. Defaults to `google`
These envvars turn off/on engines. By default all of them are enabled.
- `MOZHI_GOOGLE_ENABLED`

View File

@@ -33,6 +33,14 @@ func HandleIndex(c *fiber.Ctx) error {
for engine := range engines {
enginesAsArray = append(enginesAsArray, engine)
}
defaultEngine := os.Getenv("MOZHI_DEFAULT_ENGINE")
if defaultEngine == "" || !slices.Contains(enginesAsArray, defaultEngine) {
if slices.Contains(enginesAsArray, "google") {
defaultEngine = "google"
} else if len(enginesAsArray) > 0 {
defaultEngine = enginesAsArray[0]
}
}
engineCookie := c.Cookies("engine")
fromCookie := c.Cookies("from")
toCookie := c.Cookies("to")
@@ -41,7 +49,7 @@ func HandleIndex(c *fiber.Ctx) error {
if engineCookie != "" {
engine = engineCookie
} else {
engine = "google"
engine = defaultEngine
}
}