You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.8 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package weed_server
  2. import (
  3. "net/http"
  4. "strconv"
  5. "strings"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. ui "github.com/chrislusf/seaweedfs/weed/server/filer_ui"
  8. "github.com/syndtr/goleveldb/leveldb"
  9. )
  10. // listDirectoryHandler lists directories and folers under a directory
  11. // files are sorted by name and paginated via "lastFileName" and "limit".
  12. // sub directories are listed on the first page, when "lastFileName"
  13. // is empty.
  14. func (fs *FilerServer) listDirectoryHandler(w http.ResponseWriter, r *http.Request) {
  15. if !strings.HasSuffix(r.URL.Path, "/") {
  16. return
  17. }
  18. dirlist, err := fs.filer.ListDirectories(r.URL.Path)
  19. if err == leveldb.ErrNotFound {
  20. glog.V(3).Infoln("Directory Not Found in db", r.URL.Path)
  21. w.WriteHeader(http.StatusNotFound)
  22. return
  23. }
  24. m := make(map[string]interface{})
  25. m["Directory"] = r.URL.Path
  26. lastFileName := r.FormValue("lastFileName")
  27. if lastFileName == "" {
  28. m["Subdirectories"] = dirlist
  29. }
  30. limit, limit_err := strconv.Atoi(r.FormValue("limit"))
  31. if limit_err != nil {
  32. limit = 100
  33. }
  34. m["Files"], _ = fs.filer.ListFiles(r.URL.Path, lastFileName, limit)
  35. writeJsonQuiet(w, r, http.StatusOK, m)
  36. }
  37. func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
  38. fileLimit := 100
  39. files, err := fs.filer.ListFiles(r.URL.Path, "", fileLimit)
  40. if err == leveldb.ErrNotFound {
  41. glog.V(0).Infof("Error %s", err)
  42. return
  43. }
  44. directories, err2 := fs.filer.ListDirectories(r.URL.Path)
  45. if err2 == leveldb.ErrNotFound {
  46. glog.V(0).Infof("Error %s", err)
  47. return
  48. }
  49. args := struct {
  50. Path string
  51. Files interface{}
  52. Directories interface{}
  53. NotAllFilesDisplayed bool
  54. }{
  55. r.URL.Path,
  56. files,
  57. directories,
  58. len(files) == fileLimit,
  59. }
  60. ui.StatusTpl.Execute(w, args)
  61. }