Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
elvis972602 committed Feb 8, 2023
1 parent 2262045 commit 0d99921
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ func main() {
downloaderOptions = append(downloaderOptions, downloader.BaseURL("https://coomer.party"))
CoomerDownloader = downloader.NewDownloader(downloaderOptions...)
options[Coomer] = append(options[Coomer], kemono.SetDownloader(CoomerDownloader))
options[Coomer] = append(options[Coomer], kemono.WithBanner(true))
KCoomer = kemono.NewKemono(options[Coomer]...)
}

Expand Down
36 changes: 27 additions & 9 deletions utils/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
func FormatSize(size int64) string {

switch {
case size >= TB:
return fmt.Sprintf("%.2fTB", float64(size)/TB)
case size >= GB:
return fmt.Sprintf("%.2f GB", float64(size)/GB)
case size >= MB:
Expand All @@ -33,22 +35,38 @@ func FormatSize(size int64) string {
}

func ParseSize(size string) int64 {
size = strings.ToUpper(size)
var (
fvalue float64
unit string
value string
)
// 1MB or 1 MB
parts := strings.Fields(size)
value, err := strconv.ParseFloat(parts[0], 64)
if err != nil {
return 0
if len(parts) != 2 {
for _, u := range []string{"TB", "GB", "MB", "KB", "B"} {
if strings.HasSuffix(size, u) {
value = strings.TrimSuffix(size, u)
unit = u
break
}
}
fvalue, _ = strconv.ParseFloat(value, 64)
} else {
fvalue, _ = strconv.ParseFloat(parts[0], 64)
unit = parts[1]
}
switch parts[1] {
switch unit {
case "TB":
return int64(value * TB)
return int64(fvalue * TB)
case "GB":
return int64(value * GB)
return int64(fvalue * GB)
case "MB":
return int64(value * MB)
return int64(fvalue * MB)
case "KB":
return int64(value * KB)
return int64(fvalue * KB)
default:
return int64(value)
return int64(fvalue)
}
}

Expand Down

0 comments on commit 0d99921

Please sign in to comment.