Compare commits
3 Commits
f883b0a7d8
...
1c56423ea4
Author | SHA1 | Date | |
---|---|---|---|
1c56423ea4 | |||
5d304b6334 | |||
5e3c0762ab |
@@ -2,7 +2,7 @@ name: 构建上传工具
|
||||
on: [ push ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
build-tool:
|
||||
env:
|
||||
RUNNER_TOOL_CACHE: /toolcache
|
||||
runs-on: ubuntu-latest
|
||||
|
@@ -2,7 +2,7 @@ name: 部署开发环境
|
||||
on: [ push ]
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
deploy-dev:
|
||||
env:
|
||||
RUNNER_TOOL_CACHE: /toolcache
|
||||
runs-on: ubuntu-latest
|
||||
|
@@ -3,7 +3,7 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
deploy-production:
|
||||
env:
|
||||
RUNNER_TOOL_CACHE: /toolcache
|
||||
runs-on: ubuntu-latest
|
||||
|
@@ -31,6 +31,7 @@ func ReadDataHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
func WriteDataHandler(c *gin.Context) {
|
||||
//解析输入数据
|
||||
input := struct {
|
||||
Token string `form:"token" binding:"required"`
|
||||
Data string `form:"data" binding:"required"`
|
||||
@@ -40,6 +41,7 @@ func WriteDataHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
//数据获取
|
||||
dedupObject, err := db.GetDedupObject(input.Token)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
@@ -52,7 +54,7 @@ func WriteDataHandler(c *gin.Context) {
|
||||
}
|
||||
dedupValue := strings.Split(input.Data, "----")[dataIndex[dedupObject]]
|
||||
|
||||
err = createBF(fmt.Sprintf("dedup:%s:%s", input.Token, dedupObject), 0.01, 100000000)
|
||||
err = createCF(fmt.Sprintf("dedup:%s:%s", input.Token, dedupObject), 100000000)
|
||||
if err != nil && err.Error() != "ERR item exists" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -64,7 +66,7 @@ local dedupValue = ARGV[1] -- ARGV[1]: 去重值
|
||||
local rawData = ARGV[2] -- ARGV[2]: 原始数据
|
||||
|
||||
-- 检查布隆过滤器中是否已存在该值
|
||||
local exists = redis.call('BF.EXISTS', dedupKey, dedupValue)
|
||||
local exists = redis.call('CF.EXISTS', dedupKey, dedupValue)
|
||||
|
||||
-- 如果已存在,返回已去重标记
|
||||
if exists == 1 then
|
||||
@@ -72,7 +74,7 @@ if exists == 1 then
|
||||
end
|
||||
|
||||
-- 添加到布隆过滤器
|
||||
redis.call('BF.ADD', dedupKey, dedupValue)
|
||||
redis.call('CF.ADD', dedupKey, dedupValue)
|
||||
-- 添加到列表
|
||||
redis.call('LPUSH', listKey, rawData)
|
||||
|
||||
@@ -102,8 +104,8 @@ return "ok"
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "WriteDataHandler 错误"})
|
||||
}
|
||||
|
||||
func createBF(bloomFilter string, errorRate float64, capacity int64) error {
|
||||
_, err := global.RDB.BFReserve(global.RCtx, bloomFilter, errorRate, capacity).Result()
|
||||
func createCF(bloomFilter string, capacity int64) error {
|
||||
_, err := global.RDB.CFReserve(global.RCtx, bloomFilter, capacity).Result()
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -3,9 +3,9 @@ package controller
|
||||
import (
|
||||
"dypid/db"
|
||||
"dypid/global"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -116,9 +116,10 @@ func GetTokenInfoHandler(c *gin.Context) {
|
||||
func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
//解析输入数据
|
||||
input := struct {
|
||||
Token string `form:"token" binding:"required"`
|
||||
DedupBF string `form:"dedup_bf"`
|
||||
CacheList string `form:"cache_list"`
|
||||
Token string `form:"token" binding:"required"`
|
||||
DedupBF string `form:"dedup_bf"`
|
||||
CacheList string `form:"cache_list"`
|
||||
BothNumber string `form:"both_number"`
|
||||
}{}
|
||||
if err := c.ShouldBindQuery(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Token不能为空"})
|
||||
@@ -132,6 +133,12 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
dedupObject, err := db.GetDedupObject(input.Token)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
//删除去重对象
|
||||
switch input.DedupBF {
|
||||
case "":
|
||||
@@ -139,6 +146,7 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
keys := global.RDB.Keys(global.RCtx, "dedup:"+input.Token+":*").Val()
|
||||
global.RDB.Del(global.RCtx, keys...)
|
||||
default:
|
||||
//TODO 不考虑单独删除指定数量去重参考值
|
||||
_, err := strconv.Atoi(input.DedupBF)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_bf设置错误 " + err.Error()})
|
||||
@@ -155,9 +163,25 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
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))
|
||||
}
|
||||
//TODO
|
||||
switch input.BothNumber {
|
||||
case "":
|
||||
default:
|
||||
i, err := strconv.Atoi(input.BothNumber)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "both_number设置错误 " + err.Error()})
|
||||
return
|
||||
}
|
||||
result := global.RDB.LRange(global.RCtx, "list:"+input.Token, 1, int64(i)).Val()
|
||||
global.RDB.LTrim(global.RCtx, "list:"+input.Token, 1, int64(-i))
|
||||
dataIndex, err := getDataIndex(input.Token)
|
||||
for _, s := range result {
|
||||
s2 := strings.Split(s, "----")[dataIndex[dedupObject]]
|
||||
global.RDB.CFDel(global.RCtx, "dedup:"+input.Token+":"+dedupObject, s2)
|
||||
}
|
||||
}
|
||||
|
||||
//输出信息
|
||||
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
||||
|
@@ -26,6 +26,41 @@ var httpClient = &http.Client{
|
||||
}
|
||||
|
||||
func main() {
|
||||
initConfig()
|
||||
|
||||
//检测./upload
|
||||
fmt.Println("程序启动成功,正在检测txt文件")
|
||||
for {
|
||||
files, err := getTxtFiles("./")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if files != nil {
|
||||
start := time.Now()
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
for _, filePath := range files {
|
||||
fmt.Println("正在上传文件:", filePath)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
processFile(filePath)
|
||||
err := os.Truncate(filePath, 0)
|
||||
if err != nil {
|
||||
fmt.Println("清空文件失败:", err)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
fmt.Println("上传完成,耗时:", time.Since(start))
|
||||
}
|
||||
time.Sleep(time.Minute)
|
||||
}
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
//程序配置
|
||||
viper.SetDefault("url", "http://localhost:8080")
|
||||
viper.SetDefault("token", "")
|
||||
@@ -45,33 +80,6 @@ func main() {
|
||||
fmt.Errorf("无法读取配置文件: %w", err)
|
||||
}
|
||||
})
|
||||
|
||||
//检测./upload
|
||||
fmt.Println("程序启动成功,正在检测txt文件")
|
||||
for {
|
||||
files, err := getTxtFiles("./")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if files != nil {
|
||||
wg := sync.WaitGroup{}
|
||||
for _, filePath := range files {
|
||||
fmt.Println("正在上传文件:", filePath)
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
processFile(filePath)
|
||||
err := os.Truncate(filePath, 0)
|
||||
if err != nil {
|
||||
fmt.Println("清空文件失败:", err)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
time.Sleep(time.Minute)
|
||||
}
|
||||
}
|
||||
|
||||
func uploadDataToServer(data string) error {
|
||||
|
@@ -5,10 +5,20 @@ import axios from "@/axios.ts";
|
||||
import {useRoute} from "vue-router"
|
||||
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
// 创建响应式引用,用于存储API请求结果
|
||||
const result = ref()
|
||||
|
||||
// 创建响应式引用,用于存储当前选中的token值
|
||||
const value = ref('')
|
||||
value.value = useCounterStore().token
|
||||
|
||||
// 创建响应式引用,用于存储下拉选项列表
|
||||
const options = ref([] as string[])
|
||||
|
||||
// 控制删除指定Redis键的确认对话框的显示状态
|
||||
const deleteSpecifyDataVisible = ref(false)
|
||||
const inputSpecifyData = ref('')
|
||||
|
||||
|
||||
const getInfo = () => {
|
||||
if (value.value != '') {
|
||||
@@ -28,7 +38,7 @@ const deleteDedup = () => {
|
||||
axios.delete('/api/token/info', {
|
||||
params: {
|
||||
token: value.value,
|
||||
dedup_bf: true
|
||||
dedup_bf: "all"
|
||||
}
|
||||
}).then(res => {
|
||||
getInfo()
|
||||
@@ -53,33 +63,24 @@ watch(value, (newValue) => {
|
||||
getInfo()
|
||||
})
|
||||
|
||||
interface optionsType {
|
||||
value: string
|
||||
}
|
||||
|
||||
const options = ref([] as optionsType[])
|
||||
value.value = useCounterStore().token
|
||||
|
||||
axios.get('/api/token').then(res => {
|
||||
if (res.status == 200) {
|
||||
res.data.result.forEach((item: any) => {
|
||||
options.value.push({"value": item.token})
|
||||
options.value.push(item.token)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const deleteSpecifyRedisVisible = ref(false)
|
||||
const inputSpecifyRedis = ref('')
|
||||
|
||||
const deleteSpecifyRedis = () => {
|
||||
const deleteSpecifyData = () => {
|
||||
axios.delete('/api/token/info', {
|
||||
params: {
|
||||
token: value.value,
|
||||
cache_list: inputSpecifyRedis.value,
|
||||
cache_list: inputSpecifyData.value,
|
||||
}
|
||||
}).then(res => {
|
||||
getInfo()
|
||||
deleteSpecifyRedisVisible.value = false
|
||||
deleteSpecifyDataVisible.value = false
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@@ -90,17 +91,19 @@ const deleteSpecifyRedis = () => {
|
||||
<el-alert title="您没有权限访问此页面" type="error" center show-icon/>
|
||||
</div>
|
||||
|
||||
|
||||
<div v-if="useCounterStore().isAdmin">
|
||||
<b>当前Token:</b>
|
||||
<el-select v-model="value" placeholder="选择Token" style="width: 240px">
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.value"
|
||||
:value="item.value"
|
||||
:key="item"
|
||||
:value="item"
|
||||
/>
|
||||
</el-select>
|
||||
|
||||
<el-divider/>
|
||||
|
||||
<b>Token信息(每5秒刷新)</b>
|
||||
<el-button type="primary" plain @click="getInfo">手动刷新</el-button>
|
||||
<el-descriptions
|
||||
@@ -108,21 +111,35 @@ const deleteSpecifyRedis = () => {
|
||||
:column="4"
|
||||
border
|
||||
>
|
||||
<el-descriptions-item label="去重对象">{{ result?.dedup_object }}</el-descriptions-item>
|
||||
<el-descriptions-item label="上传数据格式">{{ result?.data_format }}</el-descriptions-item>
|
||||
<el-descriptions-item label="去重记录值">{{ result?.dedup_items_number }}</el-descriptions-item>
|
||||
<el-descriptions-item label="Redis中数据条数">{{ result?.cache_list_number }}</el-descriptions-item>
|
||||
<el-descriptions-item label="去重对象" label-width="150px">
|
||||
<el-tag>{{ result?.dedup_object }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="上传数据格式" label-width="150px">
|
||||
{{ result?.data_format }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="去重参考值数量" label-width="150px">
|
||||
{{ result?.dedup_items_number }} 条
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="原始数据数量" label-width="150px">
|
||||
{{ result?.cache_list_number }} 条
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<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="deleteSpecifyRedisVisible=true">删除指定数量Redis数据</el-button>
|
||||
<el-button type="danger" @click="deleteDedup">删除全部去重参考值</el-button>
|
||||
<el-button type="danger" @click="deleteRedis">删除全部原始数据</el-button>
|
||||
<div style="margin-top: 10px">
|
||||
<el-button type="danger" @click="deleteSpecifyDataVisible=true">
|
||||
删除指定数量的数据(去重参考值+原始数据)
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="deleteSpecifyRedisVisible" title="删除指定数量Redis数据" width="400">
|
||||
<el-input v-model="inputSpecifyRedis" style="width: 200px" placeholder="请输入删除数量"/>
|
||||
|
||||
<!--弹窗输入-->
|
||||
<el-dialog v-model="deleteSpecifyDataVisible" title="删除指定数量的数据" width="400">
|
||||
<el-input v-model="inputSpecifyData" style="width: 200px" placeholder="请输入删除数量"/>
|
||||
<template #footer>
|
||||
<el-button type="primary" @click="deleteSpecifyRedis">
|
||||
<el-button type="primary" @click="deleteSpecifyData">
|
||||
确定
|
||||
</el-button>
|
||||
</template>
|
||||
|
@@ -6,13 +6,16 @@ import {useCounterStore} from "@/stores/counter.ts";
|
||||
import {useRouter} from "vue-router";
|
||||
|
||||
const tableData = ref([])
|
||||
|
||||
axios.get("/api/token").then(res => {
|
||||
tableData.value = res.data.result
|
||||
})
|
||||
|
||||
const input = ref('')
|
||||
const value = ref('')
|
||||
const dataFormat = ref('')
|
||||
const inputPassWord = ref('')
|
||||
const router = useRouter()
|
||||
var rowOut: any
|
||||
const dedupObjectVisible = ref(false)
|
||||
const dataFormatVisible = ref(false)
|
||||
const inputNotes = ref("")
|
||||
const NotesVisible = ref(false)
|
||||
const options = [
|
||||
{
|
||||
value: 'uid',
|
||||
@@ -31,7 +34,6 @@ const options = [
|
||||
}
|
||||
]
|
||||
|
||||
const dataFormat = ref('')
|
||||
const dataFormatOptions = [
|
||||
{
|
||||
value: 'uid----secid----pid----comment_id',
|
||||
@@ -40,6 +42,11 @@ const dataFormatOptions = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
axios.get("/api/token").then(res => {
|
||||
tableData.value = res.data.result
|
||||
})
|
||||
|
||||
const addToken = () => {
|
||||
axios.post('/api/token', {}, {
|
||||
params: {
|
||||
@@ -63,8 +70,6 @@ const addToken = () => {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const router = useRouter()
|
||||
const viewDetails = (row: any) => {
|
||||
useCounterStore().token = row.token
|
||||
router.push({
|
||||
@@ -72,13 +77,11 @@ const viewDetails = (row: any) => {
|
||||
})
|
||||
}
|
||||
|
||||
var rowOut: any
|
||||
|
||||
const dedupObjectVisible = ref(false)
|
||||
const dialogDedupObjectVisible = (row: any) => {
|
||||
rowOut = row
|
||||
dedupObjectVisible.value = true
|
||||
}
|
||||
|
||||
const updateDedupObject = () => {
|
||||
dedupObjectVisible.value = false
|
||||
axios.put('/api/token', {}, {
|
||||
@@ -103,11 +106,11 @@ const updateDedupObject = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const dataFormatVisible = ref(false)
|
||||
const dialogDataFormatVisible = (row: any) => {
|
||||
rowOut = row
|
||||
dataFormatVisible.value = true
|
||||
}
|
||||
|
||||
const updateDataFormat = () => {
|
||||
dataFormatVisible.value = false
|
||||
axios.put('/api/token', {}, {
|
||||
@@ -132,12 +135,11 @@ const updateDataFormat = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const inputNotes = ref("")
|
||||
const NotesVisible = ref(false)
|
||||
const dialogNotesVisible = (row: any) => {
|
||||
rowOut = row
|
||||
NotesVisible.value = true
|
||||
}
|
||||
|
||||
const updateNotes = () => {
|
||||
NotesVisible.value = false
|
||||
axios.put('/api/token', {}, {
|
||||
@@ -182,7 +184,6 @@ const deleteToken = (row: any) => {
|
||||
})
|
||||
}
|
||||
|
||||
const inputPassWord = ref('')
|
||||
const checkPassword = () => {
|
||||
if (inputPassWord.value == "haha") {
|
||||
ElMessage({
|
||||
@@ -228,7 +229,7 @@ const checkPassword = () => {
|
||||
<el-button type="primary" @click="addToken">添加Token</el-button>
|
||||
|
||||
<!--Token列表-->
|
||||
<el-table :data="tableData" style="width: 100%">
|
||||
<el-table :data="tableData" stripe style="width: 100%">
|
||||
<el-table-column prop="token" label="Token" width="150"/>
|
||||
<el-table-column prop="dedup_object" label="去重对象" width="150"/>
|
||||
<el-table-column prop="data_format" label="上传数据格式" width="280"/>
|
||||
|
Reference in New Issue
Block a user