Compare commits

..

37 Commits

Author SHA1 Message Date
a505f2ddc9 Merge remote-tracking branch 'origin/main'
All checks were successful
构建上传工具 / build-tool (push) Successful in 1m27s
部署开发环境 / deploy-dev (push) Successful in 1m47s
2025-09-18 20:34:13 +08:00
42cfe0dc0f feat(token): 添加Token存在性检查 2025-09-18 20:32:19 +08:00
2c8e25bdf8 refactor: 更新页面标题为抖音数据去重 2025-09-17 12:21:31 +08:00
0992b02880 更新 web/src/views/TokenManageView.vue
Some checks failed
构建上传工具 / build-tool (push) Successful in 59s
部署开发环境 / deploy-dev (push) Has been cancelled
2025-09-16 06:14:45 +00:00
1f8a5b8c37 更新 web/src/views/TokenManageView.vue
Some checks failed
构建上传工具 / build-tool (push) Successful in 56s
部署开发环境 / deploy-dev (push) Failing after 44s
2025-09-16 06:04:50 +00:00
795a9186a9 refactor(data): 优化数据读取和删除逻辑
Some checks failed
构建上传工具 / build-tool (push) Failing after 2s
部署开发环境 / deploy-dev (push) Failing after 2s
2025-09-16 12:49:32 +08:00
69d4c5d038 refactor(token): 优化Token状态管理和数据更新逻辑
Some checks failed
构建上传工具 / build-tool (push) Failing after 37s
部署开发环境 / deploy-dev (push) Failing after 8s
2025-09-15 23:20:41 +08:00
78d496ae72 refactor(controller): 优化Redis去重和缓存删除逻辑
All checks were successful
构建上传工具 / build-tool (push) Successful in 56s
部署开发环境 / deploy-dev (push) Successful in 1m39s
2025-09-14 22:51:04 +08:00
4c19f4b16c refactor: 优化输出格式和去重项计数方法
All checks were successful
构建上传工具 / build-tool (push) Successful in 1m5s
部署开发环境 / deploy-dev (push) Successful in 1m18s
2025-09-12 22:52:18 +08:00
1c56423ea4 refactor: 将布隆过滤器改为Cuckoo过滤器并优化代码结构
All checks were successful
构建上传工具 / build-tool (push) Successful in 59s
部署开发环境 / deploy-dev (push) Successful in 1m36s
2025-09-12 22:26:45 +08:00
5d304b6334 refactor(token): 优化表格样式和删除功能 2025-09-12 00:07:07 +08:00
5e3c0762ab refactor(token): 优化Token管理界面和重构工作流 2025-09-11 22:47:08 +08:00
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
af3a297bb4 build(workflows): 优化Go安装方式,使用国内镜像并调整artifact版本
All checks were successful
构建上传工具 / build (push) Successful in 59s
部署开发环境 / build-and-deploy (push) Successful in 1m11s
2025-09-09 23:46:26 +08:00
eb88f4b231 ops(workflow): 添加开发环境部署配置并优化生产环境部署
Some checks failed
构建上传工具 / build (push) Failing after 5m47s
部署开发环境 / build-and-deploy (push) Successful in 1m21s
2025-09-09 23:37:36 +08:00
cf4287ddd9 build(tool): 添加Windows上传工具构建工作流
Some checks failed
构建上传工具 / build (push) Failing after 5m58s
构建Docker镜像 / build-and-deploy (push) Successful in 1m31s
2025-09-09 23:29:23 +08:00
88aee26105 更新 .gitea/workflows/deploy.yaml
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 3m5s
2025-09-09 12:55:42 +00:00
b6ce840400 feat(token): 添加备注功能和相关接口
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m41s
2025-09-06 17:43:20 +08:00
333882c9e0 feat(auth): 修改管理员密码和路由路径
Some checks failed
构建Docker镜像 / build-and-deploy (push) Has been cancelled
2025-09-05 20:16:39 +08:00
640b1aa99e feat(auth): 重构权限管理系统和路由结构
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m33s
2025-09-04 13:08:48 +08:00
509b274c5c ops(ci): 添加测试服务器部署流程
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m37s
2025-09-04 09:25:39 +08:00
4c1e0d417d feat(data): 添加数据格式支持 更改数据写入读取
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m33s
2025-09-03 20:10:19 +08:00
deb958b71b build: 修改构建脚本
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m5s
2025-09-03 01:03:02 +08:00
ad1f450b19 build: 修改构建脚本
Some checks failed
构建Docker镜像 / build (push) Has been cancelled
2025-09-03 01:02:15 +08:00
c675324d6d build: 修改构建脚本
All checks were successful
构建Docker镜像 / build (push) Successful in 1m3s
2025-09-03 00:57:53 +08:00
9a31fa96b5 build: 修改构建脚本
All checks were successful
构建Docker镜像 / build (push) Successful in 1m48s
构建Docker镜像 / deploy (push) Successful in 47s
2025-09-02 22:55:15 +08:00
fb4709e59a build: 修改构建脚本
Some checks failed
构建Docker镜像 / build (push) Successful in 1m48s
构建Docker镜像 / deploy (push) Failing after 45s
2025-09-02 22:50:21 +08:00
7e6f5e3a19 build: 修改构建脚本
Some checks failed
构建Docker镜像 / build (push) Successful in 1m49s
构建Docker镜像 / deploy (push) Failing after 43s
2025-09-02 22:43:57 +08:00
f2e7d7a5c4 build: 修改构建脚本
Some checks failed
构建Docker镜像 / build (push) Successful in 1m40s
构建Docker镜像 / deploy (push) Failing after 46s
2025-09-02 22:33:19 +08:00
7adcebee75 ops: 添加CI/CD构建和部署流程
Some checks failed
构建Docker镜像 / build (push) Failing after 1m16s
构建Docker镜像 / deploy (push) Has been skipped
2025-09-02 22:29:39 +08:00
94e472a6c4 build: Gitea Actions测试
All checks were successful
构建Docker镜像 / build (push) Successful in 58s
2025-09-02 21:24:50 +08:00
da7f40642e build: Gitea Actions测试
All checks were successful
构建Docker镜像 / build (push) Successful in 54s
2025-09-02 20:38:42 +08:00
2d80cac3fd build: Gitea Actions测试
Some checks failed
构建Docker镜像 / build (push) Failing after 1m54s
2025-09-02 20:24:50 +08:00
e20ff1a3b7 build: Gitea Actions测试
Some checks failed
构建Docker镜像 / build (push) Failing after 16s
2025-09-02 20:22:14 +08:00
f2e9afc8aa build: Gitea Actions测试
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 52s
2025-09-02 17:31:36 +08:00
16 changed files with 862 additions and 289 deletions

