cr fixes and dynamic upload size in UI
This commit is contained in:
@ -238,6 +238,11 @@ func (s *Server) viewHandler(w http.ResponseWriter, r *http.Request) {
|
||||
hostname := getURL(r, s.proxyPort).Host
|
||||
webAddress := resolveWebAddress(r, s.proxyPath, s.proxyPort)
|
||||
|
||||
maxUploadSize := ""
|
||||
if s.maxUploadSize > 0 {
|
||||
maxUploadSize = formatSize(s.maxUploadSize)
|
||||
}
|
||||
|
||||
purgeTime := ""
|
||||
if s.purgeDays > 0 {
|
||||
purgeTime = s.purgeDays.String()
|
||||
@ -248,8 +253,9 @@ func (s *Server) viewHandler(w http.ResponseWriter, r *http.Request) {
|
||||
WebAddress string
|
||||
GAKey string
|
||||
UserVoiceKey string
|
||||
PurgeTime string
|
||||
SampleToken string
|
||||
PurgeTime string
|
||||
MaxUploadSize string
|
||||
SampleToken string
|
||||
SampleToken2 string
|
||||
}{
|
||||
hostname,
|
||||
@ -257,6 +263,7 @@ func (s *Server) viewHandler(w http.ResponseWriter, r *http.Request) {
|
||||
s.gaKey,
|
||||
s.userVoiceKey,
|
||||
purgeTime,
|
||||
maxUploadSize,
|
||||
Token(s.randomTokenLength),
|
||||
Token(s.randomTokenLength),
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ THE SOFTWARE.
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"net/mail"
|
||||
@ -49,7 +50,6 @@ func getAwsSession(accessKey, secretKey, region, endpoint string, forcePathStyle
|
||||
}
|
||||
|
||||
func formatNumber(format string, s uint64) string {
|
||||
|
||||
return RenderFloat(format, float64(s))
|
||||
}
|
||||
|
||||
@ -255,3 +255,28 @@ func acceptsHTML(hdr http.Header) bool {
|
||||
|
||||
return (false)
|
||||
}
|
||||
|
||||
func formatSize(size int64) string {
|
||||
sizeFloat := float64(size)
|
||||
base := math.Log(sizeFloat)/math.Log(1024)
|
||||
|
||||
sizeOn := math.Pow(1024, base - math.Floor(base))
|
||||
|
||||
var round float64
|
||||
pow := math.Pow(10, float64(2))
|
||||
digit := pow * sizeOn
|
||||
round = math.Floor(digit)
|
||||
|
||||
newVal := round / pow
|
||||
|
||||
var suffixes [5]string
|
||||
suffixes[0] = "B"
|
||||
suffixes[1] = "KB"
|
||||
suffixes[2] = "MB"
|
||||
suffixes[3] = "GB"
|
||||
suffixes[4] = "TB"
|
||||
|
||||
|
||||
getSuffix := suffixes[int(math.Floor(base))]
|
||||
return fmt.Sprintf("%s %s", strconv.FormatFloat(newVal, 'f', -1, 64), getSuffix)
|
||||
}
|
||||
|
Reference in New Issue
Block a user