Skip to content

Commit

Permalink
remove some useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Aug 6, 2016
1 parent a7fc705 commit b4efbd1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
6 changes: 3 additions & 3 deletions httpstaticserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion res/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
33 changes: 15 additions & 18 deletions utils.go
Original file line number Diff line number Diff line change
@@ -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")
Expand Down

0 comments on commit b4efbd1

Please sign in to comment.