feat(share): 新增 shareList 接口 + 分享码模块全链路优化
- 新增 GET /audio/shareList?mac=xx 查询未过期分享码(纯 Redis,ZSET 索引)
- share:mac:{mac} 从 SET 改为 ZSET(score=expire_at),支持 ZREMRANGEBYSCORE 精确过期清理
- 空 ZSET 自动 DEL,避免 key 累积
- share:import:pending 增加 12h 兜底 TTL,防止 DB 不可用时内存泄漏
- 导入日志 field 改为 mac:code(去掉 nanotime),同 MAC+code 多次导入幂等去重
- MarkPersisted 保存/恢复 PTTL,防御性编程
- shareCreate 改为 POST + JSON body
- 全量 handler 补充 Swagger 注释,集成 swag 文档生成
- Makefile 使用 $(go env GOPATH)/bin/swag 解决 PATH 问题
This commit is contained in:
+21
-21
@@ -40,17 +40,17 @@ func NewCurveHandler(repo *repository.CurveRepository, curveCache *cache.CurveCa
|
||||
|
||||
// ModelCurve 获取机型默认曲线(固定 target: Harman over-ear 2018)
|
||||
//
|
||||
// @Summary 获取机型默认频响曲线
|
||||
// @Summary 获取机型默认频响曲线
|
||||
// @Description 返回指定机型的频响曲线数据(fr),固定使用 Harman over-ear 2018 target
|
||||
// @Tags Curve
|
||||
// @Produce json
|
||||
// @Param brand query string true "品牌名称"
|
||||
// @Param name query string true "型号名称"
|
||||
// @Param base64Resp query string false "是否返回 base64 编码响应"
|
||||
// @Success 200 {object} map[string]any "成功返回 fr 数据"
|
||||
// @Failure 400 {object} map[string]any "参数校验失败"
|
||||
// @Failure 500 {object} object
|
||||
// @Router /audio/modelCurve [get]
|
||||
// @Tags Curve
|
||||
// @Produce json
|
||||
// @Param brand query string true "品牌名称"
|
||||
// @Param name query string true "型号名称"
|
||||
// @Param base64Resp query string false "是否返回 base64 编码响应"
|
||||
// @Success 200 {object} map[string]any "成功返回 fr 数据"
|
||||
// @Failure 400 {object} map[string]any "参数校验失败"
|
||||
// @Failure 500 {object} object
|
||||
// @Router /audio/modelCurve [get]
|
||||
//
|
||||
// GET /audio/modelCurve?brand=xxx&name=xxx&base64Resp=true
|
||||
func (h *CurveHandler) ModelCurve(c *gin.Context) {
|
||||
@@ -128,18 +128,18 @@ func (h *CurveHandler) ModelCurve(c *gin.Context) {
|
||||
|
||||
// GetCurve 获取目标曲线
|
||||
//
|
||||
// @Summary 获取目标曲线参数化 EQ
|
||||
// @Summary 获取目标曲线参数化 EQ
|
||||
// @Description 根据机型和目标曲线名称,计算并返回 parametric_eq 数据
|
||||
// @Tags Curve
|
||||
// @Produce json
|
||||
// @Param brand query string true "品牌名称"
|
||||
// @Param name query string true "型号名称"
|
||||
// @Param target query string true "目标曲线名称"
|
||||
// @Param base64Resp query string false "是否返回 base64 编码响应"
|
||||
// @Success 200 {object} map[string]any "成功返回 parametric_eq 数据"
|
||||
// @Failure 400 {object} map[string]any "参数校验失败"
|
||||
// @Failure 500 {object} object
|
||||
// @Router /audio/getCurve [get]
|
||||
// @Tags Curve
|
||||
// @Produce json
|
||||
// @Param brand query string true "品牌名称"
|
||||
// @Param name query string true "型号名称"
|
||||
// @Param target query string true "目标曲线名称"
|
||||
// @Param base64Resp query string false "是否返回 base64 编码响应"
|
||||
// @Success 200 {object} map[string]any "成功返回 parametric_eq 数据"
|
||||
// @Failure 400 {object} map[string]any "参数校验失败"
|
||||
// @Failure 500 {object} object
|
||||
// @Router /audio/getCurve [get]
|
||||
//
|
||||
// GET /audio/getCurve?brand=xxx&name=xxx&target=xxx&base64Resp=true
|
||||
func (h *CurveHandler) GetCurve(c *gin.Context) {
|
||||
|
||||
@@ -29,9 +29,9 @@ func NewDeviceHandler(redis *redis.Client, log *zap.Logger) *DeviceHandler {
|
||||
// @Summary 上报设备信息
|
||||
// @Tags Device
|
||||
// @Produce json
|
||||
// @Param mac query string true "设备 MAC 地址"
|
||||
// @Param model query string true "设备型号"
|
||||
// @Param ver query string false "固件版本号"
|
||||
// @Param mac query string true "设备 MAC 地址"
|
||||
// @Param model query string true "设备型号"
|
||||
// @Param ver query string false "固件版本号"
|
||||
// @Success 200 {object} map[string]any "操作成功"
|
||||
// @Failure 500 {object} object
|
||||
// @Router /audio/reportDevInfo [get]
|
||||
|
||||
@@ -29,18 +29,18 @@ func NewModelCSVHandler(s3 *storage.S3Storage, log *zap.Logger) *ModelCSVHandler
|
||||
|
||||
// GetModelCSV 从 S3 读取耳机 CSV 频响数据
|
||||
//
|
||||
// @Summary 获取耳机原始频响 CSV 数据
|
||||
// @Summary 获取耳机原始频响 CSV 数据
|
||||
// @Description 从 S3 读取指定机型的测量 CSV 数据,返回 frequency 和 raw 数组
|
||||
// @Tags Curve
|
||||
// @Produce json
|
||||
// @Param brand query string true "品牌名称"
|
||||
// @Param model query string true "型号名称"
|
||||
// @Param form query string true "耳机类型 (in-ear/over-ear)"
|
||||
// @Param base64Resp query string false "是否返回 base64 编码响应"
|
||||
// @Success 200 {object} map[string]any "成功返回 frequency 和 raw 数组"
|
||||
// @Failure 400 {object} map[string]any "参数校验失败"
|
||||
// @Failure 500 {object} object
|
||||
// @Router /audio/getModelCSV [get]
|
||||
// @Tags Curve
|
||||
// @Produce json
|
||||
// @Param brand query string true "品牌名称"
|
||||
// @Param model query string true "型号名称"
|
||||
// @Param form query string true "耳机类型 (in-ear/over-ear)"
|
||||
// @Param base64Resp query string false "是否返回 base64 编码响应"
|
||||
// @Success 200 {object} map[string]any "成功返回 frequency 和 raw 数组"
|
||||
// @Failure 400 {object} map[string]any "参数校验失败"
|
||||
// @Failure 500 {object} object
|
||||
// @Router /audio/getModelCSV [get]
|
||||
//
|
||||
// GET /audio/getModelCSV?brand=Abyss&model=Dinan DZ&form=over-ear&base64Resp=true
|
||||
func (h *ModelCSVHandler) GetModelCSV(c *gin.Context) {
|
||||
|
||||
+11
-11
@@ -22,18 +22,18 @@ func NewOTAHandler(repo *repository.OTARepository, log *zap.Logger) *OTAHandler
|
||||
|
||||
// GetOTA 获取 OTA 升级信息
|
||||
//
|
||||
// @Summary 获取 OTA 升级信息
|
||||
// @Summary 获取 OTA 升级信息
|
||||
// @Description 根据设备型号和硬件版本查询最新 OTA 记录,支持黑名单过滤和定向升级逻辑
|
||||
// @Tags OTA
|
||||
// @Produce json
|
||||
// @Param model query string true "设备型号"
|
||||
// @Param hw query int true "硬件版本"
|
||||
// @Param mac query string false "设备 MAC 地址"
|
||||
// @Param beta query int false "是否 beta 通道 (0=否,1=是)"
|
||||
// @Success 200 {object} object "成功返回 OTA 信息"
|
||||
// @Failure 400 {object} object
|
||||
// @Failure 500 {object} object
|
||||
// @Router /audio/ota [get]
|
||||
// @Tags OTA
|
||||
// @Produce json
|
||||
// @Param model query string true "设备型号"
|
||||
// @Param hw query int true "硬件版本"
|
||||
// @Param mac query string false "设备 MAC 地址"
|
||||
// @Param beta query int false "是否 beta 通道 (0=否,1=是)"
|
||||
// @Success 200 {object} object "成功返回 OTA 信息"
|
||||
// @Failure 400 {object} object
|
||||
// @Failure 500 {object} object
|
||||
// @Router /audio/ota [get]
|
||||
func (h *OTAHandler) GetOTA(c *gin.Context) {
|
||||
modelVal := strings.TrimSpace(c.Query("model"))
|
||||
hwStr := strings.TrimSpace(c.Query("hw"))
|
||||
|
||||
@@ -22,16 +22,16 @@ func NewShareCodeHandler(shareCache *cache.ShareCodeCache, log *zap.Logger) *Sha
|
||||
|
||||
// ExportShareCode 导出分享码
|
||||
//
|
||||
// @Summary 创建 EQ 分享码
|
||||
// @Summary 创建 EQ 分享码
|
||||
// @Description 将用户的 EQ 数据生成一个 5 位分享码,有效期 30 分钟
|
||||
// @Tags ShareCode
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body object{mac=string,eq_data=object} true "分享请求"
|
||||
// @Success 200 {object} map[string]any "成功返回 share_code、expire_at、eq_data"
|
||||
// @Failure 400 {object} map[string]any "参数校验失败"
|
||||
// @Failure 500 {object} map[string]any "系统错误"
|
||||
// @Router /audio/shareCreate [post]
|
||||
// @Tags ShareCode
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body object{mac=string,eq_data=object} true "分享请求"
|
||||
// @Success 200 {object} map[string]any "成功返回 share_code、expire_at、eq_data"
|
||||
// @Failure 400 {object} map[string]any "参数校验失败"
|
||||
// @Failure 500 {object} map[string]any "系统错误"
|
||||
// @Router /audio/shareCreate [post]
|
||||
//
|
||||
// POST /audio/shareCreate
|
||||
// Body: {"mac": "xx", "eq_data": {...}}
|
||||
@@ -93,18 +93,70 @@ func (h *ShareCodeHandler) ExportShareCode(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// ListShareCodesByMac 查询某 MAC 尚未过期的分享码
|
||||
//
|
||||
// @Summary 查询未过期分享码
|
||||
// @Description 根据设备 MAC 地址查询该设备尚未过期的所有分享码(仅查询 Redis,依赖 TTL 自动过期)
|
||||
// @Tags ShareCode
|
||||
// @Produce json
|
||||
// @Param mac query string true "设备 MAC 地址"
|
||||
// @Success 200 {object} map[string]any "成功返回 share_codes 列表"
|
||||
// @Failure 400 {object} map[string]any "参数校验失败"
|
||||
// @Failure 500 {object} map[string]any "系统错误"
|
||||
// @Router /audio/shareList [get]
|
||||
func (h *ShareCodeHandler) ListShareCodesByMac(c *gin.Context) {
|
||||
mac := strings.TrimSpace(c.Query("mac"))
|
||||
if mac == "" {
|
||||
c.JSON(http.StatusOK, gin.H{"code": 400, "msg": "参数校验失败"})
|
||||
return
|
||||
}
|
||||
|
||||
ctx := c.Request.Context()
|
||||
|
||||
items, err := h.cache.ListByMac(ctx, mac)
|
||||
if err != nil {
|
||||
h.log.Error("list share codes by mac failed", zap.String("mac", mac), zap.Error(err))
|
||||
c.JSON(http.StatusOK, gin.H{"code": 500, "msg": "系统错误"})
|
||||
return
|
||||
}
|
||||
|
||||
type shareItem struct {
|
||||
ShareCode string `json:"share_code"`
|
||||
ExpireAt string `json:"expire_at"`
|
||||
EqData any `json:"eq_data"`
|
||||
}
|
||||
list := make([]shareItem, 0, len(items))
|
||||
for _, item := range items {
|
||||
var eqData any
|
||||
if err := json.Unmarshal([]byte(item.EqData), &eqData); err != nil {
|
||||
eqData = item.EqData
|
||||
}
|
||||
list = append(list, shareItem{
|
||||
ShareCode: item.ShareCode,
|
||||
ExpireAt: item.ExpireAt.Format("2006-01-02 15:04:05"),
|
||||
EqData: eqData,
|
||||
})
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"msg": "操作成功",
|
||||
"share_codes": list,
|
||||
})
|
||||
}
|
||||
|
||||
// ImportShareCode 导入分享码
|
||||
//
|
||||
// @Summary 导入 EQ 分享码
|
||||
// @Summary 导入 EQ 分享码
|
||||
// @Description 根据分享码获取他人分享的 EQ 数据
|
||||
// @Tags ShareCode
|
||||
// @Produce json
|
||||
// @Param mac query string true "设备 MAC 地址"
|
||||
// @Param shareCode query string true "5 位分享码"
|
||||
// @Success 200 {object} map[string]any "成功返回 eq_data"
|
||||
// @Failure 400 {object} map[string]any "参数校验失败"
|
||||
// @Failure 500 {object} map[string]any "系统错误"
|
||||
// @Router /audio/shareAccept [get]
|
||||
// @Tags ShareCode
|
||||
// @Produce json
|
||||
// @Param mac query string true "设备 MAC 地址"
|
||||
// @Param shareCode query string true "5 位分享码"
|
||||
// @Success 200 {object} map[string]any "成功返回 eq_data"
|
||||
// @Failure 400 {object} map[string]any "参数校验失败"
|
||||
// @Failure 500 {object} map[string]any "系统错误"
|
||||
// @Router /audio/shareAccept [get]
|
||||
//
|
||||
// GET /audio/shareAccept?mac=xx&shareCode=ABC12
|
||||
func (h *ShareCodeHandler) ImportShareCode(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user