🎨客户端列表新增客户端数据流量情况

This commit is contained in:
coward
2024-07-10 10:51:20 +08:00
parent 697341f823
commit 4b864f76bb
5 changed files with 73 additions and 11 deletions

View File

@@ -3,7 +3,9 @@ package utils
import (
"fmt"
"gitee.ltd/lxh/logger/log"
"github.com/google/uuid"
"os"
"strings"
"time"
"wireguard-ui/config"
"wireguard-ui/global/client"
@@ -31,15 +33,18 @@ func (fileSystem) UploadFile(file []byte, suffix string) (filePath string, err e
filePath = ossObj.LongPath
case "local":
filePath = fmt.Sprintf("%v/%d-avatar%s", config.Config.File.Path, time.Now().Unix(), suffix)
basePath := fmt.Sprintf("%s/%d/avatar", config.Config.File.Path, time.Now().Unix())
filePath = fmt.Sprintf("%s/%s%s", basePath, strings.ReplaceAll(uuid.NewString(), "-", ""), suffix)
// 创建目录
if err = os.MkdirAll(filePath, os.FileMode(0777)); err != nil {
if err = os.MkdirAll(basePath, os.FileMode(0777)); err != nil {
log.Errorf("本地存储目录创建失败: %v", err)
return "", err
}
if err = os.WriteFile(filePath, file, os.FileMode(0777)); err != nil {
return "", err
}
subPath := strings.ReplaceAll(filePath, fmt.Sprintf("%s/", config.Config.File.Path), "")
filePath = fmt.Sprintf("http://%s/assets/%s", config.Config.Http.Endpoint, subPath)
}
return filePath, err
}

22
utils/flow_calculation.go Normal file
View File

@@ -0,0 +1,22 @@
package utils
import (
"github.com/dustin/go-humanize"
"math/big"
)
type flowCalculation struct{}
func FlowCalculation() flowCalculation {
return flowCalculation{}
}
// Parse
// @description: 解析流量,序列化为字符串
// @receiver flowCalculation
// @param b
// @return string
func (flowCalculation) Parse(b int64) string {
b2 := big.Int{}
return humanize.BigBytes(b2.SetInt64(b))
}