feat: 并发分组系统 + 品牌/Logo 上传 + 兑换码开关 + 文档分辨率表
并发分组(新功能): - 新表 concurrency_groups(名称/上限/默认),用户加 concurrency_group_id - 启动自动建「默认并发」组(上限10、默认),老用户回填、新注册自动绑定 - 并发计数改用 Redis(自愈 sorted-set + TTL + fail-open): · 用户并发(画图台 + API key 合计)受其分组上限限制,0=不限制 → 超返回 429 · 账号级并发也从内存 gate 换成同一套 Redis(6 处调用点) · 移除旧的「已有正在生成的任务」单任务锁 - 后台「并发分组」新菜单:增删改、设默认、用户数;默认组不可删(删别的组成员转默认) - 用户管理:并发列 + 新建/编辑可选分组 - 个人设置页:账户信息卡(用户名/邮箱/角色/余额/并发);/me 暴露 concurrency_group/limit 品牌 / Logo(上传到 RustFS): - Logo 改成拖拽/点击上传,点保存才上传;替换自动删旧;branding/ 设为公开且被清理任务 pin 住(永不删) - 有自定义就用:前台左侧 nav + 后台侧栏 + favicon(浏览器标签);没有则默认 V 图标 - 前台页头还原成文字;首页 Hero 子标题用 site.subtitle(默认那句宣传语,设置页预填) - 邮件验证码标题用站点名;新增 POST/DELETE /settings/logo + POST /settings/asset(首页底图上传) 兑换码开关: - 系统设置→积分 新增「开启兑换码」(默认开);关闭后后端拒绝兑换、前台隐藏兑换入口(/site 暴露 cdk_redeem_enabled) 文档 / 分辨率: - 去掉 quality 参数:size(宽x高)同时决定比例 + 分辨率档(长边映射 1K/2K/4K) - 文档加「分辨率对照表」(14 个比例 × 1K/2K/4K → size 该传的值);guessRatio 与自定义模型 RATIO_OPTS 对齐到 14 个 其它: - 删模型时同步清掉各上游账号「支持模型」里的该 id - 首页设置/兑换码弹窗去固定高度滚动条;展示位弹窗浅色主题适配 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -41,10 +41,11 @@ type SMTPSettings struct {
|
||||
}
|
||||
|
||||
type CreditSettings struct {
|
||||
CheckinEnabled bool `json:"checkin_enabled"`
|
||||
CheckinReward int `json:"checkin_reward"`
|
||||
InviteEnabled bool `json:"invite_enabled"`
|
||||
InviteReward int `json:"invite_reward"`
|
||||
CheckinEnabled bool `json:"checkin_enabled"`
|
||||
CheckinReward int `json:"checkin_reward"`
|
||||
InviteEnabled bool `json:"invite_enabled"`
|
||||
InviteReward int `json:"invite_reward"`
|
||||
CDKRedeemEnabled bool `json:"cdk_redeem_enabled"`
|
||||
}
|
||||
|
||||
type ProxySettings struct {
|
||||
@@ -70,6 +71,75 @@ func NewAppSettingsService(settings *repo.SiteSettingRepository, events *repo.Ev
|
||||
}
|
||||
}
|
||||
|
||||
// UploadLogo stores a new site logo in object storage under branding/, deletes
|
||||
// the previously-uploaded one (if any), persists site.logo, and returns its URL.
|
||||
func (s *AppSettingsService) UploadLogo(ctx context.Context, data []byte, contentType string) (string, error) {
|
||||
if s.store == nil || !s.store.Configured() {
|
||||
return "", errors.New("对象存储未配置")
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return "", errors.New("空文件")
|
||||
}
|
||||
if len(data) > 4*1024*1024 {
|
||||
return "", errors.New("logo 不能超过 4MB")
|
||||
}
|
||||
key := "branding/logo-" + randomUpper(10) + "." + logoExt(contentType)
|
||||
if err := s.store.Put(ctx, key, data, contentType); err != nil {
|
||||
return "", err
|
||||
}
|
||||
url := "/images/" + key
|
||||
// Delete the previous uploaded logo (best-effort), then point site.logo at the new one.
|
||||
if old, _ := s.settings.GetValue(ctx, "site.logo"); strings.HasPrefix(old, "/images/branding/") {
|
||||
_ = s.store.Delete(ctx, strings.TrimPrefix(old, "/images/"))
|
||||
}
|
||||
if err := s.settings.UpsertValue(ctx, "site.logo", url); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return url, nil
|
||||
}
|
||||
|
||||
// UploadAsset stores a public image (e.g. a 首页内容 底图) under branding/ and
|
||||
// returns its storage path (for form.image). Does NOT touch site settings.
|
||||
func (s *AppSettingsService) UploadAsset(ctx context.Context, data []byte, contentType string) (string, error) {
|
||||
if s.store == nil || !s.store.Configured() {
|
||||
return "", errors.New("对象存储未配置")
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return "", errors.New("空文件")
|
||||
}
|
||||
if len(data) > 8*1024*1024 {
|
||||
return "", errors.New("图片不能超过 8MB")
|
||||
}
|
||||
key := "branding/sc-" + randomUpper(10) + "." + logoExt(contentType)
|
||||
if err := s.store.Put(ctx, key, data, contentType); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return key, nil
|
||||
}
|
||||
|
||||
// RemoveLogo deletes the uploaded logo and resets site.logo to the built-in default (empty).
|
||||
func (s *AppSettingsService) RemoveLogo(ctx context.Context) error {
|
||||
if old, _ := s.settings.GetValue(ctx, "site.logo"); strings.HasPrefix(old, "/images/branding/") && s.store != nil {
|
||||
_ = s.store.Delete(ctx, strings.TrimPrefix(old, "/images/"))
|
||||
}
|
||||
return s.settings.UpsertValue(ctx, "site.logo", "")
|
||||
}
|
||||
|
||||
func logoExt(contentType string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(contentType)) {
|
||||
case "image/jpeg", "image/jpg":
|
||||
return "jpg"
|
||||
case "image/webp":
|
||||
return "webp"
|
||||
case "image/svg+xml":
|
||||
return "svg"
|
||||
case "image/gif":
|
||||
return "gif"
|
||||
default:
|
||||
return "png"
|
||||
}
|
||||
}
|
||||
|
||||
func (s *AppSettingsService) Registration(ctx context.Context) (*RegistrationSettings, error) {
|
||||
openRaw, err := s.settings.GetValue(ctx, "auth.open")
|
||||
if err != nil {
|
||||
@@ -281,11 +351,13 @@ func (s *AppSettingsService) Credits(ctx context.Context) (*CreditSettings, erro
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cdkRaw, _ := s.settings.GetValue(ctx, "credits.cdk_redeem_enabled")
|
||||
return &CreditSettings{
|
||||
CheckinEnabled: parseBoolSetting(checkinEnabledRaw, true),
|
||||
CheckinReward: parseIntSetting(checkinRewardRaw, 3),
|
||||
InviteEnabled: parseBoolSetting(inviteEnabledRaw, true),
|
||||
InviteReward: parseIntSetting(inviteRewardRaw, 3),
|
||||
CheckinEnabled: parseBoolSetting(checkinEnabledRaw, true),
|
||||
CheckinReward: parseIntSetting(checkinRewardRaw, 3),
|
||||
InviteEnabled: parseBoolSetting(inviteEnabledRaw, true),
|
||||
InviteReward: parseIntSetting(inviteRewardRaw, 3),
|
||||
CDKRedeemEnabled: parseBoolSetting(cdkRaw, true),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -297,10 +369,11 @@ func (s *AppSettingsService) SaveCredits(ctx context.Context, in CreditSettings)
|
||||
in.InviteReward = 0
|
||||
}
|
||||
if err := s.settings.UpsertValues(ctx, map[string]string{
|
||||
"credits.checkin_enabled": strconv.FormatBool(in.CheckinEnabled),
|
||||
"credits.checkin_reward": strconv.Itoa(in.CheckinReward),
|
||||
"credits.invite_enabled": strconv.FormatBool(in.InviteEnabled),
|
||||
"credits.invite_reward": strconv.Itoa(in.InviteReward),
|
||||
"credits.checkin_enabled": strconv.FormatBool(in.CheckinEnabled),
|
||||
"credits.checkin_reward": strconv.Itoa(in.CheckinReward),
|
||||
"credits.invite_enabled": strconv.FormatBool(in.InviteEnabled),
|
||||
"credits.invite_reward": strconv.Itoa(in.InviteReward),
|
||||
"credits.cdk_redeem_enabled": strconv.FormatBool(in.CDKRedeemEnabled),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user