Files
cyi-box/backend/internal/service/setting.go
T
chiyiandDevin 834ecacdb9 cyi-box: Memphis-style toolbox admin platform
Go(fun)+SQLite backend, Vue 3 frontend. Modules: dashboard, pay gateway
(Epay-compatible + CDK stock), license/card system (per-app appid, domain
binding), AI memory bank with built-in MCP server (/mcp, FTS5 search,
signed read links), server SSH monitor + terminal + SFTP, proxy pool with
protocol-level alive checks, DB manager (mysql/pg/sqlite + SQL
autocomplete + import/export), disk share, vault (AES-GCM + TOTP),
bookmarks, dev tools.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-01 01:58:47 +08:00

40 lines
1.1 KiB
Go

package service
import (
"strings"
"github.com/cyi-cc/fun"
"github.com/cyi-cc/cyi-box/backend/internal/dto"
"github.com/cyi-cc/cyi-box/backend/internal/store"
)
// SettingSvc 站点级 KV 设置:读取对所有登录用户开放,写入仅管理员
type SettingSvc struct {
fun.Ctx
Store *store.Store
}
func (s *SettingSvc) Get(d dto.SettingDto) (dto.SettingView, error) {
key := strings.TrimSpace(d.Key)
if key == "" || len(key) > 64 {
return dto.SettingView{}, fun.Error(4001, "key 必填且不超过 64 字符")
}
v, err := s.Store.GetSetting(key)
if err != nil {
return dto.SettingView{}, err
}
return dto.SettingView{Value: v}, nil
}
func (s *SettingSvc) Set(d dto.SettingDto) (dto.OkView, error) {
key := strings.TrimSpace(d.Key)
if key == "" || len(key) > 64 || len(d.Value) > 2000 {
return dto.OkView{}, fun.Error(4001, "key 必填且不超过 64 字符,value 不超过 2000 字符")
}
if err := s.Store.SetSetting(key, strings.TrimSpace(d.Value)); err != nil {
return dto.OkView{}, err
}
return dto.OkView{Message: "已保存"}, nil
}