Skip to content

Commit

Permalink
refactor: add if and using variable that returns from the database
Browse files Browse the repository at this point in the history
  • Loading branch information
Caixetadev committed Jan 31, 2024
1 parent af22ce9 commit aa20f8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/handlers/docs/handleDocUpload.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ func HandleDocUpload(c *gin.Context) {
return
}

savedFileName := database.AddDoc(doc)
savedFileName, err := database.AddDoc(doc)
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
return
}

err = c.SaveUploadedFile(fileHeader, util.ExPath+"/uploads/docs/"+filteredFilename)
err = c.SaveUploadedFile(fileHeader, util.ExPath+"/uploads/docs/"+savedFileName)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High documentation

This path depends on a
user-provided value
.
if err != nil {
c.String(http.StatusInternalServerError, "Failed to save file: %s", err.Error())
return
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/image/handleImageUpload.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func HandleImageUpload(c *gin.Context) {
return
}

err = c.SaveUploadedFile(fileHeader, util.ExPath+"/uploads/images/"+filteredFilename)
err = c.SaveUploadedFile(fileHeader, util.ExPath+"/uploads/images/"+savedFilename)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
if err != nil {
c.String(http.StatusInternalServerError, "Failed to save file: %s", err.Error())
return
Expand Down

0 comments on commit aa20f8a

Please sign in to comment.