Format unknown filesizes in a better way
Cette révision appartient à :
Parent
af3d8957b3
révision
67ec4d5787
4 fichiers modifiés avec 11 ajouts et 19 suppressions
|
@ -25,7 +25,7 @@ type DatabaseDumpJSON struct {
|
|||
func (dump *DatabaseDump) ToJSON() DatabaseDumpJSON {
|
||||
json := DatabaseDumpJSON{
|
||||
Date: dump.Date.Format(time.RFC3339),
|
||||
Filesize: util.FormatFilesize2(dump.Filesize),
|
||||
Filesize: util.FormatFilesize(dump.Filesize),
|
||||
Name: dump.Name,
|
||||
TorrentLink: template.URL(dump.TorrentLink),
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ type CommentJSON struct {
|
|||
|
||||
type FileJSON struct {
|
||||
Path string `json:"path"`
|
||||
Filesize string `json:"filesize"`
|
||||
Filesize int64 `json:"filesize"`
|
||||
}
|
||||
|
||||
type TorrentJSON struct {
|
||||
|
@ -133,7 +133,7 @@ type TorrentJSON struct {
|
|||
Status int `json:"status"`
|
||||
Hash string `json:"hash"`
|
||||
Date string `json:"date"`
|
||||
Filesize string `json:"filesize"`
|
||||
Filesize int64 `json:"filesize"`
|
||||
Description template.HTML `json:"description"`
|
||||
Comments []CommentJSON `json:"comments"`
|
||||
SubCategory string `json:"sub_category"`
|
||||
|
@ -176,7 +176,7 @@ func (t *Torrent) ToJSON() TorrentJSON {
|
|||
for _, f := range t.FileList {
|
||||
fileListJSON = append(fileListJSON, FileJSON{
|
||||
Path: filepath.Join(f.Path()...),
|
||||
Filesize: util.FormatFilesize2(f.Filesize),
|
||||
Filesize: f.Filesize,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ func (t *Torrent) ToJSON() TorrentJSON {
|
|||
Status: t.Status,
|
||||
Hash: t.Hash,
|
||||
Date: t.Date.Format(time.RFC3339),
|
||||
Filesize: util.FormatFilesize2(t.Filesize),
|
||||
Filesize: t.Filesize,
|
||||
Description: util.MarkdownToHTML(t.Description),
|
||||
Comments: commentsJSON,
|
||||
SubCategory: strconv.Itoa(t.SubCategory),
|
||||
|
|
|
@ -2,7 +2,6 @@ package router
|
|||
|
||||
import (
|
||||
"html/template"
|
||||
//"log"
|
||||
"math"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
@ -10,6 +9,7 @@ import (
|
|||
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
"github.com/NyaaPantsu/nyaa/service/user/permission"
|
||||
"github.com/NyaaPantsu/nyaa/util"
|
||||
"github.com/NyaaPantsu/nyaa/util/languages"
|
||||
)
|
||||
|
||||
|
@ -120,7 +120,6 @@ var FuncMap = template.FuncMap{
|
|||
if endValue > int(maxPages) {
|
||||
endValue = int(maxPages)
|
||||
}
|
||||
//log.Println(nav.TotalItem)
|
||||
for i := startValue; i <= endValue; i++ {
|
||||
pageNum := strconv.Itoa(i)
|
||||
url, _ := Router.Get(nav.Route).URL("page", pageNum)
|
||||
|
@ -208,11 +207,11 @@ var FuncMap = template.FuncMap{
|
|||
}
|
||||
return e
|
||||
},
|
||||
"fileSize": func(filesize string, T languages.TemplateTfunc) template.HTML {
|
||||
if (filesize == "Unknown") {
|
||||
return T("unknown")
|
||||
}
|
||||
return template.HTML(filesize)
|
||||
"fileSize": func(filesize int64, T languages.TemplateTfunc) template.HTML {
|
||||
if (filesize == 0) {
|
||||
return T("unknown")
|
||||
}
|
||||
return template.HTML(util.FormatFilesize(filesize))
|
||||
},
|
||||
"makeCaptchaData": func(captchaID string, T languages.TemplateTfunc) captchaData {
|
||||
return captchaData{captchaID, T}
|
||||
|
|
|
@ -25,10 +25,3 @@ 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"
|
||||
}
|
||||
return FormatFilesize(bytes)
|
||||
}
|
||||
|
|
Référencer dans un nouveau ticket