add download count

This commit is contained in:
gzliuxin
2018-11-26 11:54:09 +08:00
parent 21ef8634cf
commit ffcf9cc742
4 changed files with 15 additions and 7 deletions

1
.gitignore vendored
View File

@@ -29,3 +29,4 @@ bindata_assetfs.go
assets_vfsdata.go
*.un~
*.swp
mydb.json

View File

@@ -129,7 +129,7 @@
<td style="text-align: left">
<template v-if="f.type == 'dir'">
<a class="btn btn-default btn-xs" href="/-/zip/{{f.path}}">
<span class="hidden-xs">Archive</span> Zip
<span class="hidden-xs">Archive</span> Zip({{f.dldcnt}})
<span class="glyphicon glyphicon-download-alt"></span>
</a>
<button class="btn btn-default btn-xs" v-if="auth.delete" v-on:click="deletePathConfirm(f, $event)">
@@ -138,7 +138,7 @@
</template>
<template v-if="f.type == 'file'">
<a class="btn btn-default btn-xs hidden-xs" href="/{{f.path}}?download=true">
<span class="hidden-xs">Download</span>
<span class="hidden-xs">Download({{f.dldcnt}})</span>
<span class="glyphicon glyphicon-download-alt"></span>
</a>
<button class="btn btn-default btn-xs bstooltip" data-trigger="manual" data-title="Copied!"

View File

@@ -50,12 +50,13 @@ type HTTPStaticServer struct {
PlistProxy string
GoogleTrackerID string
AuthType string
DBModel Model
indexes []IndexFileItem
m *mux.Router
}
func NewHTTPStaticServer(root string) *HTTPStaticServer {
func NewHTTPStaticServer(root string, dbmodel Model) *HTTPStaticServer {
if root == "" {
root = "./"
}
@@ -66,9 +67,10 @@ func NewHTTPStaticServer(root string) *HTTPStaticServer {
log.Printf("root path: %s\n", root)
m := mux.NewRouter()
s := &HTTPStaticServer{
Root: root,
Theme: "black",
m: m,
Root: root,
Theme: "black",
m: m,
DBModel: dbmodel,
}
go func() {
@@ -124,6 +126,7 @@ func (s *HTTPStaticServer) hIndex(w http.ResponseWriter, r *http.Request) {
}
if r.FormValue("download") == "true" {
w.Header().Set("Content-Disposition", "attachment; filename="+strconv.Quote(filepath.Base(path)))
s.DBModel.Incre(path)
}
http.ServeFile(w, r, relPath)
}
@@ -286,6 +289,7 @@ func (s *HTTPStaticServer) hInfo(w http.ResponseWriter, r *http.Request) {
func (s *HTTPStaticServer) hZip(w http.ResponseWriter, r *http.Request) {
path := mux.Vars(r)["path"]
s.DBModel.Incre(path)
CompressToZip(w, filepath.Join(s.Root, path))
}
@@ -407,6 +411,7 @@ type HTTPFileInfo struct {
Type string `json:"type"`
Size int64 `json:"size"`
ModTime int64 `json:"mtime"`
DldCnt int `json:"dldcnt"`
}
type AccessTable struct {
@@ -541,6 +546,7 @@ func (s *HTTPStaticServer) hJSONList(w http.ResponseWriter, r *http.Request) {
Name: info.Name(),
Path: path,
ModTime: info.ModTime().UnixNano() / 1e6,
DldCnt: (*s.DBModel.Data)[path],
}
if search != "" {
name, err := filepath.Rel(requestPath, path)

View File

@@ -144,7 +144,8 @@ func main() {
}
log.SetFlags(log.Lshortfile | log.LstdFlags)
ss := NewHTTPStaticServer(gcfg.Root)
DBModel.DBRead("mydb.json")
ss := NewHTTPStaticServer(gcfg.Root, DBModel)
ss.Theme = gcfg.Theme
ss.Title = gcfg.Title
ss.GoogleTrackerID = gcfg.GoogleTrackerID