mirror of
https://github.com/chrislusf/seaweedfs
synced 2024-09-18 15:00:53 +02:00
remove unused code
This commit is contained in:
parent
702d7ac424
commit
12e6ccc581
|
@ -109,15 +109,6 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
var path string
|
|
||||||
if strings.HasPrefix(r.Header.Get("Content-Type"), "multipart/form-data; boundary=") {
|
|
||||||
path, err = fs.multipartUploadAnalyzer(w, r, replication, collection, dataCenter)
|
|
||||||
} else {
|
|
||||||
path, err = fs.monolithicUploadAnalyzer(w, r, replication, collection, dataCenter)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
fileId, urlLocation, err := fs.queryFileInfoByPath(w, r, r.URL.Path)
|
fileId, urlLocation, err := fs.queryFileInfoByPath(w, r, r.URL.Path)
|
||||||
if err == nil && fileId == "" {
|
if err == nil && fileId == "" {
|
||||||
fileId, urlLocation, err = fs.assignNewFileInfo(w, r, replication, collection, dataCenter)
|
fileId, urlLocation, err = fs.assignNewFileInfo(w, r, replication, collection, dataCenter)
|
||||||
|
@ -140,6 +131,7 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
glog.V(4).Infoln("post to", u)
|
glog.V(4).Infoln("post to", u)
|
||||||
|
|
||||||
|
// send request to volume server
|
||||||
request := &http.Request{
|
request := &http.Request{
|
||||||
Method: r.Method,
|
Method: r.Method,
|
||||||
URL: u,
|
URL: u,
|
||||||
|
@ -177,6 +169,8 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
writeJsonError(w, r, http.StatusInternalServerError, errors.New(ret.Error))
|
writeJsonError(w, r, http.StatusInternalServerError, errors.New(ret.Error))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// find correct final path
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
if strings.HasSuffix(path, "/") {
|
if strings.HasSuffix(path, "/") {
|
||||||
if ret.Name != "" {
|
if ret.Name != "" {
|
||||||
|
@ -190,6 +184,7 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update metadata in filer store
|
||||||
glog.V(4).Infoln("saving", path, "=>", fileId)
|
glog.V(4).Infoln("saving", path, "=>", fileId)
|
||||||
entry := &filer2.Entry{
|
entry := &filer2.Entry{
|
||||||
FullPath: filer2.FullPath(path),
|
FullPath: filer2.FullPath(path),
|
||||||
|
@ -216,6 +211,7 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send back post result
|
||||||
reply := FilerPostResult{
|
reply := FilerPostResult{
|
||||||
Name: ret.Name,
|
Name: ret.Name,
|
||||||
Size: ret.Size,
|
Size: ret.Size,
|
||||||
|
|
|
@ -1,127 +0,0 @@
|
||||||
package weed_server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"crypto/md5"
|
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"mime/multipart"
|
|
||||||
"net/http"
|
|
||||||
"net/textproto"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
||||||
)
|
|
||||||
|
|
||||||
var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")
|
|
||||||
|
|
||||||
func escapeQuotes(s string) string {
|
|
||||||
return quoteEscaper.Replace(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func createFormFile(writer *multipart.Writer, fieldname, filename, mime string) (io.Writer, error) {
|
|
||||||
h := make(textproto.MIMEHeader)
|
|
||||||
h.Set("Content-Disposition",
|
|
||||||
fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
|
|
||||||
escapeQuotes(fieldname), escapeQuotes(filename)))
|
|
||||||
if len(mime) == 0 {
|
|
||||||
mime = "application/octet-stream"
|
|
||||||
}
|
|
||||||
h.Set("Content-Type", mime)
|
|
||||||
return writer.CreatePart(h)
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeFormData(filename, mimeType string, content io.Reader) (formData io.Reader, contentType string, err error) {
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
writer := multipart.NewWriter(buf)
|
|
||||||
defer writer.Close()
|
|
||||||
|
|
||||||
part, err := createFormFile(writer, "file", filename, mimeType)
|
|
||||||
if err != nil {
|
|
||||||
glog.V(0).Infoln(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = io.Copy(part, content)
|
|
||||||
if err != nil {
|
|
||||||
glog.V(0).Infoln(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
formData = buf
|
|
||||||
contentType = writer.FormDataContentType()
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkContentMD5(w http.ResponseWriter, r *http.Request) (err error) {
|
|
||||||
if contentMD5 := r.Header.Get("Content-MD5"); contentMD5 != "" {
|
|
||||||
buf, _ := ioutil.ReadAll(r.Body)
|
|
||||||
//checkMD5
|
|
||||||
sum := md5.Sum(buf)
|
|
||||||
fileDataMD5 := base64.StdEncoding.EncodeToString(sum[0:len(sum)])
|
|
||||||
if strings.ToLower(fileDataMD5) != strings.ToLower(contentMD5) {
|
|
||||||
glog.V(0).Infof("fileDataMD5 [%s] is not equal to Content-MD5 [%s]", fileDataMD5, contentMD5)
|
|
||||||
err = fmt.Errorf("MD5 check failed")
|
|
||||||
writeJsonError(w, r, http.StatusNotAcceptable, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//reconstruct http request body for following new request to volume server
|
|
||||||
r.Body = ioutil.NopCloser(bytes.NewBuffer(buf))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fs *FilerServer) monolithicUploadAnalyzer(w http.ResponseWriter, r *http.Request, replication, collection string, dataCenter string) (path string, err error) {
|
|
||||||
|
|
||||||
lastPos := strings.LastIndex(r.URL.Path, "/")
|
|
||||||
if lastPos == -1 || lastPos == 0 || lastPos == len(r.URL.Path)-1 {
|
|
||||||
glog.V(0).Infof("URL Path [%s] is invalid, could not retrieve file name", r.URL.Path)
|
|
||||||
err = fmt.Errorf("URL Path is invalid")
|
|
||||||
writeJsonError(w, r, http.StatusInternalServerError, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = checkContentMD5(w, r); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fileName := r.URL.Path[lastPos+1:]
|
|
||||||
if err = multipartHttpBodyBuilder(w, r, fileName); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
path = r.URL.Path
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func multipartHttpBodyBuilder(w http.ResponseWriter, r *http.Request, fileName string) (err error) {
|
|
||||||
body, contentType, te := makeFormData(fileName, r.Header.Get("Content-Type"), r.Body)
|
|
||||||
if te != nil {
|
|
||||||
glog.V(0).Infoln("S3 protocol to raw seaweed protocol failed", te.Error())
|
|
||||||
writeJsonError(w, r, http.StatusInternalServerError, te)
|
|
||||||
err = te
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if body != nil {
|
|
||||||
switch v := body.(type) {
|
|
||||||
case *bytes.Buffer:
|
|
||||||
r.ContentLength = int64(v.Len())
|
|
||||||
case *bytes.Reader:
|
|
||||||
r.ContentLength = int64(v.Len())
|
|
||||||
case *strings.Reader:
|
|
||||||
r.ContentLength = int64(v.Len())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
r.Header.Set("Content-Type", contentType)
|
|
||||||
rc, ok := body.(io.ReadCloser)
|
|
||||||
if !ok && body != nil {
|
|
||||||
rc = ioutil.NopCloser(body)
|
|
||||||
}
|
|
||||||
r.Body = rc
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
package weed_server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (fs *FilerServer) multipartUploadAnalyzer(w http.ResponseWriter, r *http.Request, replication, collection string, dataCenter string) (path string, err error) {
|
|
||||||
//Default handle way for http multipart
|
|
||||||
if r.Method == "PUT" {
|
|
||||||
path = r.URL.Path
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
Loading…
Reference in a new issue