diff --git a/controller/tokenController.go b/controller/tokenController.go index 117a2ce..d89007e 100644 --- a/controller/tokenController.go +++ b/controller/tokenController.go @@ -3,7 +3,9 @@ package controller import ( "dypid/db" "dypid/global" + "fmt" "net/http" + "strconv" "github.com/gin-gonic/gin" ) @@ -18,7 +20,7 @@ func CreateTokenHandler(c *gin.Context) { Token string `form:"token" binding:"required"` DedupObject string `form:"dedup_object" binding:"required"` DataFormat string `form:"data_format" binding:"required"` - Notes string `form:"notes" binding:"required"` + Notes string `form:"notes"` }{} if err := c.ShouldBindQuery(&input); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()}) @@ -41,7 +43,7 @@ func UpdateTokenHandler(c *gin.Context) { Token string `form:"token" binding:"required"` DedupObject string `form:"dedup_object" binding:"required"` DataFormat string `form:"data_format" binding:"required"` - Notes string `form:"notes" binding:"required"` + Notes string `form:"notes"` }{} if err := c.ShouldBindQuery(&input); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()}) @@ -115,8 +117,8 @@ func DeleteTokenInfoHandler(c *gin.Context) { //解析输入数据 input := struct { Token string `form:"token" binding:"required"` - DedupBF bool `form:"dedup_bf"` - CacheList bool `form:"cache_list"` + DedupBF string `form:"dedup_bf"` + CacheList string `form:"cache_list"` }{} if err := c.ShouldBindQuery(&input); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "Token不能为空"}) @@ -131,12 +133,30 @@ func DeleteTokenInfoHandler(c *gin.Context) { } //删除去重对象 - if input.DedupBF { + switch input.DedupBF { + case "": + case "all": keys := global.RDB.Keys(global.RCtx, "dedup:"+input.Token+":*").Val() global.RDB.Del(global.RCtx, keys...) + default: + _, err := strconv.Atoi(input.DedupBF) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_bf设置错误 " + err.Error()}) + return + } } - if input.CacheList { + switch input.CacheList { + case "": + case "all": global.RDB.Del(global.RCtx, "list:"+input.Token) + default: + i, err := strconv.Atoi(input.CacheList) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": "cache_list设置错误 " + err.Error()}) + return + } + fmt.Println(-i) + global.RDB.LTrim(global.RCtx, "list:"+input.Token, 1, int64(-i)) } //输出信息 diff --git a/web/src/views/TokenDetailView.vue b/web/src/views/TokenDetailView.vue index e54e09a..ddf057d 100644 --- a/web/src/views/TokenDetailView.vue +++ b/web/src/views/TokenDetailView.vue @@ -34,11 +34,12 @@ const deleteDedup = () => { getInfo() }) } + const deleteRedis = () => { axios.delete('/api/token/info', { params: { token: value.value, - cache_list: true + cache_list: "all", } }).then(res => { getInfo() @@ -66,6 +67,21 @@ axios.get('/api/token').then(res => { }) } }) + +const deleteSpecifyRedisVisible = ref(false) +const inputSpecifyRedis = ref('') + +const deleteSpecifyRedis = () => { + axios.delete('/api/token/info', { + params: { + token: value.value, + cache_list: inputSpecifyRedis.value, + } + }).then(res => { + getInfo() + deleteSpecifyRedisVisible.value = false + }) +} @@ -100,7 +116,17 @@ axios.get('/api/token').then(res => {

管理

删除去重记录值 - 删除Redis数据 + 删除全部Redis数据 + 删除指定数量Redis数据 + + + + +