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.

57 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. Crtime: time.Now(),
  36. Mtime: time.Now(),
  37. Uid: uint32(uid),
  38. Gid: uint32(gid),
  39. },
  40. Chunks: []*filer_pb.FileChunk{{
  41. FileId: fileId,
  42. Size: fileSize,
  43. Mtime: time.Now().UnixNano(),
  44. }},
  45. }
  46. glog.V(2).Infof("register %s to %s parse fileSize %s", fileId, path, r.FormValue("fileSize"))
  47. err = fs.filer.CreateEntry(entry)
  48. if err != nil {
  49. glog.V(4).Infof("register %s to %s error: %v", fileId, path, err)
  50. writeJsonError(w, r, http.StatusInternalServerError, err)
  51. } else {
  52. w.WriteHeader(http.StatusOK)
  53. }
  54. }