Files
artalkjs/server/handler/setting_get.go
qwqcode cf7725edba refactor(go): bump the module version and support go install (#979)
BREAKING CHANGE: The original Go module name was `github.com/ArtalkJS/Artalk`, which has now been modified to `github.com/artalkjs/artalk/v2` (all lowercase). This change may affect the CI pipeline or other areas if you are compiling the Artalk server and have specified the fixed Go module name. Regarding the original `-ldflags -X github.com/ArtalkJS/Artalk/internal/config.Version` and `CommitHash` definitions, please remove them, as they are now obsolete. The `Version` has been hardcoded into the Go code, and the `CommitHash` is now read from the Go build info via runtime/debug’s vcs.revision value. This change only affects the server developers and does not impact the frontend UI client.
2024-09-18 21:43:43 +08:00

47 lines
1.2 KiB
Go

package handler
import (
"os"
"strings"
"github.com/artalkjs/artalk/v2/internal/core"
"github.com/artalkjs/artalk/v2/internal/i18n"
"github.com/artalkjs/artalk/v2/server/common"
"github.com/gofiber/fiber/v2"
"github.com/samber/lo"
)
type ResponseSettingGet struct {
Yaml string `json:"yaml"`
Envs []string `json:"envs"`
}
// @Id GetSettings
// @Summary Get Settings
// @Description Get settings from app config file
// @Tags System
// @Security ApiKeyAuth
// @Produce json
// @Success 200 {object} ResponseSettingGet
// @Failure 403 {object} Map{msg=string}
// @Failure 500 {object} Map{msg=string}
// @Router /settings [get]
func SettingGet(app *core.App, router fiber.Router) {
router.Get("/settings", common.AdminGuard(app, func(c *fiber.Ctx) error {
dat, err := os.ReadFile(app.Conf().GetCfgFileLoaded())
if err != nil {
return common.RespError(c, 500, i18n.T("Config file read failed"))
}
// get all environment variables which start with ATK_
envs := lo.Filter(os.Environ(), func(v string, _ int) bool {
return strings.HasPrefix(v, "ATK_")
})
return common.RespData(c, ResponseSettingGet{
Yaml: string(dat),
Envs: envs,
})
}))
}