View File

@@ -0,0 +1,37 @@
name: 构建上传工具
on: [ push ]
jobs:
build-tool:
env:
RUNNER_TOOL_CACHE: /toolcache
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 安装Go镜像
run: |
# 使用国内镜像下载 Go
wget https://mirrors.aliyun.com/golang/go1.25.1.linux-amd64.tar.gz -O go.tar.gz
# 解压并设置环境变量
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go.tar.gz
echo "/usr/local/go/bin" >> $GITHUB_PATH
env:
GOROOT: /usr/local/go
- name: 构建上传工具
run: |
go env -w CGO_ENABLED=0 \
&& go env -w GOARCH=amd64 \
&& go env -w GOOS=windows \
&& go mod tidy \
&& cd ./tool \
&& go build -o 上传工具.exe
- name: 上传构建文件
uses: actions/upload-artifact@v3
with:
name: 上传工具
path: tool/上传工具.exe

View File

@@ -0,0 +1,39 @@
name: 部署开发环境
on: [ push ]
jobs:
deploy-dev:
env:
RUNNER_TOOL_CACHE: /toolcache
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 构建Docker镜像
run: docker build -t dypid:latest .
- name: 导出镜像
run: mkdir release && docker save -o release/dypid.tar dypid:latest && docker rmi dypid:latest
- name: 安装sshpass工具
run: |
apt update
apt install -y sshpass
- name: 部署程序到测试服务器
env:
SSH_HOST: ${{ secrets.TEST_SSH_HOST }}
SSH_USER: ${{ secrets.TEST_SSH_USER }}
SSH_PASSWORD: ${{ secrets.TEST_SSH_PASSWORD }}
DEPLOY_DIR: "/data/dypid"
run: |
set -ex
# 上传新镜像
sshpass -p "$SSH_PASSWORD" scp -o StrictHostKeyChecking=no release/dypid.tar $SSH_USER@$SSH_HOST:/tmp/dypid.tar
# 重启程序
sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST \
"docker load -i /tmp/dypid.tar \
&& cd $DEPLOY_DIR \
&& docker compose up -d \
&& docker image prune -f"

View File

@@ -0,0 +1,40 @@
name: 部署生产环境
on:
workflow_dispatch:
jobs:
deploy-production:
env:
RUNNER_TOOL_CACHE: /toolcache
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 构建Docker镜像
run: docker build -t dypid:latest .
- name: 导出镜像
run: mkdir release && docker save -o release/dypid.tar dypid:latest && docker rmi dypid:latest
- name: 安装sshpass工具
run: |
apt update
apt install -y sshpass
- name: 部署程序到生产服务器
env:
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
DEPLOY_DIR: "/data/dypid"
run: |
set -ex
# 上传新镜像
sshpass -p "$SSH_PASSWORD" scp -o StrictHostKeyChecking=no release/dypid.tar $SSH_USER@$SSH_HOST:/tmp/dypid.tar
# 重启程序
sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST \
"docker load -i /tmp/dypid.tar \
&& cd $DEPLOY_DIR \
&& docker compose up -d \
&& docker image prune -f"

34
Dockerfile Normal file
View File

@@ -0,0 +1,34 @@
FROM node:lts AS webBuilder
WORKDIR /build
COPY web .
RUN npm install \
&& npm run build
FROM golang AS goBuilder
WORKDIR /build
COPY . .
COPY --from=webBuilder /build/dist ./web/dist
RUN go env -w CGO_ENABLED=0 \
&& go mod tidy \
&& go build -o dypid
FROM alpine:latest
WORKDIR /data
COPY --from=goBuilder /build/dypid /dypid
RUN apk update \
&& apk add --no-cache tzdata \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata \
&& chmod +x /dypid
ENTRYPOINT [ "/dypid" ]

View File

