Code cleanup
This commit is contained in:
+1
-23
@@ -232,29 +232,7 @@ func GetPostFileInfo(mediaPath string) PostFileInfo {
|
||||
return result
|
||||
}
|
||||
|
||||
func FormatBytes(bytes int64) string {
|
||||
const (
|
||||
KB = 1 << 10 // 1024
|
||||
MB = 1 << 20
|
||||
GB = 1 << 30
|
||||
TB = 1 << 40
|
||||
)
|
||||
|
||||
switch {
|
||||
case bytes >= TB:
|
||||
return fmt.Sprintf("%.2f TB", float64(bytes)/float64(TB))
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
func FormatFileInfo(fileInfo PostFileInfo) string {
|
||||
func FormatPostFileInfo(fileInfo PostFileInfo) string {
|
||||
humanSize := FormatBytes(fileInfo.Size)
|
||||
if fileInfo.IsVideo {
|
||||
return fmt.Sprintf("(%s)", humanSize)
|
||||
|
||||
Reference in New Issue
Block a user