2014-07-21 06:12:49 +00:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2014-10-26 18:34:55 +00:00
|
|
|
|
2016-06-03 01:09:14 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2018-05-14 06:56:16 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
|
|
|
"strconv"
|
2018-05-16 07:08:44 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2018-05-16 07:54:44 +00:00
|
|
|
"time"
|
2014-07-21 06:12:49 +00:00
|
|
|
)
|
|
|
|
|
2016-07-21 06:45:55 +00:00
|
|
|
func (fs *FilerServer) registerHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
path := r.FormValue("path")
|
|
|
|
fileId := r.FormValue("fileId")
|
2018-05-14 06:56:16 +00:00
|
|
|
fileSize, err := strconv.ParseUint(r.FormValue("fileSize"), 10, 64)
|
|
|
|
if err != nil {
|
2018-05-19 19:07:15 +00:00
|
|
|
glog.V(0).Infof("register %s to %s parse fileSize %s: %v", fileId, path, r.FormValue("fileSize"), err)
|
2018-05-14 06:56:16 +00:00
|
|
|
writeJsonError(w, r, http.StatusInternalServerError, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
entry := &filer2.Entry{
|
|
|
|
FullPath: filer2.FullPath(path),
|
|
|
|
Attr: filer2.Attr{
|
|
|
|
Mode: 0660,
|
|
|
|
},
|
2018-05-16 07:08:44 +00:00
|
|
|
Chunks: []*filer_pb.FileChunk{{
|
|
|
|
FileId: fileId,
|
|
|
|
Size: fileSize,
|
2018-05-16 07:54:44 +00:00
|
|
|
Mtime: time.Now().UnixNano(),
|
2018-05-14 06:56:16 +00:00
|
|
|
}},
|
|
|
|
}
|
2018-05-19 19:07:15 +00:00
|
|
|
glog.V(2).Infof("register %s to %s parse fileSize %s", fileId, path, r.FormValue("fileSize"))
|
2018-05-14 06:56:16 +00:00
|
|
|
err = fs.filer.CreateEntry(entry)
|
2016-07-21 06:45:55 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.V(4).Infof("register %s to %s error: %v", fileId, path, err)
|
|
|
|
writeJsonError(w, r, http.StatusInternalServerError, err)
|
|
|
|
} else {
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
}
|
|
|
|
}
|