refactor(token): 修改参数验证和删除逻辑
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
//输出信息
|
||||
|
@@ -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
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -100,7 +116,17 @@ axios.get('/api/token').then(res => {
|
||||
|
||||
<p><b>管理</b></p>
|
||||
<el-button type="danger" @click="deleteDedup">删除去重记录值</el-button>
|
||||
<el-button type="danger" @click="deleteRedis">删除Redis数据</el-button>
|
||||
<el-button type="danger" @click="deleteRedis">删除全部Redis数据</el-button>
|
||||
<el-button type="danger" @click="deleteSpecifyRedisVisible=true">删除指定数量Redis数据</el-button>
|
||||
|
||||
<el-dialog v-model="deleteSpecifyRedisVisible" title="删除指定数量Redis数据" width="400">
|
||||
<el-input v-model="inputSpecifyRedis" style="width: 200px" placeholder="请输入删除数量"/>
|
||||
<template #footer>
|
||||
<el-button type="primary" @click="deleteSpecifyRedis">
|
||||
确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
Reference in New Issue
Block a user