diff --git a/httpstaticserver.go b/httpstaticserver.go index b1f068d..0657f0a 100644 --- a/httpstaticserver.go +++ b/httpstaticserver.go @@ -322,7 +322,7 @@ func (s *HTTPStaticServer) hFileOrDirectory(w http.ResponseWriter, r *http.Reque http.ServeFile(w, r, filepath.Join(s.Root, path)) } -type ListResponse struct { +type HTTPFileInfo struct { Name string `json:"name"` Path string `json:"path"` Type string `json:"type"` @@ -365,9 +365,9 @@ func (s *HTTPStaticServer) hJSONList(w http.ResponseWriter, r *http.Request) { } // turn file list -> json - lrs := make([]ListResponse, 0) + lrs := make([]HTTPFileInfo, 0) for path, info := range fileInfoMap { - lr := ListResponse{ + lr := HTTPFileInfo{ Name: info.Name(), Path: path, ModTime: info.ModTime().UnixNano() / 1e6, diff --git a/res/js/index.js b/res/js/index.js index 6529c11..ba67bb0 100644 --- a/res/js/index.js +++ b/res/js/index.js @@ -285,7 +285,7 @@ Vue.filter('fromNow', function(value) { Vue.filter('formatBytes', function(value) { var bytes = parseFloat(value); if (bytes < 0) return "-"; - else if (bytes < 1024) return bytes + " Bytes"; + else if (bytes < 1024) return bytes + " B"; else if (bytes < 1048576) return (bytes / 1024).toFixed(0) + " KB"; else if (bytes < 1073741824) return (bytes / 1048576).toFixed(1) + " MB"; else return (bytes / 1073741824).toFixed(1) + " GB"; diff --git a/utils.go b/utils.go index e386d01..d181d30 100644 --- a/utils.go +++ b/utils.go @@ -1,28 +1,25 @@ package main import ( - "fmt" "net/http" - "os" - "strconv" "strings" ) -func formatSize(file os.FileInfo) string { - if file.IsDir() { - return "-" - } - size := file.Size() - switch { - case size > 1024*1024: - return fmt.Sprintf("%.1f MB", float64(size)/1024/1024) - case size > 1024: - return fmt.Sprintf("%.1f KB", float64(size)/1024) - default: - return strconv.Itoa(int(size)) + " B" - } - return "" -} +// func formatSize(file os.FileInfo) string { +// if file.IsDir() { +// return "-" +// } +// size := file.Size() +// switch { +// case size > 1024*1024: +// return fmt.Sprintf("%.1f MB", float64(size)/1024/1024) +// case size > 1024: +// return fmt.Sprintf("%.1f KB", float64(size)/1024) +// default: +// return strconv.Itoa(int(size)) + " B" +// } +// return "" +// } func getRealIP(req *http.Request) string { xip := req.Header.Get("X-Real-IP")