mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-06 01:44:26 +02:00
refactor handling of -1 from base to business logic and UI for sizelimit working
This commit is contained in:
8 files changed
+64
-48
No files matched your search
@@ -93,21 +93,18 @@ func CreateTimeLimitCode[T time.Time | string](data string, minutes int, startTi
|
||||
|
||||
// FileSize calculates the file size and generate user-friendly string.
|
||||
func FileSize(s int64) string {
|
||||
if s == -1 {
|
||||
return "-1"
|
||||
}
|
||||
return humanize.IBytes(uint64(s))
|
||||
}
|
||||
|
||||
// Get FileSize bytes value from String.
|
||||
// GetFileSize gets FileSize bytes value from String.
|
||||
func GetFileSize(s string) (int64, error) {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "-1" {
|
||||
return -1, nil
|
||||
// default to bytes if no unit is provided
|
||||
if _, err := strconv.ParseInt(s, 10, 64); err == nil {
|
||||
s += " B"
|
||||
}
|
||||
v, err := humanize.ParseBytes(s)
|
||||
iv := int64(v)
|
||||
return iv, err
|
||||
return int64(v), err
|
||||
}
|
||||
|
||||
// StringsToInt64s converts a slice of string to a slice of int64.
|
||||
|
||||
Reference in new issue
Block a user