@@ -3,55 +3,71 @@ package controller
import ( import (
"dypid/db" "dypid/db"
"dypid/global" "dypid/global"
"dypid/model"
"encoding/json"
"fmt" "fmt"
"net/http"
"strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
) )
func ReadDataHandler(c *gin.Context) { func ReadDataHandler(c *gin.Context) {
lLen := global.RDB.LLen(global.RCtx, fmt.Sprintf("list:%s", c.Query("token"))) //解析输入数据
if lLen.Val() == 0 { input := struct {
c.JSON(200, gin.H{"result": "数据库没有数据"}) Token string `form:"token" binding:"required"`
}{}
if err := c.ShouldBindQuery(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
return return
} }
retData := global.RDB.BLPop(global.RCtx, 0, fmt.Sprintf("list:%s", c.Query("token")))
newData := model.Data{} retData := global.RDB.LPop(global.RCtx, fmt.Sprintf("list:%s", input.Token)).Val()
err := json.Unmarshal([]byte(retData.Val()[1]), &newData) if retData == "null" {
if err != nil { c.JSON(http.StatusOK, gin.H{"result": "数据库没有数据"})
c.JSON(400, gin.H{"error": err.Error()})
return return
} }
c.JSON(200, gin.H{"result": newData})
c.String(http.StatusOK, retData)
} }
func WriteDataHandler(c *gin.Context) { func WriteDataHandler(c *gin.Context) {
data := model.Data{} //解析输入数据
input := struct {
if err := c.BindQuery(&data); err != nil { Token string `form:"token" binding:"required"`
c.JSON(400, gin.H{"error": err.Error()}) Data string `form:"data" binding:"required"`
}{}
if err := c.ShouldBindQuery(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
return return
} }
dedupObject, err := db.GetDedupObject(data.Token)
//数据获取
dedupObject, err := db.GetDedupObject(input.Token)
if err != nil { if err != nil {
c.JSON(400, gin.H{"error": err.Error()}) c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return return
} }
err = createBF(fmt.Sprintf("dedup:%s:%s", data.Token, dedupObject), 0.01, 100000000) dataIndex, err := getDataIndex(input.Token)
if err != nil && err.Error() != "ERR item exists" { if err != nil {
c.JSON(400, gin.H{"error": err.Error()}) c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return return
} }
dedupValue := strings.Split(input.Data, "----")[dataIndex[dedupObject]]
err = createCF(fmt.Sprintf("dedup:%s:%s", input.Token, dedupObject), 100_000_000)
if err != nil && err.Error() != "ERR item exists" {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
luaScript := ` luaScript := `
local dedupKey = KEYS[1] -- KEYS[1]: 去重键 (dedup:token:object) local dedupKey = KEYS[1] -- KEYS[1]: 去重键 (dedup:token:object)
local listKey = KEYS[2] -- KEYS[2]: 列表键 (list:token) local listKey = KEYS[2] -- KEYS[2]: 列表键 (list:token)
local deleteListKey = KEYS[3] -- KEYS[3]: 删除列表键 (delete-list:token)
local dedupValue = ARGV[1] -- ARGV[1]: 去重值 local dedupValue = ARGV[1] -- ARGV[1]: 去重值
local jsonData = ARGV[2] -- ARGV[2]: JSON序列化的数据 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 if exists == 1 then
@@ -59,43 +75,54 @@ if exists == 1 then
end end
-- 添加到布隆过滤器 -- 添加到布隆过滤器
redis.call('BF.ADD', dedupKey, dedupValue) redis.call('CF.ADD', dedupKey, dedupValue)
-- 添加到列表 -- 添加到列表
redis.call('LPUSH', listKey, jsonData) redis.call('LPUSH', listKey, rawData)
redis.call('LPUSH', deleteListKey, dedupValue)
-- 返回成功结果 -- 返回成功结果
return "ok" return "ok"
` `
k1 := fmt.Sprintf("dedup:%s:%s", data.Token, dedupObject)
k2 := fmt.Sprintf("list:%s", data.Token)
v1 := c.Query(dedupObject)
v2, err := json.Marshal(data)
if err != nil {
c.JSON(500, gin.H{"error": "JSON序列化失败 " + err.Error()})
return
}
result, err := redis.NewScript(luaScript).Run( result, err := redis.NewScript(luaScript).Run(
global.RCtx, global.RCtx,
global.RDB, global.RDB,
[]string{k1, k2}, []string{
v1, fmt.Sprintf("dedup:%s:%s", input.Token, dedupObject),
string(v2), fmt.Sprintf("list:%s", input.Token),
fmt.Sprintf("delete-list:%s", input.Token),
},
dedupValue,
input.Data,
).Result() ).Result()
if err != nil { if err != nil {
c.JSON(500, gin.H{"error": "Redis操作失败 " + err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": "Redis操作失败 " + err.Error()})
return return
} }
if resultMap, ok := result.(string); ok { if resultMap, ok := result.(string); ok {
c.JSON(200, gin.H{"result": resultMap}) c.JSON(http.StatusOK, gin.H{"result": resultMap})
return return
} }
c.JSON(500, gin.H{"error": "WriteDataHandler 错误"}) c.JSON(http.StatusInternalServerError, gin.H{"error": "WriteDataHandler 错误"})
} }
func createBF(bloomFilter string, errorRate float64, capacity int64) error { func createCF(bloomFilter string, capacity int64) error {
_, err := global.RDB.BFReserve(global.RCtx, bloomFilter, errorRate, capacity).Result() _, err := global.RDB.CFReserveBucketSize(global.RCtx, bloomFilter, capacity, 6).Result()
return err return err
} }
func getDataIndex(token string) (index map[string]int, err error) {
dataFormat, err := db.GetDataFormat(token)
if err != nil {
return nil, err
}
f := strings.Split(dataFormat, "----")
index = make(map[string]int)
for i, s := range f {
index[s] = i
}
return index, nil
}

View File

@@ -4,8 +4,10 @@ import (
"dypid/db" "dypid/db"
"dypid/global" "dypid/global"
"net/http" "net/http"
"strconv"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/redis/go-redis/v9"
) )
func ListTokenHandler(c *gin.Context) { func ListTokenHandler(c *gin.Context) {
@@ -13,50 +15,80 @@ func ListTokenHandler(c *gin.Context) {
} }
func CreateTokenHandler(c *gin.Context) { func CreateTokenHandler(c *gin.Context) {
if c.Query("token") == "" { //解析输入数据
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"}) input := struct {
Token string `form:"token" binding:"required"`
DedupObject string `form:"dedup_object" binding:"required"`
DataFormat string `form:"data_format" binding:"required"`
Notes string `form:"notes"`
}{}
if err := c.ShouldBindQuery(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
return return
} else if c.Query("dedup_object") == "" { }
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_object不能为空"}) //检查Token是否存在
if db.CheckToken(input.Token) {
c.JSON(http.StatusBadRequest, gin.H{"error": "创建Token失败Token已经存在"})
return return
} }
err := db.CreateToken(c.Query("token"), c.Query("dedup_object")) //创建Token
err := db.CreateToken(input.Token, input.DedupObject, input.DataFormat, input.Notes)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
//返回
c.JSON(http.StatusOK, gin.H{"result": "ok"}) c.JSON(http.StatusOK, gin.H{"result": "ok"})
} }
func UpdateTokenHandler(c *gin.Context) { func UpdateTokenHandler(c *gin.Context) {
if c.Query("token") == "" { input := struct {
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"}) Token string `form:"token" binding:"required"`
DedupObject string `form:"dedup_object" binding:"required"`
DataFormat string `form:"data_format" binding:"required"`
Notes string `form:"notes"`
}{}
if err := c.ShouldBindQuery(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
return return
} else if c.Query("dedup_object") == "" { }
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_object不能为空"}) //检查Token是否存在
if !db.CheckToken(input.Token) {
c.JSON(http.StatusBadRequest, gin.H{"error": "更改失败Token不存在"})
return return
} }
err := db.UpdateToken(c.Query("token"), c.Query("dedup_object")) err := db.UpdateToken(input.Token, input.DedupObject, input.DataFormat, input.Notes)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, gin.H{"result": "ok"}) c.JSON(http.StatusOK, gin.H{"result": "ok"})
} }
func DeleteTokenHandler(c *gin.Context) { func DeleteTokenHandler(c *gin.Context) {
if c.Query("token") == "" { input := struct {
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"}) Token string `form:"token" binding:"required"`
}{}
if err := c.ShouldBindQuery(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
return
}
//检查Token是否存在
if !db.CheckToken(input.Token) {
c.JSON(http.StatusBadRequest, gin.H{"error": "删除Token失败Token不存在"})
return return
} }
err := db.DeleteToken(c.Query("token")) err := db.DeleteToken(input.Token)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, gin.H{"result": "ok"}) c.JSON(http.StatusOK, gin.H{"result": "ok"})
} }
@@ -68,22 +100,34 @@ func GetTokenInfoHandler(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "Token不能为空"}) c.JSON(http.StatusBadRequest, gin.H{"error": "Token不能为空"})
return return
} }
//检查Token是否存在
if !db.CheckToken(input.Token) {
c.JSON(http.StatusBadRequest, gin.H{"error": "获取信息失败Token不存在"})
return
}
dedupObject, err := db.GetDedupObject(input.Token) dedupObject, err := db.GetDedupObject(input.Token)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取去重对象失败 " + err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": "获取去重对象失败 " + err.Error()})
return return
} }
dataFormat, err := db.GetDataFormat(input.Token)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取数据格式失败 " + err.Error()})
return
}
output := struct { output := struct {
Token string `json:"token"` Token string `json:"token"`
DedupObject string `json:"dedup_object"` DedupObject string `json:"dedup_object"`
DataFormat string `json:"data_format"`
DedupItemsNumber int64 `json:"dedup_items_number"` DedupItemsNumber int64 `json:"dedup_items_number"`
CacheListNumber int64 `json:"cache_list_number"` CacheListNumber int64 `json:"cache_list_number"`
}{} }{}
output.Token = input.Token output.Token = input.Token
output.DedupObject = dedupObject output.DedupObject = dedupObject
output.DedupItemsNumber = global.RDB.BFCard(global.RCtx, "dedup:"+input.Token+":"+dedupObject).Val() output.DataFormat = dataFormat
output.DedupItemsNumber = global.RDB.CFInfo(global.RCtx, "dedup:"+input.Token+":"+dedupObject).Val().NumItemsInserted
output.CacheListNumber = global.RDB.LLen(global.RCtx, "list:"+input.Token).Val() output.CacheListNumber = global.RDB.LLen(global.RCtx, "list:"+input.Token).Val()
c.JSON(http.StatusOK, gin.H{"result": output}) c.JSON(http.StatusOK, gin.H{"result": output})
@@ -92,14 +136,20 @@ func GetTokenInfoHandler(c *gin.Context) {
func DeleteTokenInfoHandler(c *gin.Context) { 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"`
BothNumber string `form:"both_number"`
}{} }{}
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不能为空"})
return return
} }
//检查Token是否存在
if !db.CheckToken(input.Token) {
c.JSON(http.StatusBadRequest, gin.H{"error": "删除Token失败Token不存在"})
return
}
//检查token是否存在 //检查token是否存在
_, err := db.GetDedupObject(input.Token) _, err := db.GetDedupObject(input.Token)
@@ -107,14 +157,77 @@ func DeleteTokenInfoHandler(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token不存在" + err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": "Token不存在" + err.Error()})
return return
} }
dedupObject, err := db.GetDedupObject(input.Token)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
//删除去重对象 //删除去重对象
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...)
global.RDB.Del(global.RCtx, "delete-list:"+input.Token)
default:
i, err := strconv.Atoi(input.DedupBF)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_bf设置错误 " + err.Error()})
return
}
result := global.RDB.LRange(global.RCtx, "delete-list:"+input.Token, int64(-i), -1).Val()
_, err = global.RDB.TxPipelined(global.RCtx, func(pipe redis.Pipeliner) error {
for _, s := range result {
pipe.CFDel(global.RCtx, "dedup:"+input.Token+":"+dedupObject, s)
}
return nil
})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
global.RDB.LTrim(global.RCtx, "delete-list:"+input.Token, 0, int64(-i-1))
} }
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
}
global.RDB.LTrim(global.RCtx, "list:"+input.Token, 0, int64(-i-1))
}
//删除去重参考值和原始数据
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, "delete-list:"+input.Token, int64(-i), -1).Val()
_, err = global.RDB.TxPipelined(global.RCtx, func(pipe redis.Pipeliner) error {
for _, s := range result {
pipe.CFDel(global.RCtx, "dedup:"+input.Token+":"+dedupObject, s)
}
pipe.LTrim(global.RCtx, "delete-list:"+input.Token, 0, int64(-i-1))
pipe.LTrim(global.RCtx, "list:"+input.Token, 0, int64(-i-1))
return nil
})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
} }
//输出信息 //输出信息

