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.

36 lines
992 B

  1. package weed_server
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "github.com/chrislusf/seaweedfs/weed/filer"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. )
  8. func (fs *FilerServer) apiHandler(w http.ResponseWriter, r *http.Request) {
  9. request := r.FormValue("request")
  10. apiRequest := filer.ApiRequest{}
  11. err := json.Unmarshal([]byte(request), &apiRequest)
  12. if err != nil {
  13. glog.V(0).Infoln("failing to read request", r.RequestURI, request)
  14. writeJsonError(w, r, http.StatusInternalServerError, err)
  15. }
  16. switch apiRequest.Command {
  17. case "listDirectories":
  18. res := filer.ListDirectoriesResult{}
  19. res.Directories, err = fs.filer.ListDirectories(apiRequest.Directory)
  20. if err != nil {
  21. res.Error = err.Error()
  22. }
  23. writeJsonQuiet(w, r, http.StatusOK, res)
  24. case "listFiles":
  25. res := filer.ListFilesResult{}
  26. res.Files, err = fs.filer.ListFiles(apiRequest.Directory, apiRequest.FileName, 100)
  27. if err != nil {
  28. res.Error = err.Error()
  29. }
  30. writeJsonQuiet(w, r, http.StatusOK, res)
  31. }
  32. }