This repository was archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextra.go
79 lines (65 loc) · 2.35 KB
/
extra.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
package backend
import (
"bytes"
"fmt"
"io"
"mime/multipart"
)
// ResizeImage upload and resize and image based on the max width allowed.
// The input image must be a PNG or JPG and the end result will always be a JPG
func ResizeImage(token, filename string, file io.ReadSeeker, maxWidth float64) (StoreFileResult, error) {
var res StoreFileResult
// multipart form data
var buf bytes.Buffer
w := multipart.NewWriter(&buf)
fw, err := w.CreateFormFile("file", filename)
if err != nil {
return res, fmt.Errorf("error creating form field: %v", err)
}
if _, err := io.Copy(fw, file); err != nil {
return res, fmt.Errorf("error copying file data to form field: %v", err)
}
ww, err := w.CreateFormField("width")
if err != nil {
return res, fmt.Errorf("error creating the width field: %v", err)
}
if _, err := ww.Write([]byte(fmt.Sprintf("%f", maxWidth))); err != nil {
return res, fmt.Errorf("error writing the max width parameter: %v", err)
}
w.Close()
if err := request(token, "POST", "/extra/resizeimg", w.FormDataContentType(), &buf, &res); err != nil {
return res, fmt.Errorf("error while uploading file: %v", err)
}
return res, nil
}
type SMSData struct {
AccountSID string `json:"accountSID"` // Twilio account SID
AuthToken string `json:"authToken"` // Twilio authentication token
ToNumber string `json:"toNumber"` // Destination number
FromNumber string `json:"fromNumber"` // Twilio phone number
Body string `json:"body"` // text-message body
}
// SudoSendSMS sends a text message via the Twilio API. You need a valid Twilio
// AccountSID, AuthToken and phone number.
func SudoSendSMS(token string, data SMSData) error {
var status bool
if err := Post(token, "/extra/sms", data, &status); err != nil {
return err
}
return nil
}
// ConvertParam used for the ConvertURLToX request.
type ConvertParam struct {
// ToPDF indicates if the output is a PDF, otherwise a PNG
ToPDF bool `json:"toPDF"`
// URL a publicly available URL
URL string `json:"url"`
// FullPage indicates to PNG to screenshot the entire page (still not working)
FullPage bool `json:"fullpage"`
}
// ConvertURLToX converts a URL (web page) to either a PDF or a PNG. The ID and
// URL of the PDF or PNG is returned.
func ConvertURLToX(token string, data ConvertParam) (res StoreFileResult, err error) {
err = Post(token, "/extra/htmltox", data, &res)
return
}