Compare commits
34 Commits
315d43a16e
...
main
Author | SHA1 | Date | |
---|---|---|---|
0992b02880 | |||
1f8a5b8c37 | |||
795a9186a9 | |||
69d4c5d038 | |||
78d496ae72 | |||
4c19f4b16c | |||
1c56423ea4 | |||
5d304b6334 | |||
5e3c0762ab | |||
f883b0a7d8 | |||
861ac5d365 | |||
1e4c2d540e | |||
af3a297bb4 | |||
eb88f4b231 | |||
cf4287ddd9 | |||
88aee26105 | |||
b6ce840400 | |||
333882c9e0 | |||
640b1aa99e | |||
509b274c5c | |||
4c1e0d417d | |||
deb958b71b | |||
ad1f450b19 | |||
c675324d6d | |||
9a31fa96b5 | |||
fb4709e59a | |||
7e6f5e3a19 | |||
f2e7d7a5c4 | |||
7adcebee75 | |||
94e472a6c4 | |||
da7f40642e | |||
2d80cac3fd | |||
e20ff1a3b7 | |||
f2e9afc8aa |
37
.gitea/workflows/build_tool.yaml
Normal file
37
.gitea/workflows/build_tool.yaml
Normal 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
|
39
.gitea/workflows/deploy-dev.yaml
Normal file
39
.gitea/workflows/deploy-dev.yaml
Normal 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"
|
40
.gitea/workflows/deploy-production.yaml
Normal file
40
.gitea/workflows/deploy-production.yaml
Normal 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
34
Dockerfile
Normal 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" ]
|
@@ -3,55 +3,71 @@ package controller
|
||||
import (
|
||||
"dypid/db"
|
||||
"dypid/global"
|
||||
"dypid/model"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func ReadDataHandler(c *gin.Context) {
|
||||
lLen := global.RDB.LLen(global.RCtx, fmt.Sprintf("list:%s", c.Query("token")))
|
||||
if lLen.Val() == 0 {
|
||||
c.JSON(200, gin.H{"result": "数据库没有数据"})
|
||||
//解析输入数据
|
||||
input := struct {
|
||||
Token string `form:"token" binding:"required"`
|
||||
}{}
|
||||
if err := c.ShouldBindQuery(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||
return
|
||||
}
|
||||
retData := global.RDB.BLPop(global.RCtx, 0, fmt.Sprintf("list:%s", c.Query("token")))
|
||||
newData := model.Data{}
|
||||
err := json.Unmarshal([]byte(retData.Val()[1]), &newData)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"error": err.Error()})
|
||||
|
||||
retData := global.RDB.LPop(global.RCtx, fmt.Sprintf("list:%s", input.Token)).Val()
|
||||
if retData == "null" {
|
||||
c.JSON(http.StatusOK, gin.H{"result": "数据库没有数据"})
|
||||
return
|
||||
}
|
||||
c.JSON(200, gin.H{"result": newData})
|
||||
|
||||
c.String(http.StatusOK, retData)
|
||||
}
|
||||
|
||||
func WriteDataHandler(c *gin.Context) {
|
||||
data := model.Data{}
|
||||
|
||||
if err := c.BindQuery(&data); err != nil {
|
||||
c.JSON(400, gin.H{"error": err.Error()})
|
||||
//解析输入数据
|
||||
input := struct {
|
||||
Token string `form:"token" binding:"required"`
|
||||
Data string `form:"data" binding:"required"`
|
||||
}{}
|
||||
if err := c.ShouldBindQuery(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||
return
|
||||
}
|
||||
dedupObject, err := db.GetDedupObject(data.Token)
|
||||
|
||||
//数据获取
|
||||
dedupObject, err := db.GetDedupObject(input.Token)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"error": err.Error()})
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
err = createBF(fmt.Sprintf("dedup:%s:%s", data.Token, dedupObject), 0.01, 100000000)
|
||||
if err != nil && err.Error() != "ERR item exists" {
|
||||
c.JSON(400, gin.H{"error": err.Error()})
|
||||
dataIndex, err := getDataIndex(input.Token)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
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 := `
|
||||
local dedupKey = KEYS[1] -- KEYS[1]: 去重键 (dedup:token:object)
|
||||
local listKey = KEYS[2] -- KEYS[2]: 列表键 (list:token)
|
||||
local deleteListKey = KEYS[3] -- KEYS[3]: 删除列表键 (delete-list:token)
|
||||
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
|
||||
@@ -59,43 +75,54 @@ if exists == 1 then
|
||||
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"
|
||||
`
|
||||
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(
|
||||
global.RCtx,
|
||||
global.RDB,
|
||||
[]string{k1, k2},
|
||||
v1,
|
||||
string(v2),
|
||||
[]string{
|
||||
fmt.Sprintf("dedup:%s:%s", input.Token, dedupObject),
|
||||
fmt.Sprintf("list:%s", input.Token),
|
||||
fmt.Sprintf("delete-list:%s", input.Token),
|
||||
},
|
||||
dedupValue,
|
||||
input.Data,
|
||||
).Result()
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"error": "Redis操作失败 " + err.Error()})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Redis操作失败 " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if resultMap, ok := result.(string); ok {
|
||||
c.JSON(200, gin.H{"result": resultMap})
|
||||
c.JSON(http.StatusOK, gin.H{"result": resultMap})
|
||||
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 {
|
||||
_, err := global.RDB.BFReserve(global.RCtx, bloomFilter, errorRate, capacity).Result()
|
||||
func createCF(bloomFilter string, capacity int64) error {
|
||||
_, err := global.RDB.CFReserveBucketSize(global.RCtx, bloomFilter, capacity, 6).Result()
|
||||
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
|
||||
}
|
||||
|
@@ -4,8 +4,10 @@ import (
|
||||
"dypid/db"
|
||||
"dypid/global"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func ListTokenHandler(c *gin.Context) {
|
||||
@@ -13,50 +15,65 @@ func ListTokenHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
func CreateTokenHandler(c *gin.Context) {
|
||||
if c.Query("token") == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"})
|
||||
return
|
||||
} else if c.Query("dedup_object") == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_object不能为空"})
|
||||
//解析输入数据
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
//返回
|
||||
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
||||
}
|
||||
|
||||
func UpdateTokenHandler(c *gin.Context) {
|
||||
if c.Query("token") == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"})
|
||||
return
|
||||
} else if c.Query("dedup_object") == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_object不能为空"})
|
||||
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
|
||||
}
|
||||
|
||||
err := db.UpdateToken(c.Query("token"), c.Query("dedup_object"))
|
||||
err := db.UpdateToken(input.Token, input.DedupObject, input.DataFormat, input.Notes)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
||||
}
|
||||
|
||||
func DeleteTokenHandler(c *gin.Context) {
|
||||
if c.Query("token") == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"})
|
||||
input := struct {
|
||||
Token string `form:"token" binding:"required"`
|
||||
}{}
|
||||
if err := c.ShouldBindQuery(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
err := db.DeleteToken(c.Query("token"))
|
||||
err := db.DeleteToken(input.Token)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
||||
}
|
||||
|
||||
@@ -74,16 +91,23 @@ func GetTokenInfoHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取去重对象失败 " + err.Error()})
|
||||
return
|
||||
}
|
||||
dataFormat, err := db.GetDataFormat(input.Token)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取数据格式失败 " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
output := struct {
|
||||
Token string `json:"token"`
|
||||
DedupObject string `json:"dedup_object"`
|
||||
DataFormat string `json:"data_format"`
|
||||
DedupItemsNumber int64 `json:"dedup_items_number"`
|
||||
CacheListNumber int64 `json:"cache_list_number"`
|
||||
}{}
|
||||
output.Token = input.Token
|
||||
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()
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"result": output})
|
||||
@@ -92,9 +116,10 @@ func GetTokenInfoHandler(c *gin.Context) {
|
||||
func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
//解析输入数据
|
||||
input := struct {
|
||||
Token string `form:"token" binding:"required"`
|
||||
DedupBF bool `form:"dedup_bf"`
|
||||
CacheList bool `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不能为空"})
|
||||
@@ -107,14 +132,77 @@ func DeleteTokenInfoHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Token不存在" + err.Error()})
|
||||
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()
|
||||
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)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
//输出信息
|
||||
|
21
db/local.go
21
db/local.go
@@ -12,6 +12,8 @@ var localDB []Token
|
||||
type Token struct {
|
||||
Token string `json:"token"`
|
||||
DedupObject string `json:"dedup_object"`
|
||||
DataFormat string `json:"data_format"`
|
||||
Notes string `json:"notes"`
|
||||
}
|
||||
|
||||
func InitLocalDB() {
|
||||
@@ -35,7 +37,7 @@ func ListToken() []Token {
|
||||
return localDB
|
||||
}
|
||||
|
||||
func CreateToken(token string, dedupObject string) error {
|
||||
func CreateToken(token string, dedupObject string, dataFormat string, Notes string) error {
|
||||
InitLocalDB()
|
||||
for _, t := range localDB {
|
||||
if t.Token == token {
|
||||
@@ -43,7 +45,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)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -55,12 +57,14 @@ func CreateToken(token string, dedupObject string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateToken(token string, dedupObject string) error {
|
||||
func UpdateToken(token string, dedupObject string, dataFormat string, Notes string) error {
|
||||
InitLocalDB()
|
||||
|
||||
for i, t := range localDB {
|
||||
if t.Token == token {
|
||||
localDB[i].DedupObject = dedupObject
|
||||
localDB[i].DataFormat = dataFormat
|
||||
localDB[i].Notes = Notes
|
||||
|
||||
marshal, err := json.Marshal(localDB)
|
||||
if err != nil {
|
||||
@@ -72,6 +76,7 @@ func UpdateToken(token string, dedupObject string) error {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
InitLocalDB()
|
||||
return errors.New("token not found")
|
||||
}
|
||||
@@ -93,6 +98,7 @@ func DeleteToken(token string) error {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
InitLocalDB()
|
||||
return errors.New("token not found")
|
||||
}
|
||||
@@ -105,3 +111,12 @@ func GetDedupObject(token string) (dedupObject string, err error) {
|
||||
}
|
||||
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")
|
||||
}
|
||||
|
@@ -16,19 +16,6 @@ import (
|
||||
"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{
|
||||
Transport: &http.Transport{
|
||||
MaxIdleConns: 200,
|
||||
@@ -39,14 +26,45 @@ 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.Printf("上传完成,耗时:%s\n", time.Since(start))
|
||||
}
|
||||
time.Sleep(time.Minute)
|
||||
}
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
//程序配置
|
||||
viper.SetDefault("url", "http://localhost:8080")
|
||||
viper.SetDefault("token", "")
|
||||
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
|
||||
viper.AddConfigPath(".")
|
||||
viper.SetConfigName("config")
|
||||
@@ -62,46 +80,12 @@ func main() {
|
||||
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.Add("token", viper.GetString("token"))
|
||||
params.Add("dyid", data.Dyid)
|
||||
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)
|
||||
params.Set("token", viper.GetString("token"))
|
||||
params.Set("data", data)
|
||||
|
||||
resp, err := httpClient.Post(viper.GetString("url")+"/api/data?"+params.Encode(), "application/x-www-form-urlencoded", strings.NewReader(""))
|
||||
if err != nil {
|
||||
@@ -114,10 +98,8 @@ func uploadDataToServer(data UploadData) error {
|
||||
}
|
||||
|
||||
// 获取目录中的所有txt文件
|
||||
func getTxtFiles(dir string) ([]string, error) {
|
||||
var txtFiles []string
|
||||
|
||||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
func getTxtFiles(dir string) (txtFiles []string, err error) {
|
||||
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -177,6 +159,7 @@ func processFile(filePath string) {
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
fmt.Printf("读取文件 %s 错误: %v\n", filePath, err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("文件【%s】处理完成,共处理 %d 行数据\n", filePath, lineCount)
|
||||
@@ -188,35 +171,8 @@ func processLines(lines <-chan string, workerID int, filePath string) {
|
||||
if strings.TrimSpace(line) == "" {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Vite App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
<title>dypid</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -1,64 +1,15 @@
|
||||
<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="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>
|
||||
<router-view></router-view>
|
||||
</template>
|
||||
|
||||
|
||||
<style>
|
||||
<style scoped>
|
||||
html, body, #app {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.el-container {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.el-menu-demo {
|
||||
line-height: 60px;
|
||||
}
|
||||
</style>
|
||||
|
@@ -2,10 +2,33 @@ import {createRouter, createWebHistory} from 'vue-router'
|
||||
|
||||
import TokenManageView from '@/views/TokenManageView.vue'
|
||||
import TokenDetailView from '@/views/TokenDetailView.vue'
|
||||
import AdminView from '@/views/AdminView.vue'
|
||||
import HomeView from '@/views/HomeView.vue'
|
||||
|
||||
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({
|
||||
|
@@ -2,11 +2,13 @@ import {ref, computed} from 'vue'
|
||||
import {defineStore} from 'pinia'
|
||||
|
||||
export const useCounterStore = defineStore('counter', () => {
|
||||
const homeToken = ref("")
|
||||
|
||||
const token = ref("")
|
||||
|
||||
const isAdmin = ref(false)
|
||||
|
||||
|
||||
|
||||
return {token, isAdmin}
|
||||
}, {
|
||||
persist: true
|
||||
|
50
web/src/views/AdminView.vue
Normal file
50
web/src/views/AdminView.vue
Normal 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>
|
77
web/src/views/HomeView.vue
Normal file
77
web/src/views/HomeView.vue
Normal 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>
|
@@ -3,8 +3,25 @@ import {useCounterStore} from "@/stores/counter.ts";
|
||||
import {ref, watch} from 'vue'
|
||||
import axios from "@/axios.ts";
|
||||
|
||||
|
||||
// 创建响应式引用,用于存储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 deleteSpecifyDedupVisible = ref(false)
|
||||
const inputSpecifyDedup = ref('')
|
||||
const deleteSpecifyRawVisible = ref(false)
|
||||
const inputSpecifyRaw = ref('')
|
||||
|
||||
const getInfo = () => {
|
||||
if (value.value != '') {
|
||||
@@ -24,17 +41,18 @@ const deleteDedup = () => {
|
||||
axios.delete('/api/token/info', {
|
||||
params: {
|
||||
token: value.value,
|
||||
dedup_bf: true
|
||||
dedup_bf: "all"
|
||||
}
|
||||
}).then(res => {
|
||||
getInfo()
|
||||
})
|
||||
}
|
||||
|
||||
const deleteRedis = () => {
|
||||
axios.delete('/api/token/info', {
|
||||
params: {
|
||||
token: value.value,
|
||||
cache_list: true
|
||||
cache_list: "all",
|
||||
}
|
||||
}).then(res => {
|
||||
getInfo()
|
||||
@@ -45,55 +63,133 @@ getInfo()
|
||||
setInterval(getInfo, 5000)
|
||||
|
||||
watch(value, (newValue) => {
|
||||
useCounterStore().token = value.value
|
||||
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 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>
|
||||
|
||||
|
||||
<template>
|
||||
<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"
|
||||
/>
|
||||
</el-select>
|
||||
<div v-if="!useCounterStore().isAdmin">
|
||||
<el-alert title="您没有权限访问此页面" type="error" center show-icon/>
|
||||
</div>
|
||||
|
||||
|
||||
<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">
|
||||
<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-button type="danger" @click="deleteRedis">删除Redis数据</el-button>
|
||||
<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="去重对象" 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>
|
||||
</template>
|
||||
|
||||
|
@@ -2,43 +2,60 @@
|
||||
import {ref} from "vue";
|
||||
import axios from "@/axios.ts";
|
||||
import {ElMessage, ElMessageBox} from 'element-plus'
|
||||
import {useCounterStore} from "@/stores/counter.ts";
|
||||
import {useRouter} from "vue-router";
|
||||
|
||||
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 => {
|
||||
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 = () => {
|
||||
axios.post('/api/token', {}, {
|
||||
params: {
|
||||
token: input.value,
|
||||
dedup_object: value.value
|
||||
dedup_object: value.value,
|
||||
data_format: dataFormat.value,
|
||||
notes: inputNotes.value,
|
||||
}
|
||||
}).then(response => {
|
||||
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) => {
|
||||
useCounterStore().token = row.token
|
||||
router.push({
|
||||
name: "TokenDetail"
|
||||
name: "TokenDetail",
|
||||
})
|
||||
}
|
||||
|
||||
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', {}, {
|
||||
params: {
|
||||
token: rowOut.token,
|
||||
dedup_object: value.value
|
||||
dedup_object: value.value,
|
||||
data_format: rowOut.data_format,
|
||||
notes: rowOut.notes,
|
||||
}
|
||||
}).then(res => {
|
||||
if (res.data.result == "ok") {
|
||||
@@ -92,7 +106,64 @@ const updateDedupObject = () => {
|
||||
}).catch(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) => {
|
||||
@@ -115,9 +186,8 @@ const deleteToken = (row: any) => {
|
||||
})
|
||||
}
|
||||
|
||||
const inputPassWord = ref('')
|
||||
const checkPassword = () => {
|
||||
if (inputPassWord.value == "admin") {
|
||||
if (inputPassWord.value == "haha") {
|
||||
ElMessage({
|
||||
message: '密码正确',
|
||||
type: 'success',
|
||||
@@ -127,7 +197,6 @@ const checkPassword = () => {
|
||||
ElMessage.error('密码错误')
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -135,7 +204,7 @@ const checkPassword = () => {
|
||||
<div v-if="!useCounterStore().isAdmin" style="margin: auto auto; max-width: 400px">
|
||||
<el-alert title="您没有权限访问此页面,输入管理员密码" type="error" :closable="false" show-icon/>
|
||||
<p></p>
|
||||
<el-input v-model="inputPassWord" style="width: 400px" placeholder="请输入管理员密码"/>
|
||||
<el-input v-model="inputPassWord" style="width: 400px" placeholder="请输入管理员密码" @change="checkPassword"/>
|
||||
<p></p>
|
||||
<el-button type="primary" @click="checkPassword">确认</el-button>
|
||||
</div>
|
||||
@@ -143,25 +212,36 @@ const checkPassword = () => {
|
||||
<!--管理员-->
|
||||
<div v-if="useCounterStore().isAdmin">
|
||||
<!--添加Token-->
|
||||
<el-input v-model="input" style="width: 200px" placeholder="请输入Token名称"/>
|
||||
<el-select v-model="value" placeholder="选择去重对象" style="width: 200px">
|
||||
<el-input v-model="input" style="width: 150px" placeholder="请输入Token名称"/>
|
||||
<el-select v-model="value" placeholder="选择去重对象" style="width: 150px">
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</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>
|
||||
|
||||
<!--Token列表-->
|
||||
<el-table :data="tableData" style="width: 100%">
|
||||
<el-table-column prop="token" label="Token" width="180"/>
|
||||
<el-table-column prop="dedup_object" label="去重对象" width="180"/>
|
||||
<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"/>
|
||||
<el-table-column prop="notes" label="备注" width="200"/>
|
||||
<el-table-column label="操作">
|
||||
<template #default="scope">
|
||||
<el-button @click="viewDetails(scope.row)">查看详细</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
|
||||
width="180"
|
||||
title="确认删除此Token吗"
|
||||
@@ -183,7 +263,6 @@ const checkPassword = () => {
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
@@ -193,6 +272,30 @@ const checkPassword = () => {
|
||||
</el-button>
|
||||
</template>
|
||||
</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>
|
||||
</template>
|
||||
|
||||
|
Reference in New Issue
Block a user