sparklxb
8 years ago
3 changed files with 81 additions and 24 deletions
-
64weed/command/mount_std.go
-
1weed/server/filer_server.go
-
40weed/server/filer_server_handlers_api.go
@ -0,0 +1,40 @@ |
|||
package weed_server |
|||
|
|||
import ( |
|||
"encoding/json" |
|||
"net/http" |
|||
|
|||
"github.com/chrislusf/seaweedfs/weed/filer" |
|||
"github.com/chrislusf/seaweedfs/weed/glog" |
|||
) |
|||
|
|||
func (fs *FilerServer) apiHandler(w http.ResponseWriter, r *http.Request) { |
|||
request := r.FormValue("request") |
|||
apiRequest := filer.ApiRequest{} |
|||
|
|||
err := json.Unmarshal([]byte(request), &apiRequest) |
|||
if err != nil { |
|||
glog.V(0).Infoln("failing to read request", r.RequestURI, request) |
|||
writeJsonError(w, r, http.StatusInternalServerError, err) |
|||
} |
|||
switch apiRequest.Command { |
|||
case "listDirectories": |
|||
res := filer.ListDirectoriesResult{} |
|||
res.Directories, err = fs.filer.ListDirectories(apiRequest.Directory) |
|||
if err != nil { |
|||
res.Error = err.Error() |
|||
} |
|||
writeJsonQuiet(w, r, http.StatusOK, res) |
|||
case "listFiles": |
|||
res := filer.ListFilesResult{} |
|||
limit := 1 |
|||
if len(apiRequest.FileName) == 0 { |
|||
limit = 100 |
|||
} |
|||
res.Files, err = fs.filer.ListFiles(apiRequest.Directory, apiRequest.FileName, limit) |
|||
if err != nil { |
|||
res.Error = err.Error() |
|||
} |
|||
writeJsonQuiet(w, r, http.StatusOK, res) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue