From 025cfff2970da4625aac4966439ea3a906385e1d Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 7 May 2017 13:51:59 +0200 Subject: [PATCH] Show unknown filesizes correctly --- model/torrent.go | 2 +- util/format.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/model/torrent.go b/model/torrent.go index 9144d530..bb4c3b20 100644 --- a/model/torrent.go +++ b/model/torrent.go @@ -82,7 +82,7 @@ func (t *Torrents) ToJson() TorrentsJson { Status: t.Status, Hash: t.Hash, Date: time.Unix(t.Date, 0).Format(time.RFC3339), - Filesize: util.FormatFilesize(t.Filesize), + Filesize: util.FormatFilesize2(t.Filesize), Description: template.HTML(t.Description), Comments: b, Sub_Category: strconv.Itoa(t.Sub_Category), diff --git a/util/format.go b/util/format.go index 18427e83..44eb12ca 100644 --- a/util/format.go +++ b/util/format.go @@ -25,3 +25,11 @@ func FormatFilesize(bytes int64) string { } return fmt.Sprintf("%.1f %s", value, unit) } + +func FormatFilesize2(bytes int64) string { + if bytes == 0 { // this is what gorm returns for NULL + return "Unknown" + } else { + return FormatFilesize(bytes) + } +}