Skip to content

Commit

Permalink
Prevent crashing if litterbox is dead or timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Arno500 committed Jun 10, 2024
1 parent 8158e9f commit 9a7e125
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion discord/file-hosting.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
func UploadImage(image []byte, imageName string) (string, error) {

reader, mpForm := createMultipartForm("", image, imageName)
defer reader.Close()

req, err := http.NewRequest(http.MethodPost, "https://litterbox.catbox.moe/resources/internals/api.php", reader)
if err != nil {
Expand Down Expand Up @@ -44,7 +45,10 @@ func createMultipartForm(expiration string, image []byte, imageName string) (*io
m.WriteField("time", "12h")
}

formFile, _ := m.CreateFormFile("fileToUpload", path.Base(imageName))
formFile, err := m.CreateFormFile("fileToUpload", path.Base(imageName))
if err != nil {
return
}
if _, err := io.Copy(formFile, bytes.NewBuffer(image)); err != nil {
return
}
Expand Down

0 comments on commit 9a7e125

Please sign in to comment.