|
|
@ -2,14 +2,25 @@ package utils
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
|
|
BYTE = 1 << (10 * iota)
|
|
|
|
|
|
|
|
KILOBYTE
|
|
|
|
|
|
|
|
MEGABYTE
|
|
|
|
|
|
|
|
GIGABYTE
|
|
|
|
|
|
|
|
TERABYTE
|
|
|
|
|
|
|
|
PETABYTE
|
|
|
|
|
|
|
|
EXABYTE
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Determine whether the given path is a folder
|
|
|
|
// Determine whether the given path is a folder
|
|
|
|
func IsDir(path string) bool {
|
|
|
|
func IsDir(path string) bool {
|
|
|
|
s, err := os.Stat(path)
|
|
|
|
s, err := os.Stat(path)
|
|
|
@ -39,39 +50,34 @@ func GetNewFileNameAndContentType(fileName string, fileType int) (string, string
|
|
|
|
return newName, contentType
|
|
|
|
return newName, contentType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func GetUploadAppNewName(appType int, version, fileName, yamlName string) (string, string, error) {
|
|
|
|
func ByteSize(bytes uint64) string {
|
|
|
|
var newFileName, newYamlName = "_" + version + "_app", "_" + version + "_yaml"
|
|
|
|
unit := ""
|
|
|
|
switch appType {
|
|
|
|
value := float64(bytes)
|
|
|
|
case constant.IOSPlatformID:
|
|
|
|
switch {
|
|
|
|
newFileName = constant.IOSPlatformStr + newFileName
|
|
|
|
case bytes >= EXABYTE:
|
|
|
|
newYamlName = constant.IOSPlatformStr + newYamlName
|
|
|
|
unit = "E"
|
|
|
|
case constant.AndroidPlatformID:
|
|
|
|
value = value / EXABYTE
|
|
|
|
newFileName = constant.AndroidPlatformStr + newFileName
|
|
|
|
case bytes >= PETABYTE:
|
|
|
|
newYamlName = constant.AndroidPlatformStr + newYamlName
|
|
|
|
unit = "P"
|
|
|
|
case constant.WindowsPlatformID:
|
|
|
|
value = value / PETABYTE
|
|
|
|
newFileName = constant.WindowsPlatformStr + newFileName
|
|
|
|
case bytes >= TERABYTE:
|
|
|
|
newYamlName = constant.WindowsPlatformStr + newYamlName
|
|
|
|
unit = "T"
|
|
|
|
case constant.OSXPlatformID:
|
|
|
|
value = value / TERABYTE
|
|
|
|
newFileName = constant.OSXPlatformStr + newFileName
|
|
|
|
case bytes >= GIGABYTE:
|
|
|
|
newYamlName = constant.OSXPlatformStr + newYamlName
|
|
|
|
unit = "G"
|
|
|
|
case constant.WebPlatformID:
|
|
|
|
value = value / GIGABYTE
|
|
|
|
newFileName = constant.WebPlatformStr + newFileName
|
|
|
|
case bytes >= MEGABYTE:
|
|
|
|
newYamlName = constant.WebPlatformStr + newYamlName
|
|
|
|
unit = "M"
|
|
|
|
case constant.MiniWebPlatformID:
|
|
|
|
value = value / MEGABYTE
|
|
|
|
newFileName = constant.MiniWebPlatformStr + newFileName
|
|
|
|
case bytes >= KILOBYTE:
|
|
|
|
newYamlName = constant.MiniWebPlatformStr + newYamlName
|
|
|
|
unit = "K"
|
|
|
|
case constant.LinuxPlatformID:
|
|
|
|
value = value / KILOBYTE
|
|
|
|
newFileName = constant.LinuxPlatformStr + newFileName
|
|
|
|
case bytes >= BYTE:
|
|
|
|
newYamlName = constant.LinuxPlatformStr + newYamlName
|
|
|
|
unit = "B"
|
|
|
|
default:
|
|
|
|
case bytes == 0:
|
|
|
|
return "", "", errors.New("invalid app type")
|
|
|
|
return "0"
|
|
|
|
}
|
|
|
|
|
|
|
|
suffixFile := path.Ext(fileName)
|
|
|
|
|
|
|
|
suffixYaml := path.Ext(yamlName)
|
|
|
|
|
|
|
|
newFileName = fmt.Sprintf("%s%s", newFileName, suffixFile)
|
|
|
|
|
|
|
|
newYamlName = fmt.Sprintf("%s%s", newYamlName, suffixYaml)
|
|
|
|
|
|
|
|
if yamlName == "" {
|
|
|
|
|
|
|
|
newYamlName = ""
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newFileName, newYamlName, nil
|
|
|
|
result := strconv.FormatFloat(value, 'f', 1, 64)
|
|
|
|
|
|
|
|
result = strings.TrimSuffix(result, ".0")
|
|
|
|
|
|
|
|
return result + unit
|
|
|
|
}
|
|
|
|
}
|
|
|
|