View File

@@ -12,6 +12,8 @@ var localDB []Token
type Token struct { type Token struct {
Token string `json:"token"` Token string `json:"token"`
DedupObject string `json:"dedup_object"` DedupObject string `json:"dedup_object"`
DataFormat string `json:"data_format"`
Notes string `json:"notes"`
} }
func InitLocalDB() { func InitLocalDB() {
@@ -30,12 +32,22 @@ start:
} }
} }
func CheckToken(token string) bool {
InitLocalDB()
for _, t := range localDB {
if t.Token == token {
return true
}
}
return false
}
func ListToken() []Token { func ListToken() []Token {
InitLocalDB() InitLocalDB()
return localDB return localDB
} }
func CreateToken(token string, dedupObject string) error { func CreateToken(token string, dedupObject string, dataFormat string, Notes string) error {
InitLocalDB() InitLocalDB()
for _, t := range localDB { for _, t := range localDB {
if t.Token == token { if t.Token == token {
@@ -43,7 +55,7 @@ func CreateToken(token string, dedupObject string) error {
} }
} }
a := append(localDB, Token{token, dedupObject}) a := append(localDB, Token{token, dedupObject, dataFormat, Notes})
marshal, err := json.Marshal(a) marshal, err := json.Marshal(a)
if err != nil { if err != nil {
return err return err
@@ -55,12 +67,14 @@ func CreateToken(token string, dedupObject string) error {
return nil return nil
} }
func UpdateToken(token string, dedupObject string) error { func UpdateToken(token string, dedupObject string, dataFormat string, Notes string) error {
InitLocalDB() InitLocalDB()
for i, t := range localDB { for i, t := range localDB {
if t.Token == token { if t.Token == token {
localDB[i].DedupObject = dedupObject localDB[i].DedupObject = dedupObject
localDB[i].DataFormat = dataFormat
localDB[i].Notes = Notes
marshal, err := json.Marshal(localDB) marshal, err := json.Marshal(localDB)
if err != nil { if err != nil {
@@ -72,6 +86,7 @@ func UpdateToken(token string, dedupObject string) error {
return nil return nil
} }
} }
InitLocalDB() InitLocalDB()
return errors.New("token not found") return errors.New("token not found")
} }
@@ -93,6 +108,7 @@ func DeleteToken(token string) error {
return nil return nil
} }
} }
InitLocalDB() InitLocalDB()
return errors.New("token not found") return errors.New("token not found")
} }
@@ -105,3 +121,12 @@ func GetDedupObject(token string) (dedupObject string, err error) {
} }
return "", errors.New("未找到Token") return "", errors.New("未找到Token")
} }
func GetDataFormat(token string) (dataFormat string, err error) {
for i, t := range localDB {
if t.Token == token {
return localDB[i].DataFormat, nil
}
}
return "", errors.New("未找到Token")
}

