feat: 画图台并发重构 + 品牌定制 + 用户备注 + provider/UI 多项修复

画图台(并发出图):
- 不再锁定 UI:点「生成」开独立任务,可连续多次并发
- 结果网格一行5个、最多10张,进行中/成功/失败状态回显,刷新保留进行中
- 生图张数 1/2/3/4,各自独立计费出卡
- 点图=参考图(单张替换/多张替换末位);首尾帧模型点视频=抓末帧设为首帧,否则放大
- /logs 新增 statuses=pending,success 服务端过滤(status IN 专用 SQL)

品牌定制(设置→网站):
- 自定义 Logo 图片 + 子标题(公开页头部 + 管理侧栏)
- 邮件验证码标题改用站点名:{title} 邮箱验证码

提示词复制:
- 去掉复制按钮,点提示词文字即复制(预览/后台日志/图片管理/画图记录),统一弹「指令已复制」
- 新增 utils/clipboard.js:execCommand 回退,非安全上下文(http/IP)也能复制

用户管理:列表加「备注」列,新建/编辑可填改备注(默认空)

provider 修复:
- grok 401 正确判死封号(markTokenFailure 漏了 grok 池)
- grok 视频支持 15s
- custom 上游报错去敏感(抹掉上游 URL/IP,改英文短描述)
- custom 去掉额度耗尽锁定:429/欠费当临时错误,账号保持 active

