Files
smartmate/backend/gateway/shared/respond/respond.go
Losita 25a608eaeb Version: 0.9.82.dev.260507
后端:
1. 登录注册补齐极验行为验证与跨域入口:gateway 新增 `/user/captcha/register`,登录/注册先做 GeeTest 初始化与二次校验,再进入 user/auth RPC;补充验证码失败/初始化失败/服务不可用响应码,并新增可配置 CORS middleware 适配分域部署。
2. 容器部署配置入口收口:`bootstrap.LoadConfig` 支持 `SMARTFLOW_CONFIG_FILE` 与环境变量覆盖,`config.example.yaml` / `config.docker.yaml` 补齐 geetest 与容器内服务地址,网关新增配置列表解析,便于 compose 场景直接挂载配置启动。
3. LLM outbox 与助手时间线稳定性修正:`cmd/llm` 显式绑定 llm 自身 topic/group,避免误入 agent consumer group;agent timeline 在 Redis 热缓存未落 MySQL 时改用 `seq` 兜底临时 id,避免前端历史回放撞 key。

前端:
4. 认证页接入极验并补齐提交前校验:新增 GeeTest 脚本加载与实例封装,登录/注册面板支持 challenge 初始化、切换面板重挂载、失败提示与提交前校验,认证 API/types 同步透传 geetest 三元组。
5. 前端部署基址与网关对接收口:Axios `baseURL`、Vue Router `history base` 与 Vite `base/dev proxy` 改为读取环境变量,新增 `frontend/.env.example`,支持子路径部署、容器内反向代理和本地联调共存。
6. 助手与工作台展示细节修正:AssistantPanel 历史重建优先使用真实 timeline id、缺失时退回 `seq` 保证消息主键唯一;首页主面板改为纵向可滚动并补底部留白,避免内容截断。

仓库:
7. 整站容器化交付链路补齐并重写说明文档:新增后端/前端 Dockerfile、`.dockerignore`、前端 Nginx 代理、`docker-compose.full.yml`、`.env.full.example` 与镜像打包/导入脚本,README 改写数据库/路由/部署章节,并新增 `docs/容器化部署说明.md` 说明离线镜像分发方案。
2026-05-07 00:58:27 +08:00

82 lines
3.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package respond 承载 gateway HTTP 门面使用的响应适配入口。
//
// 职责边界:
// 1. 只面向 gateway/api 与 gateway/middleware统一 HTTP JSON 写回与错误响应常量的 import 位置;
// 2. 迁移期继续复用根 backend/respond 的响应码和错误语义避免一次性改动服务层、RPC 层和 client 层;
// 3. 不承载任何服务私有业务逻辑,服务代码禁止反向 import backend/gateway/shared/respond。
package respond
import (
"errors"
"net/http"
rootrespond "github.com/LoveLosita/smartflow/backend/shared/respond"
"github.com/gin-gonic/gin"
)
type (
// Response 是 gateway 透传给前端的项目响应码结构。
Response = rootrespond.Response
// FinalResponse 是带 data 字段的统一 HTTP 响应结构。
FinalResponse = rootrespond.FinalResponse
)
var (
Ok = rootrespond.Ok
UserTasksEmpty = rootrespond.UserTasksEmpty
NoOngoingOrUpcomingSchedule = rootrespond.NoOngoingOrUpcomingSchedule
TaskAlreadyDeleted = rootrespond.TaskAlreadyDeleted
WrongParamType = rootrespond.WrongParamType
MissingParam = rootrespond.MissingParam
MissingIdempotencyKey = rootrespond.MissingIdempotencyKey
MissingToken = rootrespond.MissingToken
InvalidClaims = rootrespond.InvalidClaims
ErrUnauthorized = rootrespond.ErrUnauthorized
RequestIsProcessing = rootrespond.RequestIsProcessing
ScheduleConflict = rootrespond.ScheduleConflict
TooManyRequests = rootrespond.TooManyRequests
TokenUsageExceedsLimit = rootrespond.TokenUsageExceedsLimit
ConversationNotFound = rootrespond.ConversationNotFound
MissingConversationID = rootrespond.MissingConversationID
CaptchaVerifyFailed = rootrespond.CaptchaVerifyFailed
CaptchaInitFailed = rootrespond.CaptchaInitFailed
CaptchaVerifyUnavailable = rootrespond.CaptchaVerifyUnavailable
)
// RespWithData 为 gateway HTTP 门面生成带 data 的统一响应体。
//
// 职责边界:
// 1. 只做响应结构组装,不决定 HTTP 状态码;
// 2. 响应码来源仍是根 respond保证迁移前后前端协议不变。
func RespWithData(response Response, data interface{}) FinalResponse {
return rootrespond.RespWithData(response, data)
}
// DealWithError 将项目 error 映射为 HTTP JSON 响应。
//
// 职责边界:
// 1. 只在 gateway HTTP 层写响应;
// 2. 业务错误语义仍由根 respond 统一维护;
// 3. nil error 直接忽略,保持旧 DealWithError 的降级语义。
func DealWithError(c *gin.Context, err error) {
if err == nil {
return
}
var resp Response
if errors.Is(err, UserTasksEmpty) || errors.Is(err, NoOngoingOrUpcomingSchedule) || errors.Is(err, TaskAlreadyDeleted) {
c.JSON(http.StatusOK, err)
return
}
if errors.As(err, &resp) {
c.JSON(resp.HTTPStatus(), resp)
return
}
c.JSON(http.StatusInternalServerError, InternalError(err))
}
// InternalError 生成 500 类响应体,供 gateway 依赖缺失等边缘错误使用。
func InternalError(err error) Response {
return rootrespond.InternalError(err)
}