View File

@@ -16,19 +16,6 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
type UploadData struct {
Dyid string // dyid
Uid string // uid
Secid string // secid
Pid string // pid
CommentId string // comment_id
Id1 string // id1
Id2 string // id2
Id3 string // id3
Id4 string // id4
Id5 string // id5
}
var httpClient = &http.Client{ var httpClient = &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
MaxIdleConns: 200, MaxIdleConns: 200,
@@ -39,14 +26,45 @@ var httpClient = &http.Client{
} }
func main() { 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.Printf("上传完成,耗时:%s\n", time.Since(start))
}
time.Sleep(time.Minute)
}
}
func initConfig() {
//程序配置 //程序配置
viper.SetDefault("url", "http://localhost:8080") viper.SetDefault("url", "http://localhost:8080")
viper.SetDefault("token", "") viper.SetDefault("token", "")
viper.SetDefault("thread-count", 10) viper.SetDefault("thread-count", 10)
viper.SetDefault("index.uid", 0)
viper.SetDefault("index.secid", 1)
viper.SetDefault("index.pid", 2)
viper.SetDefault("index.comment-id", 3)
//设置配置文件名和路径 ./config.toml //设置配置文件名和路径 ./config.toml
viper.AddConfigPath(".") viper.AddConfigPath(".")
viper.SetConfigName("config") viper.SetConfigName("config")
@@ -62,46 +80,12 @@ func main() {
fmt.Errorf("无法读取配置文件: %w", err) fmt.Errorf("无法读取配置文件: %w", err)
} }
}) })
//检测./upload
fmt.Println("程序启动成功正在检测txt文件")
//os.Mkdir("./upload", os.ModePerm)
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)
os.Remove(filePath)
wg.Done()
}()
}
wg.Wait()
}
time.Sleep(2 * time.Second)
}
} }
func uploadDataToServer(data UploadData) error {
func uploadDataToServer(data string) error {
params := url.Values{} params := url.Values{}
params.Add("token", viper.GetString("token")) params.Set("token", viper.GetString("token"))
params.Add("dyid", data.Dyid) params.Set("data", data)
params.Add("uid", data.Uid)
params.Add("secid", data.Secid)
params.Add("pid", data.Pid)
params.Add("comment_id", data.CommentId)
params.Add("id1", data.Id1)
params.Add("id2", data.Id2)
params.Add("id3", data.Id3)
params.Add("id4", data.Id4)
params.Add("id5", data.Id5)
resp, err := httpClient.Post(viper.GetString("url")+"/api/data?"+params.Encode(), "application/x-www-form-urlencoded", strings.NewReader("")) resp, err := httpClient.Post(viper.GetString("url")+"/api/data?"+params.Encode(), "application/x-www-form-urlencoded", strings.NewReader(""))
if err != nil { if err != nil {
@@ -114,10 +98,8 @@ func uploadDataToServer(data UploadData) 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
} }
@@ -177,6 +159,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)
@@ -188,35 +171,8 @@ func processLines(lines <-chan string, workerID int, filePath string) {
if strings.TrimSpace(line) == "" { if strings.TrimSpace(line) == "" {
continue continue
} }
// 使用----分割行数据
parts := strings.Split(line, "----")
for i := 0; i < 10; i++ {
parts = append(parts, "")
}
// 确保有足够的字段
if len(parts) < 3 {
fmt.Printf("Worker %d (文件 %s): 行数据字段不足,跳过: %s\n", workerID, filePath, line)
continue
}
// 创建上传数据结构
uploadData := UploadData{
Uid: parts[viper.GetInt("index.uid")],
Secid: parts[viper.GetInt("index.secid")],
Pid: parts[viper.GetInt("index.pid")],
CommentId: parts[viper.GetInt("index.comment-id")],
Dyid: parts[4],
Id1: parts[5],
Id2: parts[6],
Id3: parts[7],
Id4: parts[8],
Id5: parts[9],
}
// 上传数据 // 上传数据
if err := uploadDataToServer(uploadData); err != nil { if err := uploadDataToServer(line); err != nil {
fmt.Printf("Worker %d (文件 %s): 上传失败: %v\n", workerID, filePath, err) fmt.Printf("Worker %d (文件 %s): 上传失败: %v\n", workerID, filePath, err)
} }
} }

View File

@@ -1,13 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang=""> <html lang="">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel="icon" href="/favicon.ico"> <link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title> <title>抖音数据去重</title>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
<script type="module" src="/src/main.ts"></script> <script type="module" src="/src/main.ts"></script>
</body> </body>
</html> </html>

View File

@@ -1,64 +1,15 @@
<script setup lang="ts"> <script setup lang="ts">
import {ref, watch} from 'vue'
import {useRoute, useRouter} from "vue-router";
import {useCounterStore} from "@/stores/counter.ts";
const router = useRouter()
const route = useRoute()
const activeIndex = ref(route.name?.toString() || "TokenList")
watch(route, (newRoute) => {
activeIndex.value = newRoute.name?.toString() || "TokenList"
})
const handleSelect = (key: string) => {
router.push({
name: key
})
}
</script> </script>
<template> <template>
<el-container> <router-view></router-view>
<el-header>
<el-menu
:default-active="activeIndex"
class="el-menu-demo"
mode="horizontal"
@select="handleSelect"
>
<el-menu-item index="TokenDetail">Token详细信息</el-menu-item>
<el-menu-item index="TokenManage">管理Token</el-menu-item>
<el-menu-item v-if="useCounterStore().isAdmin">
<el-button type="danger" plain @click="useCounterStore().isAdmin=false">退出管理员</el-button>
</el-menu-item>
</el-menu>
</el-header>
<el-container>
<el-main>
<router-view></router-view>
</el-main>
</el-container>
</el-container>
</template> </template>
<style scoped>
<style>
html, body, #app { html, body, #app {
height: 100%; height: 100%;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.el-container {
height: 100%;
}
.el-menu-demo {
line-height: 60px;
}
</style> </style>

