@@ -4,7 +4,7 @@ import (
|
||||
"code.cloudfoundry.org/bytefmt"
|
||||
"fmt"
|
||||
"github.com/emicklei/go-restful"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/errors"
|
||||
"kubesphere.io/kubesphere/pkg/models/devops"
|
||||
"kubesphere.io/kubesphere/pkg/utils/hashutil"
|
||||
@@ -17,38 +17,38 @@ func UploadS2iBinary(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
err := req.Request.ParseMultipartForm(bytefmt.MEGABYTE * 20)
|
||||
if err != nil {
|
||||
glog.Errorf("%+v", err)
|
||||
klog.Errorf("%+v", err)
|
||||
errors.ParseSvcErr(restful.NewError(http.StatusBadRequest, err.Error()), resp)
|
||||
return
|
||||
}
|
||||
if len(req.Request.MultipartForm.File) == 0 {
|
||||
err := restful.NewError(http.StatusBadRequest, "could not get file from form")
|
||||
glog.Errorf("%+v", err)
|
||||
klog.Errorf("%+v", err)
|
||||
errors.ParseSvcErr(restful.NewError(http.StatusBadRequest, err.Error()), resp)
|
||||
return
|
||||
}
|
||||
if len(req.Request.MultipartForm.File["s2ibinary"]) == 0 {
|
||||
err := restful.NewError(http.StatusBadRequest, "could not get file from form")
|
||||
glog.Errorf("%+v", err)
|
||||
klog.Errorf("%+v", err)
|
||||
errors.ParseSvcErr(err, resp)
|
||||
return
|
||||
}
|
||||
if len(req.Request.MultipartForm.File["s2ibinary"]) > 1 {
|
||||
err := restful.NewError(http.StatusBadRequest, "s2ibinary should only have one file")
|
||||
glog.Errorf("%+v", err)
|
||||
klog.Errorf("%+v", err)
|
||||
errors.ParseSvcErr(err, resp)
|
||||
return
|
||||
}
|
||||
defer req.Request.MultipartForm.RemoveAll()
|
||||
file, err := req.Request.MultipartForm.File["s2ibinary"][0].Open()
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
errors.ParseSvcErr(err, resp)
|
||||
return
|
||||
}
|
||||
filemd5, err := hashutil.GetMD5(file)
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
errors.ParseSvcErr(err, resp)
|
||||
return
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func UploadS2iBinary(req *restful.Request, resp *restful.Response) {
|
||||
if ok && len(req.Request.MultipartForm.Value["md5"]) > 0 {
|
||||
if md5[0] != filemd5 {
|
||||
err := restful.NewError(http.StatusBadRequest, fmt.Sprintf("md5 not match, origin: %+v, calculate: %+v", md5[0], filemd5))
|
||||
glog.Error(err)
|
||||
klog.Error(err)
|
||||
errors.ParseSvcErr(err, resp)
|
||||
return
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func UploadS2iBinary(req *restful.Request, resp *restful.Response) {
|
||||
|
||||
s2ibin, err := devops.UploadS2iBinary(ns, name, filemd5, req.Request.MultipartForm.File["s2ibinary"][0])
|
||||
if err != nil {
|
||||
glog.Errorf("%+v", err)
|
||||
klog.Errorf("%+v", err)
|
||||
errors.ParseSvcErr(err, resp)
|
||||
return
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func DownloadS2iBinary(req *restful.Request, resp *restful.Response) {
|
||||
fileName := req.PathParameter("file")
|
||||
url, err := devops.DownloadS2iBinary(ns, name, fileName)
|
||||
if err != nil {
|
||||
glog.Errorf("%+v", err)
|
||||
klog.Errorf("%+v", err)
|
||||
errors.ParseSvcErr(err, resp)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user