-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevelation.go
88 lines (71 loc) · 1.73 KB
/
revelation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/url"
"os"
"path"
"strings"
"github.com/atotto/clipboard"
)
var pasteURL = os.Getenv("PASTEBIN_URL")
var key = os.Getenv("AUTH_KEY")
var authParam = os.Getenv("AUTH_PARAM")
func main() {
if pasteURL == "" {
fmt.Println("Please set PASTEBIN_URL environment variable")
return
}
file := strings.Split(SelectFile(), "file://")[1]
output, _ := url.QueryUnescape(file)
request, err := uploadFile(output)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
client := &http.Client{}
res, err := client.Do(request)
if err != nil {
fmt.Println("Error executing request:", err)
return
}
defer res.Body.Close()
respBody, _ := io.ReadAll(res.Body)
if err := clipboard.WriteAll(string(respBody)); err != nil {
panic(err)
}
}
func uploadFile(file string) (*http.Request, error) {
// open the file
body, err := os.Open(file)
if err != nil {
return nil, fmt.Errorf("failed to open file: %v", err)
}
defer body.Close()
// prepare multipart form data
data := &bytes.Buffer{}
writer := multipart.NewWriter(data)
// create the form file part
part, err := writer.CreateFormFile("file", path.Base(file))
if err != nil {
return nil, fmt.Errorf("error creating form file: %v", err)
}
// copy file content to form data
_, err = io.Copy(part, body)
if err != nil {
return nil, fmt.Errorf("error copying file content: %v", err)
}
writer.Close()
// create the HTTP request
req, err := http.NewRequest("POST", pasteURL, data)
if err != nil {
return nil, fmt.Errorf("error creating request: %v", err)
}
// set headers
req.Header.Set(authParam, key)
req.Header.Set("Content-Type", writer.FormDataContentType())
return req, nil
}