Skip to content

Commit

Permalink
Handle publish calls without uploaded file
Browse files Browse the repository at this point in the history
  • Loading branch information
anbsky committed Mar 24, 2021
1 parent d909efb commit 0553c71
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions app/publish/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@ func getCaller(sdkAddress, filename string, userID int, qCache cache.QueryCache)
// CanHandle checks if http.Request contains POSTed data in an accepted format.
// Supposed to be used in gorilla mux router MatcherFunc.
func (h Handler) CanHandle(r *http.Request, _ *mux.RouteMatch) bool {
_, _, err := r.FormFile(fileFieldName)
return !errors.Is(err, http.ErrMissingFile) && r.FormValue(jsonRPCFieldName) != ""
err := r.ParseMultipartForm(32 << 20)
if err != nil {
return false
}

return r.FormValue(jsonRPCFieldName) != ""
}

func (h Handler) saveFile(r *http.Request, userID int) (*os.File, error) {
Expand Down Expand Up @@ -223,17 +227,12 @@ func (h Handler) createFile(userID int, origFilename string) (*os.File, error) {
func (h Handler) fetchFile(r *http.Request, userID int) (*os.File, error) {
log := logger.WithFields(logrus.Fields{"user_id": userID, "method_handler": method})

err := r.ParseMultipartForm(32 << 20)
if err != nil {
return nil, err
}

url := r.Form.Get(remoteURLParam)
if url == "" {
return nil, ErrEmptyRemoteURL
}

r, err = http.NewRequest(http.MethodGet, url, nil)
r, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, werrors.Wrap(err, "error creating request")
}
Expand Down

0 comments on commit 0553c71

Please sign in to comment.