View File

@@ -2,10 +2,33 @@ import {createRouter, createWebHistory} from 'vue-router'
import TokenManageView from '@/views/TokenManageView.vue' import TokenManageView from '@/views/TokenManageView.vue'
import TokenDetailView from '@/views/TokenDetailView.vue' import TokenDetailView from '@/views/TokenDetailView.vue'
import AdminView from '@/views/AdminView.vue'
import HomeView from '@/views/HomeView.vue'
const routes = [ const routes = [
{path: '/manage', name: "TokenManage", component: TokenManageView}, {
{path: '/', name: "TokenDetail", component: TokenDetailView}, path: '/',
name: "Home",
component: HomeView,
},
{
path: '/haha',
name: "Admin",
component: AdminView,
children: [
{
path: '',
name: "TokenManage",
component: TokenManageView
},
{
path: 'token',
name: "TokenDetail",
component: TokenDetailView
},
],
},
]; ];
const router = createRouter({ const router = createRouter({

View File

@@ -2,11 +2,13 @@ import {ref, computed} from 'vue'
import {defineStore} from 'pinia' import {defineStore} from 'pinia'
export const useCounterStore = defineStore('counter', () => { export const useCounterStore = defineStore('counter', () => {
const homeToken = ref("")
const token = ref("") const token = ref("")
const isAdmin = ref(false) const isAdmin = ref(false)
return {token, isAdmin} return {token, isAdmin}
}, { }, {
persist: true persist: true

View File

@@ -0,0 +1,50 @@
<script setup lang="ts">
import {ref, watch} from 'vue'
import {useRoute, useRouter} from "vue-router";
import {useCounterStore} from "@/stores/counter.ts";
const router = useRouter()
const route = useRoute()
const activeIndex = ref(route.name?.toString() || "TokenList")
watch(route, (newRoute) => {
activeIndex.value = newRoute.name?.toString() || "TokenList"
})
const handleSelect = (key: string) => {
router.push({
name: key
})
}
</script>
<template>
<el-container>
<el-header>
<el-menu
:default-active="activeIndex"
class="el-menu-demo"
mode="horizontal"
@select="handleSelect"
>
<el-menu-item index="TokenManage">管理Token</el-menu-item>
<el-menu-item index="TokenDetail">Token详细信息</el-menu-item>
<el-menu-item v-if="useCounterStore().isAdmin">
<el-button type="danger" plain @click="useCounterStore().isAdmin=false">退出管理员</el-button>
</el-menu-item>
</el-menu>
</el-header>
<el-container>
<el-main>
<router-view></router-view>
</el-main>
</el-container>
</el-container>
</template>
<style scoped>
</style>

View File

@@ -0,0 +1,77 @@
<script setup lang="ts">
import {ref} from 'vue'
import axios from "@/axios.ts";
import {useRoute} from "vue-router"
import {ElMessage} from "element-plus";
const token = ref(useRoute().query.token)
const input = ref(useRoute().query.token)
const result = ref()
const inputChange = () => {
if (input.value != null && input.value != '') {
axios.get('/api/token/info', {
params: {
token: input.value
}
}).then(res => {
result.value = res.data.result
token.value = input.value
ElMessage({
message: '更改成功',
type: 'success',
})
}).catch(error => {
ElMessage({
message: 'Token输入错误',
type: 'error',
})
})
}
}
const getInfo = () => {
if (token.value != null && token.value != '') {
axios.get('/api/token/info', {
params: {
token: token.value
}
}).then(res => {
result.value = res.data.result
})
}
}
getInfo()
setInterval(getInfo, 5000)
</script>
<template>
<b>当前Token</b>
<el-input
v-model="input"
style="width: 240px"
placeholder="输入Token"
clearable
@change="inputChange"
/>
<el-divider/>
<b>Token信息每5秒刷新</b>
<el-button type="primary" plain @click="getInfo">手动刷新</el-button>
<el-descriptions
direction="vertical"
: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>
</template>
<style scoped>
</style>

View File

@@ -3,8 +3,25 @@ import {useCounterStore} from "@/stores/counter.ts";
import {ref, watch} from 'vue' import {ref, watch} from 'vue'
import axios from "@/axios.ts"; import axios from "@/axios.ts";
// 创建响应式引用用于存储API请求结果
const result = ref() const result = ref()
// 创建响应式引用用于存储当前选中的token值
const value = ref('') const value = ref('')
value.value = useCounterStore().token
// 创建响应式引用,用于存储下拉选项列表
const options = ref([] as string[])
// 控制删除指定Redis键的确认对话框的显示状态
const deleteSpecifyDataVisible = ref(false)
const inputSpecifyData = ref('')
const deleteSpecifyDedupVisible = ref(false)
const inputSpecifyDedup = ref('')
const deleteSpecifyRawVisible = ref(false)
const inputSpecifyRaw = ref('')
const getInfo = () => { const getInfo = () => {
if (value.value != '') { if (value.value != '') {
@@ -24,17 +41,18 @@ const deleteDedup = () => {
axios.delete('/api/token/info', { axios.delete('/api/token/info', {
params: { params: {
token: value.value, token: value.value,
dedup_bf: true dedup_bf: "all"
} }
}).then(res => { }).then(res => {
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()
@@ -45,55 +63,133 @@ getInfo()
setInterval(getInfo, 5000) setInterval(getInfo, 5000)
watch(value, (newValue) => { watch(value, (newValue) => {
useCounterStore().token = value.value
getInfo() getInfo()
}) })
interface optionsType {
value: string
}
const options = ref([] as optionsType[])
value.value = useCounterStore().token
axios.get('/api/token').then(res => { axios.get('/api/token').then(res => {
if (res.status == 200) { if (res.status == 200) {
res.data.result.forEach((item: any) => { res.data.result.forEach((item: any) => {
options.value.push({"value": item.token}) options.value.push(item.token)
}) })
} }
}) })
const deleteSpecifyData = () => {
axios.delete('/api/token/info', {
params: {
token: value.value,
both_number: inputSpecifyData.value,
}
}).then(res => {
getInfo()
deleteSpecifyDataVisible.value = false
})
}
const deleteSpecifyDedup = () => {
axios.delete('/api/token/info', {
params: {
token: value.value,
dedup_bf: inputSpecifyDedup.value,
}
}).then(res => {
getInfo()
deleteSpecifyDedupVisible.value = false
})
}
const deleteSpecifyRaw = () => {
axios.delete('/api/token/info', {
params: {
token: value.value,
cache_list: inputSpecifyRaw.value,
}
}).then(res => {
getInfo()
deleteSpecifyRawVisible.value = false
})
}
</script> </script>
<template> <template>
<b>当前Token</b> <div v-if="!useCounterStore().isAdmin">
<el-select v-model="value" placeholder="选择Token" style="width: 240px"> <el-alert title="您没有权限访问此页面" type="error" center show-icon/>
<el-option </div>
v-for="item in options"
:key="item.value"
:value="item.value"
/>
</el-select>
<el-divider/>
<b>Token信息每5秒刷新</b>
<el-button type="primary" plain @click="getInfo">手动刷新</el-button>
<el-descriptions
direction="vertical"
:column="4"
border
>
<el-descriptions-item label="去重对象">{{ result?.dedup_object }}</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>
<div v-if="useCounterStore().isAdmin"> <div v-if="useCounterStore().isAdmin">
<p><b>管理</b></p> <b>当前Token</b>
<el-select v-model="value" placeholder="选择Token" style="width: 240px">
<el-option
v-for="item in options"
:key="item"
:value="item"
/>
</el-select>
<el-button type="danger" @click="deleteDedup">删除去重记录值</el-button> <el-divider/>
<el-button type="danger" @click="deleteRedis">删除Redis数据</el-button>
<b>Token信息每5秒刷新</b>
<el-button type="primary" plain @click="getInfo">手动刷新</el-button>
<el-descriptions
direction="vertical"
:column="4"
border
>
<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">删除全部原始数据</el-button>
<div style="margin-top: 10px">
<el-button type="danger" @click="deleteSpecifyDedupVisible=true">删除指定数量去重参考值</el-button>
<el-button type="danger" @click="deleteSpecifyRawVisible=true">删除指定数量原始数据</el-button>
</div>
<div style="margin-top: 10px">
<el-button type="danger" @click="deleteSpecifyDataVisible=true">
删除指定数量的数据去重参考值+原始数据
</el-button>
</div>
<!--弹窗输入-->
<el-dialog v-model="deleteSpecifyDedupVisible" title="删除指定数量去重参考值" width="400">
<el-input v-model="inputSpecifyDedup" style="width: 200px" placeholder="请输入删除数量"/>
<template #footer>
<el-button type="primary" @click="deleteSpecifyDedup">
确定
</el-button>
</template>
</el-dialog>
<el-dialog v-model="deleteSpecifyRawVisible" title="删除指定数量原始数据" width="400">
<el-input v-model="inputSpecifyRaw" style="width: 200px" placeholder="请输入删除数量"/>
<template #footer>
<el-button type="primary" @click="deleteSpecifyRaw">
确定
</el-button>
</template>
</el-dialog>
<el-dialog v-model="deleteSpecifyDataVisible" title="删除指定数量的数据" width="400">
<el-input v-model="inputSpecifyData" style="width: 200px" placeholder="请输入删除数量"/>
<template #footer>
<el-button type="primary" @click="deleteSpecifyData">
确定
</el-button>
</template>
</el-dialog>
</div> </div>
</template> </template>

View File

@@ -2,43 +2,60 @@
import {ref} from "vue"; import {ref} from "vue";
import axios from "@/axios.ts"; import axios from "@/axios.ts";
import {ElMessage, ElMessageBox} from 'element-plus' import {ElMessage, ElMessageBox} from 'element-plus'
import {useCounterStore} from "@/stores/counter.ts";
import {useRouter} from "vue-router";
const tableData = ref([]) const tableData = ref([])
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',
},
{
value: 'secid',
},
{
value: 'pid',
},
{
value: 'comment_id',
},
{
value: 'dyid',
}
]
const dataFormatOptions = [
{
value: 'uid----secid----pid----comment_id',
}, {
value: 'uid----secid',
}, {
value: 'dyid',
}
]
axios.get("/api/token").then(res => { axios.get("/api/token").then(res => {
tableData.value = res.data.result tableData.value = res.data.result
}) })
const input = ref('')
const value = ref('')
const options = [
{
value: 'uid',
label: 'uid',
},
{
value: 'pid',
label: 'pid',
},
{
value: 'secid',
label: 'secid',
},
{
value: 'dyid',
label: 'dyid',
},
{
value: 'comment_id',
label: 'comment_id',
}
]
const addToken = () => { const addToken = () => {
axios.post('/api/token', {}, { axios.post('/api/token', {}, {
params: { params: {
token: input.value, token: input.value,
dedup_object: value.value dedup_object: value.value,
data_format: dataFormat.value,
notes: inputNotes.value,
} }
}).then(response => { }).then(response => {
if (response.data.result == "ok") { if (response.data.result == "ok") {
@@ -55,29 +72,26 @@ const addToken = () => {
}) })
} }
import {useCounterStore} from "@/stores/counter.ts";
import {useRouter} from "vue-router";
const router = useRouter()
const viewDetails = (row: any) => { const viewDetails = (row: any) => {
useCounterStore().token = row.token useCounterStore().token = row.token
router.push({ router.push({
name: "TokenDetail" name: "TokenDetail",
}) })
} }
var rowOut: any
const dedupObjectVisible = ref(false)
const dialogDedupObjectVisible = (row: any) => { const dialogDedupObjectVisible = (row: any) => {
rowOut = row rowOut = row
dedupObjectVisible.value = true dedupObjectVisible.value = true
} }
const updateDedupObject = () => { const updateDedupObject = () => {
dedupObjectVisible.value = false dedupObjectVisible.value = false
axios.put('/api/token', {}, { axios.put('/api/token', {}, {
params: { params: {
token: rowOut.token, token: rowOut.token,
dedup_object: value.value dedup_object: value.value,
data_format: rowOut.data_format,
notes: rowOut.notes,
} }
}).then(res => { }).then(res => {
if (res.data.result == "ok") { if (res.data.result == "ok") {
@@ -92,7 +106,64 @@ const updateDedupObject = () => {
}).catch(error => { }).catch(error => {
ElMessage.error(error.response?.data?.error) ElMessage.error(error.response?.data?.error)
}) })
}
const dialogDataFormatVisible = (row: any) => {
rowOut = row
dataFormatVisible.value = true
}
const updateDataFormat = () => {
dataFormatVisible.value = false
axios.put('/api/token', {}, {
params: {
token: rowOut.token,
dedup_object: rowOut.dedup_object,
data_format: dataFormat.value,
notes: rowOut.notes,
}
}).then(res => {
if (res.data.result == "ok") {
ElMessage({
message: '更改成功',
type: 'success',
})
axios.get('/api/token').then(res => {
tableData.value = res.data.result
})
}
}).catch(error => {
ElMessage.error(error.response?.data?.error)
})
}
const dialogNotesVisible = (row: any) => {
rowOut = row
NotesVisible.value = true
}
const updateNotes = () => {
NotesVisible.value = false
axios.put('/api/token', {}, {
params: {
token: rowOut.token,
dedup_object: rowOut.dedup_object,
data_format: rowOut.data_format,
notes: inputNotes.value
}
}).then(res => {
if (res.data.result == "ok") {
ElMessage({
message: '更改成功',
type: 'success',
})
axios.get('/api/token').then(res => {
tableData.value = res.data.result
})
}
}).catch(error => {
ElMessage.error(error.response?.data?.error)
})
} }
const deleteToken = (row: any) => { const deleteToken = (row: any) => {
@@ -115,9 +186,8 @@ const deleteToken = (row: any) => {
}) })
} }
const inputPassWord = ref('')
const checkPassword = () => { const checkPassword = () => {
if (inputPassWord.value == "admin") { if (inputPassWord.value == "haha") {
ElMessage({ ElMessage({
message: '密码正确', message: '密码正确',
type: 'success', type: 'success',
@@ -127,7 +197,6 @@ const checkPassword = () => {
ElMessage.error('密码错误') ElMessage.error('密码错误')
} }
} }
</script> </script>
<template> <template>
@@ -135,7 +204,7 @@ const checkPassword = () => {
<div v-if="!useCounterStore().isAdmin" style="margin: auto auto; max-width: 400px"> <div v-if="!useCounterStore().isAdmin" style="margin: auto auto; max-width: 400px">
<el-alert title="您没有权限访问此页面,输入管理员密码" type="error" :closable="false" show-icon/> <el-alert title="您没有权限访问此页面,输入管理员密码" type="error" :closable="false" show-icon/>
<p></p> <p></p>
<el-input v-model="inputPassWord" style="width: 400px" placeholder="请输入管理员密码"/> <el-input v-model="inputPassWord" style="width: 400px" placeholder="请输入管理员密码" @change="checkPassword"/>
<p></p> <p></p>
<el-button type="primary" @click="checkPassword">确认</el-button> <el-button type="primary" @click="checkPassword">确认</el-button>
</div> </div>
@@ -143,25 +212,36 @@ const checkPassword = () => {
<!--管理员--> <!--管理员-->
<div v-if="useCounterStore().isAdmin"> <div v-if="useCounterStore().isAdmin">
<!--添加Token--> <!--添加Token-->
<el-input v-model="input" style="width: 200px" placeholder="请输入Token名称"/> <el-input v-model="input" style="width: 150px" placeholder="请输入Token名称"/>
<el-select v-model="value" placeholder="选择去重对象" style="width: 200px"> <el-select v-model="value" placeholder="选择去重对象" style="width: 150px">
<el-option <el-option
v-for="item in options" v-for="item in options"
:key="item.value" :key="item.value"
:label="item.label"
:value="item.value" :value="item.value"
/> />
</el-select> </el-select>
<el-select v-model="dataFormat" placeholder="选择数据格式" style="width: 280px">
<el-option
v-for="item in dataFormatOptions"
:key="item.value"
:value="item.value"
/>
</el-select>
<el-input v-model="inputNotes" style="width: 200px" placeholder="请输入备注"/>
<el-button type="primary" @click="addToken">添加Token</el-button> <el-button type="primary" @click="addToken">添加Token</el-button>
<!--Token列表--> <!--Token列表-->
<el-table :data="tableData" style="width: 100%"> <el-table :data="tableData" stripe style="width: 100%">
<el-table-column prop="token" label="Token" width="180"/> <el-table-column prop="token" label="Token" width="150"/>
<el-table-column prop="dedup_object" label="去重对象" width="180"/> <el-table-column prop="dedup_object" label="去重对象" width="150"/>
<el-table-column prop="data_format" label="上传数据格式" width="280"/>
<el-table-column prop="notes" label="备注" width="200"/>
<el-table-column label="操作"> <el-table-column label="操作">
<template #default="scope"> <template #default="scope">
<el-button @click="viewDetails(scope.row)">查看详细</el-button> <el-button @click="viewDetails(scope.row)">查看详细</el-button>
<el-button @click="dialogDedupObjectVisible(scope.row)" type="primary">更改去重对象</el-button> <el-button @click="dialogDedupObjectVisible(scope.row)" type="primary">更改去重对象</el-button>
<el-button @click="dialogDataFormatVisible(scope.row)" type="primary">更改数据格式</el-button>
<el-button @click="dialogNotesVisible(scope.row)" type="primary">更改备注</el-button>
<el-popconfirm <el-popconfirm
width="180" width="180"
title="确认删除此Token吗" title="确认删除此Token吗"
@@ -183,7 +263,6 @@ const checkPassword = () => {
<el-option <el-option
v-for="item in options" v-for="item in options"
:key="item.value" :key="item.value"
:label="item.label"
:value="item.value" :value="item.value"
/> />
</el-select> </el-select>
@@ -193,6 +272,30 @@ const checkPassword = () => {
</el-button> </el-button>
</template> </template>
</el-dialog> </el-dialog>
<el-dialog v-model="dataFormatVisible" title="更改数据格式" width="400">
<el-select v-model="dataFormat" placeholder="选择数据格式" style="width: 280px">
<el-option
v-for="item in dataFormatOptions"
:key="item.value"
:value="item.value"
/>
</el-select>
<template #footer>
<el-button type="primary" @click="updateDataFormat">
确定
</el-button>
</template>
</el-dialog>
<el-dialog v-model="NotesVisible" title="更改备注" width="400">
<el-input v-model="inputNotes" style="width: 200px" placeholder="请输入备注"/>
<template #footer>
<el-button type="primary" @click="updateNotes">
确定
</el-button>
</template>
</el-dialog>
</div> </div>
</template> </template>