mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Add limit parameter and pagination for files
This commit is contained in:
parent
c63cebaee1
commit
af905a3ff7
|
@ -10,59 +10,66 @@ import (
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// listDirectoryHandler lists directories and folers under a directory
|
func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
|
||||||
// files are sorted by name and paginated via "lastFileName" and "limit".
|
|
||||||
// sub directories are listed on the first page, when "lastFileName"
|
|
||||||
// is empty.
|
|
||||||
func (fs *FilerServer) listDirectoryHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if !strings.HasSuffix(r.URL.Path, "/") {
|
if !strings.HasSuffix(r.URL.Path, "/") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dirlist, err := fs.filer.ListDirectories(r.URL.Path)
|
|
||||||
if err == leveldb.ErrNotFound {
|
if fs.disableDirListing {
|
||||||
glog.V(3).Infoln("Directory Not Found in db", r.URL.Path)
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
w.WriteHeader(http.StatusNotFound)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m := make(map[string]interface{})
|
|
||||||
m["Directory"] = r.URL.Path
|
|
||||||
lastFileName := r.FormValue("lastFileName")
|
|
||||||
if lastFileName == "" {
|
|
||||||
m["Subdirectories"] = dirlist
|
|
||||||
}
|
|
||||||
limit, limit_err := strconv.Atoi(r.FormValue("limit"))
|
limit, limit_err := strconv.Atoi(r.FormValue("limit"))
|
||||||
if limit_err != nil {
|
if limit_err != nil {
|
||||||
limit = 100
|
limit = 100
|
||||||
}
|
}
|
||||||
m["Files"], _ = fs.filer.ListFiles(r.URL.Path, lastFileName, limit)
|
|
||||||
writeJsonQuiet(w, r, http.StatusOK, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
|
lastFileName := r.FormValue("lastFileName")
|
||||||
fileLimit := 100
|
files, err := fs.filer.ListFiles(r.URL.Path, lastFileName, limit)
|
||||||
files, err := fs.filer.ListFiles(r.URL.Path, "", fileLimit)
|
|
||||||
|
|
||||||
if err == leveldb.ErrNotFound {
|
if err == leveldb.ErrNotFound {
|
||||||
glog.V(0).Infof("Error %s", err)
|
glog.V(0).Infof("Error %s", err)
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
directories, err2 := fs.filer.ListDirectories(r.URL.Path)
|
directories, err2 := fs.filer.ListDirectories(r.URL.Path)
|
||||||
if err2 == leveldb.ErrNotFound {
|
if err2 == leveldb.ErrNotFound {
|
||||||
glog.V(0).Infof("Error %s", err)
|
glog.V(0).Infof("Error %s", err)
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldDisplayLoadMore := len(files) > 0
|
||||||
|
|
||||||
|
lastFileName = ""
|
||||||
|
if len(files) > 0 {
|
||||||
|
lastFileName = files[len(files)-1].Name
|
||||||
|
|
||||||
|
files2, err3 := fs.filer.ListFiles(r.URL.Path, lastFileName, limit)
|
||||||
|
if err3 == leveldb.ErrNotFound {
|
||||||
|
glog.V(0).Infof("Error %s", err)
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
shouldDisplayLoadMore = len(files2) > 0
|
||||||
|
}
|
||||||
|
|
||||||
args := struct {
|
args := struct {
|
||||||
Path string
|
Path string
|
||||||
Files interface{}
|
Files interface{}
|
||||||
Directories interface{}
|
Directories interface{}
|
||||||
NotAllFilesDisplayed bool
|
Limit int
|
||||||
|
LastFileName string
|
||||||
|
ShouldDisplayLoadMore bool
|
||||||
}{
|
}{
|
||||||
r.URL.Path,
|
r.URL.Path,
|
||||||
files,
|
files,
|
||||||
directories,
|
directories,
|
||||||
len(files) == fileLimit,
|
limit,
|
||||||
|
lastFileName,
|
||||||
|
shouldDisplayLoadMore,
|
||||||
}
|
}
|
||||||
ui.StatusTpl.Execute(w, args)
|
ui.StatusTpl.Execute(w, args)
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,9 +42,11 @@ var StatusTpl = template.Must(template.New("status").Parse(`<!DOCTYPE html>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{if .NotAllFilesDisplayed}}
|
{{if .ShouldDisplayLoadMore}}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
Not all files are displayed.
|
<a href= {{ print .Path "?limit=" .Limit "&lastFileName=" .LastFileName}} >
|
||||||
|
Load more
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue