画图台(并发出图):
- 不再锁定 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>
230 lines
6.0 KiB
Go
230 lines
6.0 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
|
|
"backend/internal/model"
|
|
"backend/internal/service"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type AdminReadHandler struct {
|
|
admin *service.AdminReadService
|
|
}
|
|
|
|
func NewAdminReadHandler(admin *service.AdminReadService) *AdminReadHandler {
|
|
return &AdminReadHandler{admin: admin}
|
|
}
|
|
|
|
func (h *AdminReadHandler) Users(c *gin.Context) {
|
|
users, stats, err := h.admin.Users(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load users"})
|
|
return
|
|
}
|
|
|
|
out := make([]gin.H, 0, len(users))
|
|
for _, user := range users {
|
|
row := userPublic(user)
|
|
row["generation_count"] = user.GenerationCount
|
|
out = append(out, row)
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"data": out, "stats": stats})
|
|
}
|
|
|
|
func (h *AdminReadHandler) Models(c *gin.Context) {
|
|
items, err := h.admin.ModelsView(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load models"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"data": items})
|
|
}
|
|
|
|
func (h *AdminReadHandler) Logs(c *gin.Context) {
|
|
limit := parseInt(c.Query("limit"), 50)
|
|
offset := parseInt(c.Query("offset"), 0)
|
|
kind := c.Query("kind")
|
|
status := c.Query("status")
|
|
var since *time.Time
|
|
if raw := c.Query("since"); raw != "" {
|
|
if f, err := strconv.ParseFloat(raw, 64); err == nil {
|
|
t := time.Unix(int64(f), 0)
|
|
since = &t
|
|
}
|
|
}
|
|
|
|
items, total, stats, err := h.admin.Logs(c.Request.Context(), limit, offset, kind, status, nil, since, "", "", c.Query("source"), false)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load logs"})
|
|
return
|
|
}
|
|
// Resolve user_id -> display name once for the page (mirrors admin.py).
|
|
nameByID, err := h.admin.UserNameMap(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load logs"})
|
|
return
|
|
}
|
|
out := make([]gin.H, 0, len(items))
|
|
for _, item := range items {
|
|
var userName any
|
|
if item.UserID == "" {
|
|
userName = "匿名"
|
|
} else if name, ok := nameByID[item.UserID]; ok {
|
|
userName = name
|
|
} else {
|
|
userName = item.UserID
|
|
}
|
|
out = append(out, gin.H{
|
|
"id": item.ID,
|
|
"ts": item.TS.Unix(),
|
|
"kind": item.Kind,
|
|
"status": item.Status,
|
|
"model": item.Model,
|
|
"provider": item.Provider,
|
|
"prompt": item.Prompt,
|
|
"ratio": item.Ratio,
|
|
"resolution": item.Resolution,
|
|
"duration": item.Duration,
|
|
"refs": item.Refs,
|
|
"source": item.Source,
|
|
"user_id": emptyStringNil(item.UserID),
|
|
"user_name": userName,
|
|
"cost": item.Cost,
|
|
"elapsed_ms": item.ElapsedMS,
|
|
"file": emptyStringNil(item.File),
|
|
"error": emptyStringNil(item.Error),
|
|
"created_at": unixSec(item.CreatedAt),
|
|
"updated_at": unixSec(item.UpdatedAt),
|
|
})
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"data": out,
|
|
"total": total,
|
|
"limit": limit,
|
|
"offset": offset,
|
|
"stats": stats,
|
|
})
|
|
}
|
|
|
|
func (h *AdminReadHandler) Stats(c *gin.Context) {
|
|
stats, err := h.admin.Stats(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load stats"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, stats)
|
|
}
|
|
|
|
func (h *AdminReadHandler) Dashboard(c *gin.Context) {
|
|
data, err := h.admin.Dashboard(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load dashboard"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, data)
|
|
}
|
|
|
|
func (h *AdminReadHandler) Invites(c *gin.Context) {
|
|
items, stats, err := h.admin.Invites(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load invites"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"data": items, "stats": stats})
|
|
}
|
|
|
|
func (h *AdminReadHandler) Providers(c *gin.Context) {
|
|
items, err := h.admin.Providers(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load providers"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"data": items})
|
|
}
|
|
|
|
func (h *AdminReadHandler) Images(c *gin.Context) {
|
|
limit := parseInt(c.Query("limit"), 30)
|
|
offset := parseInt(c.Query("offset"), 0)
|
|
kind := c.Query("kind")
|
|
items, total, stats, err := h.admin.Images(c.Request.Context(), limit, offset, kind)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load images"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"data": items,
|
|
"total": total,
|
|
"limit": limit,
|
|
"offset": offset,
|
|
"stats": stats,
|
|
})
|
|
}
|
|
|
|
func userPublic(user model.User) gin.H {
|
|
keys := make([]gin.H, 0, len(user.APIKeys))
|
|
for _, key := range user.APIKeys {
|
|
keys = append(keys, gin.H{
|
|
"id": key.ID,
|
|
"name": key.Name,
|
|
"key_preview": key.KeyPreview,
|
|
"created_at": unixSec(key.CreatedAt),
|
|
"last_used_at": unixSecPtr(key.LastUsedAt),
|
|
})
|
|
}
|
|
return gin.H{
|
|
"id": user.ID,
|
|
"email": user.Email,
|
|
"name": user.Name,
|
|
"role": user.Role,
|
|
"status": user.Status,
|
|
"credits": user.Credits,
|
|
"notes": user.Notes,
|
|
"created_at": unixSec(user.CreatedAt),
|
|
"last_login_at": unixSecPtr(user.LastLoginAt),
|
|
"last_login_ip": user.LastLoginIP,
|
|
"invite_code": user.InviteCode,
|
|
"invited_by": user.InvitedBy,
|
|
"checkin_last": user.CheckinLast,
|
|
"checkin_streak": user.CheckinStreak,
|
|
"api_keys": keys,
|
|
"has_password": user.PasswordHash != "",
|
|
}
|
|
}
|
|
|
|
// unixSec / unixSecPtr render timestamps as unix SECONDS — the frontend's
|
|
// fmtTs/fmtRelative expect seconds (matching the Python reference's time.time()),
|
|
// not the RFC3339 string Go marshals a time.Time into (which parses to NaN → "—").
|
|
func unixSec(t time.Time) any {
|
|
if t.IsZero() {
|
|
return nil
|
|
}
|
|
return t.Unix()
|
|
}
|
|
|
|
func unixSecPtr(t *time.Time) any {
|
|
if t == nil || t.IsZero() {
|
|
return nil
|
|
}
|
|
return t.Unix()
|
|
}
|
|
|
|
func parseInt(raw string, fallback int) int {
|
|
if raw == "" {
|
|
return fallback
|
|
}
|
|
if n, err := strconv.Atoi(raw); err == nil {
|
|
return n
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
func emptyStringNil(v string) any {
|
|
if v == "" {
|
|
return nil
|
|
}
|
|
return v
|
|
}
|