99ad76f76f
* This allows changing the nyaa, sukebei and status URL via config. Previously only the nyaa address was configurable * This helps testing changes locally without having to set up a TLS terminating proxy * Also refactored uses of hardcoded URLs in the html templates The html templates will now also use the configured urls
38 lignes
834 o
Go
38 lignes
834 o
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
)
|
|
|
|
// FormatFilesize : format file size
|
|
func FormatFilesize(bytes int64) string {
|
|
var unit string
|
|
var value float64
|
|
if bytes >= 1024*1024*1024*1024 {
|
|
unit = "TiB"
|
|
value = float64(bytes) / (1024 * 1024 * 1024 * 1024)
|
|
} else if bytes >= 1024*1024*1024 {
|
|
unit = "GiB"
|
|
value = float64(bytes) / (1024 * 1024 * 1024)
|
|
} else if bytes >= 1024*1024 {
|
|
unit = "MiB"
|
|
value = float64(bytes) / (1024 * 1024)
|
|
} else if bytes >= 1024 {
|
|
unit = "KiB"
|
|
value = float64(bytes) / (1024)
|
|
} else {
|
|
unit = "B"
|
|
value = float64(bytes)
|
|
}
|
|
return fmt.Sprintf("%.1f %s", value, unit)
|
|
}
|
|
|
|
// GetHostname : Returns the host of a URL, without any scheme or port number.
|
|
func GetHostname(rawurl string) string {
|
|
u, err := url.Parse(rawurl)
|
|
if err != nil {
|
|
return rawurl
|
|
}
|
|
return u.Hostname()
|
|
}
|