Skip to content

Commit

Permalink
Update wings diagnostics for new pastebin
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkubi committed May 14, 2024
1 parent 4ceaf34 commit 86fb2c5
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions cmd/diagnostics.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package cmd

import (
"bytes"
"context"
"errors"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/url"
"os/exec"
Expand All @@ -29,7 +31,7 @@ import (
)

const (
DefaultHastebinUrl = "https://peli.cc"
DefaultHastebinUrl = "https://paste.pelistuff.com"
DefaultLogLines = 200
)

Expand Down Expand Up @@ -223,15 +225,22 @@ func getDockerInfo() (types.Version, types.Info, error) {
}

func uploadToHastebin(hbUrl, content string) (string, error) {
r := strings.NewReader(content)
u, err := url.Parse(hbUrl)
if err != nil {
return "", err
}
u.Path = path.Join(u.Path, "documents")
res, err := http.Post(u.String(), "plain/text", r)

formData := new(bytes.Buffer)
formWriter := multipart.NewWriter(formData)
formWriter.WriteField("c", content)
formWriter.WriteField("e", "14d")
formWriter.Close()

res, err := http.Post(u.String(), formWriter.FormDataContentType(), formData)
if err != nil || res.StatusCode != 200 {
fmt.Println("Failed to upload report to ", u.String(), err)
fmt.Println("Failed to upload report to ", u.String(), err, res.StatusCode)
myb, _ := io.ReadAll(res.Body)
fmt.Println(string(myb))
return "", err
}
pres := make(map[string]interface{})
Expand All @@ -241,10 +250,8 @@ func uploadToHastebin(hbUrl, content string) (string, error) {
return "", err
}
json.Unmarshal(body, &pres)
if key, ok := pres["key"].(string); ok {
u, _ := url.Parse(hbUrl)
u.Path = path.Join(u.Path, key)
return u.String(), nil
if pasteUrl, ok := pres["url"].(string); ok {
return pasteUrl, nil
}
return "", errors.New("failed to find key in response")
}
Expand Down

0 comments on commit 86fb2c5

Please sign in to comment.