UI/其它:
- 展示位弹窗浅色主题适配(tab 选中高亮、输入框边框)— 主题变量 + 中心补丁
- 自定义模型:时长可填任意秒数 + 15s 预设
- 首页设置/卡密弹窗去固定高度与滚动条
- 顶部菜单「记录」→「图片」
- 下线 Flow provider(代码移除)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-30 01:11:22 +08:00
co-authored by Claude Opus 4.8
parent 3ef84bb9b3
commit 1137d0bd1d
35 changed files with 810 additions and 347 deletions
+70 -8
View File
@@ -18,7 +18,8 @@ type EventListFilter struct {
Limit int
Offset int
Kind string
Status string
Status string // single status (status = ?)
Statuses []string // multiple statuses (status IN (?)) — used by the 画图台 grid
Since *time.Time
UserID string
ExcludeSource string // when set, omit rows with this source (e.g. hide API-key "v1" usage from the customer logs page)
@@ -47,6 +48,9 @@ func (r *EventRepository) List(ctx context.Context, filter EventListFilter) ([]m
if filter.Status != "" {
q = q.Where("status = ?", filter.Status)
}
if len(filter.Statuses) > 0 {
q = q.Where("status IN ?", filter.Statuses)
}
if filter.Since != nil {
q = q.Where("ts > ?", *filter.Since)
}
@@ -443,7 +447,49 @@ func (r *EventRepository) PurgeStale(ctx context.Context, maxAge time.Duration)
}
func (r *EventRepository) Create(ctx context.Context, item *model.EventLog) error {
return r.db.WithContext(ctx).Create(item).Error
if err := r.db.WithContext(ctx).Create(item).Error; err != nil {
return err
}
// Persistent cumulative counters (survive log retention/clearing): every
// created event bumps total + its kind + (api source).
deltas := map[string]int64{"total": 1}
if item.Kind == "video" {
deltas["video"] = 1
} else if item.Kind == "image" {
deltas["image"] = 1
}
if item.Source == "v1" {
deltas["api"] = 1
}
r.incrCounters(ctx, deltas)
return nil
}
// incrCounters upserts monotonic counters (stat_counters). Best-effort: a counter
// failure must never fail the generation, so errors are swallowed.
func (r *EventRepository) incrCounters(ctx context.Context, deltas map[string]int64) {
for k, n := range deltas {
if n == 0 {
continue
}
_ = r.db.WithContext(ctx).Exec(
`INSERT INTO stat_counters (key, value, updated_at) VALUES (?, ?, now())
ON CONFLICT (key) DO UPDATE SET value = stat_counters.value + EXCLUDED.value, updated_at = now()`,
k, n).Error
}
}
// Counters returns all persistent counters as key→value.
func (r *EventRepository) Counters(ctx context.Context) (map[string]int64, error) {
var rows []model.StatCounter
if err := r.db.WithContext(ctx).Find(&rows).Error; err != nil {
return nil, err
}
out := make(map[string]int64, len(rows))
for _, x := range rows {
out[x.Key] = x.Value
}
return out, nil
}
// GetByID fetches a single event (nil, nil when not found). Used by the async
@@ -462,16 +508,22 @@ func (r *EventRepository) GetByID(ctx context.Context, id string) (*model.EventL
// MarkVideoReady completes an async video job: status=success, file=upstream URL
// (proxied on /content — never persisted), elapsed.
func (r *EventRepository) MarkVideoReady(ctx context.Context, eventID, fileURL string, elapsedMS int) error {
return r.db.WithContext(ctx).
// Guard on a real transition (status <> success) so the success counter is
// incremented exactly once even if this fires twice / concurrently.
res := r.db.WithContext(ctx).
Model(&model.EventLog{}).
Where("id = ?", eventID).
Where("id = ? AND status <> ?", eventID, "success").
Updates(map[string]any{
"status": "success",
"file": fileURL,
"error": "",
"elapsed_ms": elapsedMS,
"updated_at": time.Now(),
}).Error
})
if res.Error == nil && res.RowsAffected > 0 {
r.incrCounters(ctx, map[string]int64{"success": 1})
}
return res.Error
}
func (r *EventRepository) UpdateStatus(ctx context.Context, eventID, status, errMsg string, elapsedMS int) error {
@@ -488,10 +540,20 @@ func (r *EventRepository) UpdateStatus(ctx context.Context, eventID, status, err
// "成功 + abandoned" at once.
patch["error"] = ""
}
return r.db.WithContext(ctx).
// Guard on a real transition so the success/failed counters increment exactly
// once per event even under a duplicate/concurrent terminal status update.
res := r.db.WithContext(ctx).
Model(&model.EventLog{}).
Where("id = ?", eventID).
Updates(patch).Error
Where("id = ? AND status <> ?", eventID, status).
Updates(patch)
if res.Error == nil && res.RowsAffected > 0 {
if status == "success" {
r.incrCounters(ctx, map[string]int64{"success": 1})
} else if status == "failed" {
r.incrCounters(ctx, map[string]int64{"failed": 1})
}
}
return res.Error
}
// MarkRefunded atomically claims the right to refund this event exactly once:
+8
View File
@@ -18,6 +18,14 @@ func NewModelRepository(db *gorm.DB) *ModelRepository {
return &ModelRepository{db: db}
}
// IncrementGenerationCount bumps a model's persistent success counter by 1.
// Best-effort: a missing model id is a no-op (0 rows affected, no error).
func (r *ModelRepository) IncrementGenerationCount(ctx context.Context, modelID string) error {
return r.db.WithContext(ctx).Model(&model.ModelConfig{}).
Where("id = ?", modelID).
UpdateColumn("generation_count", gorm.Expr("generation_count + 1")).Error
}
func (r *ModelRepository) List(ctx context.Context) ([]model.ModelConfig, error) {
var items []model.ModelConfig
// Higher weight floats to the top of the dropdown / admin list; ties fall
+10
View File
@@ -87,6 +87,16 @@ func (r *UserRepository) GetByInviteCode(ctx context.Context, code string) (*mod
return &user, nil
}
// IncrementGenerationCount bumps a user's persistent success counter by 1.
func (r *UserRepository) IncrementGenerationCount(ctx context.Context, userID string) error {
if userID == "" {
return nil
}
return r.db.WithContext(ctx).Model(&model.User{}).
Where("id = ?", userID).
UpdateColumn("generation_count", gorm.Expr("generation_count + 1")).Error
}
func (r *UserRepository) List(ctx context.Context) ([]model.User, error) {
var users []model.User
if err := r.db.WithContext(ctx).Preload("APIKeys").Order("created_at desc").Find(&users).Error; err != nil {