图片处理模块

This commit is contained in:
李琦
2026-06-30 12:30:49 +08:00
parent 3882f33058
commit 617760a319
36 changed files with 2293 additions and 2102 deletions

View File

@@ -2,6 +2,7 @@ package services
import (
"encoding/json"
"fmt"
"path/filepath"
"strings"
)
@@ -31,3 +32,23 @@ func ToJSON(v interface{}) ([]byte, error) {
func ParseJSON(data []byte, v interface{}) error {
return json.Unmarshal(data, v)
}
// formatSize 格式化文件大小为可读字符串
func formatSize(bytes int64) string {
const (
KB = 1024
MB = KB * 1024
GB = MB * 1024
)
switch {
case bytes >= GB:
return fmt.Sprintf("%.2f GB", float64(bytes)/float64(GB))
case bytes >= MB:
return fmt.Sprintf("%.2f MB", float64(bytes)/float64(MB))
case bytes >= KB:
return fmt.Sprintf("%.2f KB", float64(bytes)/float64(KB))
default:
return fmt.Sprintf("%d B", bytes)
}
}