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.

55 lines
1.7 KiB

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