- 移除管理员初始化/登录/JWT 流程,改为固定进入密钥(19735500), 首次启动自动初始化到数据库 settings 表(可改库更新) - analyze 接口支持可选密钥鉴权:X-Access-Key 请求头或 access_key 字段, 带密钥强制校验(错误 401),不带密钥保持免鉴权 - 解锁后顶栏"复制 API 文档"按钮:以当前访问 URL 为基础地址动态生成 Markdown 文档(免鉴权/带密钥两种 curl 示例,供智能体直接调用) - 白昼/黑夜主题切换:CSS 变量驱动,localStorage 持久化,默认跟随系统 - 修复 hidden 属性被 display:flex 覆盖导致解锁层无法隐藏的问题 - 页面去除"免费/Agnes"文案,页脚署名青梧映星软件开发工作室 - build.bat/build.sh 简化为 Linux 交叉编译(CGO_ENABLED=0) - 依赖精简:移除 golang-jwt/bcrypt,直接依赖仅 gin/sqlite/gorm/yaml Co-Authored-By: Claude <noreply@anthropic.com>
36 lines
880 B
Go
36 lines
880 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"vision-tool/internal/model"
|
|
"vision-tool/internal/service"
|
|
)
|
|
|
|
// AuthHandler HTTP 处理器:进入密钥校验。
|
|
type AuthHandler struct {
|
|
svc *service.AccessService
|
|
}
|
|
|
|
func NewAuthHandler(svc *service.AccessService) *AuthHandler {
|
|
return &AuthHandler{svc: svc}
|
|
}
|
|
|
|
// Verify POST /api/v1/auth/verify — 校验进入密钥(固定密钥,存于数据库)
|
|
func (h *AuthHandler) Verify(c *gin.Context) {
|
|
var req struct {
|
|
Key string `json:"key" binding:"required"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, model.Err(model.CodeBadParam, "请输入进入密钥"))
|
|
return
|
|
}
|
|
if !h.svc.VerifyKey(req.Key) {
|
|
c.JSON(http.StatusUnauthorized, model.Err(model.CodeUnauthorized, "密钥错误"))
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, model.OK(gin.H{"ok": true}))
|
|
}
|