diff --git a/internal/utils/numberutils/utils.go b/internal/utils/numberutils/utils.go index ee3e5618..7b0c09e1 100644 --- a/internal/utils/numberutils/utils.go +++ b/internal/utils/numberutils/utils.go @@ -24,37 +24,19 @@ func Pow1024(n int) int64 { } func FormatBytes(bytes int64) string { - if bytes < 1024 { + if bytes < Pow1024(1) { return FormatInt64(bytes) + "B" - } else if bytes < 1024*1024 { - return fmt.Sprintf("%.2fKB", float64(bytes)/1024) - } else if bytes < 1024*1024*1024 { - return fmt.Sprintf("%.2fMB", float64(bytes)/1024/1024) - } else if bytes < 1024*1024*1024*1024 { - return fmt.Sprintf("%.2fGB", float64(bytes)/1024/1024/1024) - } else if bytes < 1024*1024*1024*1024*1024 { - return fmt.Sprintf("%.2fTB", float64(bytes)/1024/1024/1024/1024) - } else if bytes < 1024*1024*1024*1024*1024*1024 { - return fmt.Sprintf("%.2fPB", float64(bytes)/1024/1024/1024/1024/1024) + } else if bytes < Pow1024(2) { + return fmt.Sprintf("%.2fKB", float64(bytes)/float64(Pow1024(1))) + } else if bytes < Pow1024(3) { + return fmt.Sprintf("%.2fMB", float64(bytes)/float64(Pow1024(2))) + } else if bytes < Pow1024(4) { + return fmt.Sprintf("%.2fGB", float64(bytes)/float64(Pow1024(3))) + } else if bytes < Pow1024(5) { + return fmt.Sprintf("%.2fTB", float64(bytes)/float64(Pow1024(4))) + } else if bytes < Pow1024(6) { + return fmt.Sprintf("%.2fPB", float64(bytes)/float64(Pow1024(5))) } else { - return fmt.Sprintf("%.2fEB", float64(bytes)/1024/1024/1024/1024/1024/1024) - } -} - -func FormatBits(bits int64) string { - if bits < 1000 { - return FormatInt64(bits) + "B" - } else if bits < 1000*1000 { - return fmt.Sprintf("%.2fKB", float64(bits)/1000) - } else if bits < 1000*1000*1000 { - return fmt.Sprintf("%.2fMB", float64(bits)/1000/1000) - } else if bits < 1000*1000*1000*1000 { - return fmt.Sprintf("%.2fGB", float64(bits)/1000/1000/1000) - } else if bits < 1000*1000*1000*1000*1000 { - return fmt.Sprintf("%.2fTB", float64(bits)/1000/1000/1000/1000) - } else if bits < 1000*1000*1000*1000*1000*1000 { - return fmt.Sprintf("%.2fPB", float64(bits)/1000/1000/1000/1000/1000) - } else { - return fmt.Sprintf("%.2fEB", float64(bits)/1000/1000/1000/1000/1000/1000) + return fmt.Sprintf("%.2fEB", float64(bytes)/float64(Pow1024(6))) } } diff --git a/internal/utils/numberutils/utils_test.go b/internal/utils/numberutils/utils_test.go new file mode 100644 index 00000000..c71f1033 --- /dev/null +++ b/internal/utils/numberutils/utils_test.go @@ -0,0 +1,16 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package numberutils + +import "testing" + +func TestFormatBytes(t *testing.T) { + t.Log(FormatBytes(1)) + t.Log(FormatBytes(1000)) + t.Log(FormatBytes(1_000_000)) + t.Log(FormatBytes(1_000_000_000)) + t.Log(FormatBytes(1_000_000_000_000)) + t.Log(FormatBytes(1_000_000_000_000_000)) + t.Log(FormatBytes(1_000_000_000_000_000_000)) + t.Log(FormatBytes(9_000_000_000_000_000_000)) +} diff --git a/internal/web/actions/default/servers/create.go b/internal/web/actions/default/servers/create.go index 53f51524..26667286 100644 --- a/internal/web/actions/default/servers/create.go +++ b/internal/web/actions/default/servers/create.go @@ -467,7 +467,7 @@ func (this *CreateAction) RunPost(params struct { AccessLogJSON: []byte(`{ "isPrior": false, "isOn": true, - "fields": [], + "fields": [6, 7], "status1": true, "status2": true, "status3": true, diff --git a/internal/web/helpers/user_must_auth.go b/internal/web/helpers/user_must_auth.go index 76c365c8..0824ff9e 100644 --- a/internal/web/helpers/user_must_auth.go +++ b/internal/web/helpers/user_must_auth.go @@ -191,8 +191,8 @@ func (this *userMustAuth) modules(actionPtr actions.ActionWrapper, adminId int64 var countNodeLogs = countNodeLogsResp.Count if countNodeLogs > 0 { countUnreadNodeLogs = countNodeLogs - if countUnreadNodeLogs >= 1000 { - countUnreadNodeLogs = 999 + if countUnreadNodeLogs >= 100 { + countUnreadNodeLogs = 99 } nodeLogsType = "unread" }