SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
Add limit parameter and pagination for files
cschianoaf905a3ff719
diff --git a/weed/server/filer_server_handlers_read.go b/weed/server/filer_server_handlers_read.goindex 1470bcc48a..98ec13f959 100644--- a/weed/server/filer_server_handlers_read.go+++ b/weed/server/filer_server_handlers_read.go@@ -10,59 +10,66 @@ import ("github.com/syndtr/goleveldb/leveldb")-// listDirectoryHandler lists directories and folers under a directory-// 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) {+func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {if !strings.HasSuffix(r.URL.Path, "/") {return}- dirlist, err := fs.filer.ListDirectories(r.URL.Path)- if err == leveldb.ErrNotFound {- glog.V(3).Infoln("Directory Not Found in db", r.URL.Path)- w.WriteHeader(http.StatusNotFound)++ if fs.disableDirListing {+ w.WriteHeader(http.StatusMethodNotAllowed)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"))if limit_err != nil {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) {- fileLimit := 100- files, err := fs.filer.ListFiles(r.URL.Path, "", fileLimit)+ lastFileName := r.FormValue("lastFileName")+ files, err := fs.filer.ListFiles(r.URL.Path, lastFileName, limit)if err == leveldb.ErrNotFound {glog.V(0).Infof("Error %s", err)+ w.WriteHeader(http.StatusNotFound)return}directories, err2 := fs.filer.ListDirectories(r.URL.Path)if err2 == leveldb.ErrNotFound {glog.V(0).Infof("Error %s", err)+ w.WriteHeader(http.StatusNotFound)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 {- Path string- Files interface{}- Directories interface{}- NotAllFilesDisplayed bool+ Path string+ Files interface{}+ Directories interface{}+ Limit int+ LastFileName string+ ShouldDisplayLoadMore bool}{r.URL.Path,files,directories,- len(files) == fileLimit,+ limit,+ lastFileName,+ shouldDisplayLoadMore,}ui.StatusTpl.Execute(w, args)}diff --git a/weed/server/filer_ui/templates.go b/weed/server/filer_ui/templates.goindex b4d16d4db3..6f4f7ce868 100644--- a/weed/server/filer_ui/templates.go+++ b/weed/server/filer_ui/templates.go@@ -42,9 +42,11 @@ var StatusTpl = template.Must(template.New("status").Parse(`<!DOCTYPE html></ul></div>- {{if .NotAllFilesDisplayed}}+{{if .ShouldDisplayLoadMore}}<div class="row">- Not all files are displayed.+ <a href= {{ print .Path "?limit=" .Limit "&lastFileName=" .LastFileName}} >+ Load more+ </a></div>{{end}}</div>