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) + } +}