Compare commits

..

3 Commits

Author SHA1 Message Date
f883b0a7d8 refactor(tool): 优化文件处理逻辑和性能
All checks were successful
构建上传工具 / build (push) Successful in 1m2s
部署开发环境 / build-and-deploy (push) Successful in 1m17s
2025-09-10 21:26:24 +08:00
861ac5d365 refactor(token): 修改参数验证和删除逻辑 2025-09-10 17:03:09 +08:00
1e4c2d540e build: 简化Go安装流程,移除冗余代码 2025-09-10 15:12:47 +08:00
4 changed files with 64 additions and 24 deletions

View File

@@ -13,9 +13,7 @@ jobs:
- name: 安装Go镜像 - name: 安装Go镜像
run: | run: |
# 使用国内镜像下载 Go # 使用国内镜像下载 Go
export GO_MIRROR_URL="https://mirrors.aliyun.com/golang" wget https://mirrors.aliyun.com/golang/go1.25.1.linux-amd64.tar.gz -O go.tar.gz
wget $GO_MIRROR_URL/go1.25.1.linux-amd64.tar.gz -O go.tar.gz
# 解压并设置环境变量 # 解压并设置环境变量
sudo rm -rf /usr/local/go sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go.tar.gz sudo tar -C /usr/local -xzf go.tar.gz
@@ -23,11 +21,6 @@ jobs:
env: env:
GOROOT: /usr/local/go GOROOT: /usr/local/go
# - name: 安装Go
# uses: actions/setup-go@v5
# with:
# go-version-file: "go.mod"
- name: 构建上传工具 - name: 构建上传工具
run: | run: |
go env -w CGO_ENABLED=0 \ go env -w CGO_ENABLED=0 \

View File

@@ -3,7 +3,9 @@ package controller
import ( import (
"dypid/db" "dypid/db"
"dypid/global" "dypid/global"
"fmt"
"net/http" "net/http"
"strconv"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -18,7 +20,7 @@ func CreateTokenHandler(c *gin.Context) {
Token string `form:"token" binding:"required"` Token string `form:"token" binding:"required"`
DedupObject string `form:"dedup_object" binding:"required"` DedupObject string `form:"dedup_object" binding:"required"`
DataFormat string `form:"data_format" 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 { if err := c.ShouldBindQuery(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()}) c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
@@ -41,7 +43,7 @@ func UpdateTokenHandler(c *gin.Context) {
Token string `form:"token" binding:"required"` Token string `form:"token" binding:"required"`
DedupObject string `form:"dedup_object" binding:"required"` DedupObject string `form:"dedup_object" binding:"required"`
DataFormat string `form:"data_format" 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 { if err := c.ShouldBindQuery(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()}) c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
@@ -115,8 +117,8 @@ func DeleteTokenInfoHandler(c *gin.Context) {
//解析输入数据 //解析输入数据
input := struct { input := struct {
Token string `form:"token" binding:"required"` Token string `form:"token" binding:"required"`
DedupBF bool `form:"dedup_bf"` DedupBF string `form:"dedup_bf"`
CacheList bool `form:"cache_list"` CacheList string `form:"cache_list"`
}{} }{}
if err := c.ShouldBindQuery(&input); err != nil { if err := c.ShouldBindQuery(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Token不能为空"}) 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() keys := global.RDB.Keys(global.RCtx, "dedup:"+input.Token+":*").Val()
global.RDB.Del(global.RCtx, keys...) 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) 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))
} }
//输出信息 //输出信息

View File

@@ -48,7 +48,6 @@ func main() {
//检测./upload //检测./upload
fmt.Println("程序启动成功正在检测txt文件") fmt.Println("程序启动成功正在检测txt文件")
//os.Mkdir("./upload", os.ModePerm)
for { for {
files, err := getTxtFiles("./") files, err := getTxtFiles("./")
if err != nil { if err != nil {
@@ -62,16 +61,19 @@ func main() {
wg.Add(1) wg.Add(1)
go func() { go func() {
processFile(filePath) processFile(filePath)
os.Remove(filePath) err := os.Truncate(filePath, 0)
if err != nil {
fmt.Println("清空文件失败:", err)
}
wg.Done() wg.Done()
}() }()
} }
wg.Wait() wg.Wait()
} }
time.Sleep(2 * time.Second) time.Sleep(time.Minute)
} }
} }
func uploadDataToServer(data string) error { func uploadDataToServer(data string) error {
params := url.Values{} params := url.Values{}
params.Set("token", viper.GetString("token")) params.Set("token", viper.GetString("token"))
@@ -88,10 +90,8 @@ func uploadDataToServer(data string) error {
} }
// 获取目录中的所有txt文件 // 获取目录中的所有txt文件
func getTxtFiles(dir string) ([]string, error) { func getTxtFiles(dir string) (txtFiles []string, err error) {
var txtFiles []string err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
@@ -151,6 +151,7 @@ func processFile(filePath string) {
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil {
fmt.Printf("读取文件 %s 错误: %v\n", filePath, err) fmt.Printf("读取文件 %s 错误: %v\n", filePath, err)
return
} }
fmt.Printf("文件【%s】处理完成共处理 %d 行数据\n", filePath, lineCount) fmt.Printf("文件【%s】处理完成共处理 %d 行数据\n", filePath, lineCount)

View File

@@ -34,11 +34,12 @@ const deleteDedup = () => {
getInfo() getInfo()
}) })
} }
const deleteRedis = () => { const deleteRedis = () => {
axios.delete('/api/token/info', { axios.delete('/api/token/info', {
params: { params: {
token: value.value, token: value.value,
cache_list: true cache_list: "all",
} }
}).then(res => { }).then(res => {
getInfo() 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> </script>
@@ -100,7 +116,17 @@ axios.get('/api/token').then(res => {
<p><b>管理</b></p> <p><b>管理</b></p>
<el-button type="danger" @click="deleteDedup">删除去重记录值</el-button> <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> </div>
</template> </template>