Files
jmiller bab29a83fa refactor: rename Go module path MokoConsulting/MokoGitea -> MokoConsulting/MokoGIT
Sweep all .go imports + go.mod, plus module-path refs in .golangci.yml,
Dockerfile, swagger templates, locale example, and repo/wiki URLs
(MokoGitea-Fork -> MokoGIT). Part of the MokoGIT rebrand.

Claude-Session: https://claude.ai/code/session_01Bqe7fAuHQeiLueYfeHFrHw
2026-07-14 15:31:19 -05:00

72 lines
2.3 KiB
Go

// Copyright 2026 Moko Consulting <hello@mokoconsulting.tech>
// SPDX-License-Identifier: GPL-3.0-or-later
package admin
import (
"net/http"
"strings"
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/log"
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/setting"
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/modules/templates"
"code.mokoconsulting.tech/MokoConsulting/MokoGIT/services/context"
)
const tplMetadata templates.TplName = "admin/metadata"
// Metadata shows the admin metadata-settings page.
func Metadata(ctx *context.Context) {
ctx.Data["Title"] = "Metadata"
ctx.Data["PageIsAdminMetadata"] = true
ctx.Data["PlatformOptions"] = strings.Join(setting.Metadata.PlatformOptions, "\n")
ctx.HTML(http.StatusOK, tplMetadata)
}
// parsePlatformOptions normalizes admin input (comma- or newline-separated) into
// a clean, lowercased, de-duplicated, order-preserving list of platform values.
func parsePlatformOptions(raw string) []string {
seen := make(map[string]bool)
var out []string
for _, tok := range strings.FieldsFunc(raw, func(r rune) bool { return r == ',' || r == '\n' || r == '\r' }) {
v := strings.ToLower(strings.TrimSpace(tok))
if v == "" || seen[v] {
continue
}
seen[v] = true
out = append(out, v)
}
return out
}
// MetadataSettings persists the admin metadata settings.
func MetadataSettings(ctx *context.Context) {
opts := parsePlatformOptions(ctx.FormString("platform_options"))
if len(opts) == 0 {
ctx.Flash.Error("Platform options cannot be empty")
ctx.Redirect(setting.AppSubURL + "/-/admin/metadata")
return
}
// Apply in-memory so the change takes effect without a restart.
setting.Metadata.PlatformOptions = opts
// Persist to app.ini [metadata] PLATFORM_OPTIONS.
cfg, err := setting.NewConfigProviderFromFile(setting.CustomConf)
if err != nil {
ctx.Flash.Error("Failed to load config: " + err.Error())
ctx.Redirect(setting.AppSubURL + "/-/admin/metadata")
return
}
cfg.Section("metadata").Key("PLATFORM_OPTIONS").SetValue(strings.Join(opts, ","))
if err := cfg.SaveTo(setting.CustomConf); err != nil {
ctx.Flash.Error("Failed to save config: " + err.Error())
log.Error("SaveTo %s: %v", setting.CustomConf, err)
} else {
ctx.Flash.Success("Metadata settings saved")
log.Info("Metadata platform options updated: %v", opts)
}
ctx.Redirect(setting.AppSubURL + "/-/admin/metadata")
}