Skip to content

Commit

Permalink
close #18 support show folder size
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed May 17, 2017
1 parent a1b1611 commit e5677be
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Upload size now limited to 1G
1. [x] Custom title support
1. [x] Support setting from conf file
1. [x] Quick copy download link
1. [x] Show folder size

## Installation
```
Expand Down
25 changes: 24 additions & 1 deletion httpstaticserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (
type ApkInfo struct {
PackageName string `json:"packageName"`
MainActivity string `json:"mainActivity"`
Version struct {
Code int `json:"code"`
Name string `json:"name"`
} `json:"version"`
}

type IndexFileItem struct {
Expand Down Expand Up @@ -206,6 +210,8 @@ func (s *HTTPStaticServer) hInfo(w http.ResponseWriter, r *http.Request) {
ai := ApkInfo{}
ai.MainActivity, _ = apkf.MainAcitivty()
ai.PackageName = apkf.PackageName()
ai.Version.Code = apkf.Manifest().VersionCode
ai.Version.Name = apkf.Manifest().VersionName
fji.Extra = ai
}
default:
Expand Down Expand Up @@ -474,7 +480,7 @@ func (s *HTTPStaticServer) hJSONList(w http.ResponseWriter, r *http.Request) {
lr.Name = name
lr.Path = filepath.Join(filepath.Dir(path), name)
lr.Type = "dir"
lr.Size = -1 //"-"
lr.Size = s.historyDirSize(lr.Path)
} else {
lr.Type = "file"
lr.Size = info.Size() // formatSize(info)
Expand All @@ -490,6 +496,8 @@ func (s *HTTPStaticServer) hJSONList(w http.ResponseWriter, r *http.Request) {
w.Write(data)
}

var dirSizeMap = make(map[string]int64)

func (s *HTTPStaticServer) makeIndex() error {
var indexes = make([]IndexFileItem, 0)
var err = filepath.Walk(s.Root, func(path string, info os.FileInfo, err error) error {
Expand All @@ -508,9 +516,24 @@ func (s *HTTPStaticServer) makeIndex() error {
return nil
})
s.indexes = indexes
dirSizeMap = make(map[string]int64)
return err
}

func (s *HTTPStaticServer) historyDirSize(dir string) int64 {
var size int64
if size, ok := dirSizeMap[dir]; ok {
return size
}
for _, fitem := range s.indexes {
if filepath.HasPrefix(fitem.Path, dir) {
size += fitem.Info.Size()
}
}
dirSizeMap[dir] = size
return size
}

func (s *HTTPStaticServer) findIndex(text string) []IndexFileItem {
ret := make([]IndexFileItem, 0)
for _, item := range s.indexes {
Expand Down
29 changes: 24 additions & 5 deletions res/index.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<i style="padding-right: 0.5em" class="fa" v-bind:class='genFileClass(f)'></i> {{f.name}}
</a>
</td>
<td>{{f.size | formatBytes}}</td>
<td><span v-if="f.type == 'dir'">~</span> {{f.size | formatBytes}}</td>
<td class="hidden-xs">{{formatTime(f.mtime)}}</td>
<td style="text-align: left">
<template v-if="f.type == 'dir'">
Expand All @@ -130,13 +130,16 @@
<button class="btn btn-default btn-xs bstooltip" data-trigger="manual" data-title="Copied!" data-clipboard-text="{{genDownloadURL(f)}}">
<i class="fa fa-copy"></i>
</button>
<button class="btn btn-default btn-xs" v-on:click="showInfo(f)">
<span class="glyphicon glyphicon-info-sign"></span>
</button>
<button class="btn btn-default btn-xs hidden-xs" v-on:click="genQrcode(f.name)">
<span v-if="shouldHaveQrcode(f.name)">QRCode</span>
<span class="glyphicon glyphicon-qrcode"></span>
</button>
<a class="btn btn-default btn-xs visible-xs" v-if="shouldHaveQrcode(f.name)" href="{{genInstallURL(f.name)}}">
Install <i class="fa fa-cube"></i>
</a>
Install <i class="fa fa-cube"></i>
</a>
<button class="btn btn-default btn-xs" v-if="auth.delete" v-on:click="deletePathConfirm(f, $event)">
<span style="color:#CC3300" class="glyphicon glyphicon-trash"></span>
</button>
Expand Down Expand Up @@ -197,10 +200,26 @@ <h4 class="modal-title">
</div>
</div>
</div>
<!-- File info modal -->
<div id="file-info-modal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">
<span id="file-info-title"></span>
</h4>
</div>
<div class="modal-body">
<pre id="file-info-content"></pre>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div id="footer" class="pull-right" style="margin: 2em 1em">
<a href="https://github.com/codeskyblue/gohttpserver">gohttpserver (ver:{{version}})</a>, written by <a href="https://github.com/codeskyblue">codeskyblue</a>. 2016. go1.6
<a href="https://github.com/codeskyblue/gohttpserver">gohttpserver (ver:{{version}})</a>, written by <a href="https://github.com/codeskyblue">codeskyblue</a>. Copyright 2016-2017. go1.7
</div>
</div>
</div>
Expand All @@ -209,7 +228,7 @@ <h4 class="modal-title">
<script src="/-/res/js/jquery.scrollUp.min.js"></script>
<script src="/-/res/js/qrcode.js"></script>
<script src="/-/res/js/vue-1.0.min.js"></script>
<script src="/-/res/js/showdown-1.4.2.min.js"></script>
<script src="/-/res/js/showdown-1.6.4.min.js"></script>
<script src="/-/res/js/moment.min.js"></script>
<script src="/-/res/js/dropzone.js"></script>
<script src="/-/res/js/underscore-min.js"></script>
Expand Down
15 changes: 15 additions & 0 deletions res/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ var vm = new Vue({
tasklists: true,
ghCodeBlocks: true,
smoothLivePreview: true,
simplifiedAutoLink: true,
strikethrough: true,
});

var html = converter.makeHtml(res);
Expand Down Expand Up @@ -211,6 +213,19 @@ var vm = new Vue({
loadFileOrDir(reqPath);
e.preventDefault()
},
showInfo: function(f) {
console.log(f);
$.ajax({
url: pathJoin(["-/info", location.pathname, f.name]),
method: "GET",
success: function(res) {
$("#file-info-title").text(f.name);
$("#file-info-content").text(JSON.stringify(res, null, 4));
$("#file-info-modal").modal("show");
// console.log(JSON.stringify(res, null, 4));
}
})
},
deletePathConfirm: function(f, e) {
// confirm
e.preventDefault();
Expand Down
4 changes: 0 additions & 4 deletions res/js/showdown-1.4.2.min.js

This file was deleted.

5 changes: 5 additions & 0 deletions res/js/showdown-1.6.4.min.js

Large diffs are not rendered by default.

0 comments on commit e5677be

Please sign in to comment.