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.

58 lines
1.9 KiB

7 years ago
7 years ago
  1. package weed_server
  2. import (
  3. "net/http"
  4. "github.com/chrislusf/seaweedfs/weed/filer2"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. "strconv"
  8. "time"
  9. "fmt"
  10. )
  11. func (fs *FilerServer) registerHandler(w http.ResponseWriter, r *http.Request) {
  12. path := r.FormValue("path")
  13. fileId := r.FormValue("fileId")
  14. fileSize, err := strconv.ParseUint(r.FormValue("fileSize"), 10, 64)
  15. if err != nil {
  16. glog.V(0).Infof("register %s to %s parse fileSize %s: %v", fileId, path, r.FormValue("fileSize"), err)
  17. writeJsonError(w, r, http.StatusInternalServerError, fmt.Errorf("parsing fileSize: %v", err))
  18. return
  19. }
  20. uid, err := strconv.ParseUint(r.FormValue("uid"), 10, 64)
  21. if err != nil && r.FormValue("uid") != "" {
  22. glog.V(0).Infof("register %s to %s parse uid %s: %v", fileId, path, r.FormValue("uid"), err)
  23. writeJsonError(w, r, http.StatusInternalServerError, fmt.Errorf("parsing uid: %v", err))
  24. return
  25. }
  26. gid, err := strconv.ParseUint(r.FormValue("gid"), 10, 64)
  27. if err != nil && r.FormValue("gid") != "" {
  28. glog.V(0).Infof("register %s to %s parse gid %s: %v", fileId, path, r.FormValue("gid"), err)
  29. writeJsonError(w, r, http.StatusInternalServerError, fmt.Errorf("parsing gid: %v", err))
  30. return
  31. }
  32. entry := &filer2.Entry{
  33. FullPath: filer2.FullPath(path),
  34. Attr: filer2.Attr{
  35. Mode: 0660,
  36. Crtime: time.Now(),
  37. Mtime: time.Now(),
  38. Uid: uint32(uid),
  39. Gid: uint32(gid),
  40. },
  41. Chunks: []*filer_pb.FileChunk{{
  42. FileId: fileId,
  43. Size: fileSize,
  44. Mtime: time.Now().UnixNano(),
  45. }},
  46. }
  47. glog.V(2).Infof("register %s to %s parse fileSize %s", fileId, path, r.FormValue("fileSize"))
  48. err = fs.filer.CreateEntry(entry)
  49. if err != nil {
  50. glog.V(0).Infof("register %s to %s error: %v", fileId, path, err)
  51. writeJsonError(w, r, http.StatusInternalServerError, fmt.Errorf("create %s: %v", path, err))
  52. } else {
  53. w.WriteHeader(http.StatusOK)
  54. }
  55. }