forked from ProtonMail/go-proton-api
-
Notifications
You must be signed in to change notification settings - Fork 4
/
manager_report_types.go
103 lines (79 loc) · 1.54 KB
/
manager_report_types.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package proton
import (
"encoding/json"
"fmt"
"github.com/ProtonMail/gluon/rfc822"
)
type ClientType int
const (
ClientTypeEmail ClientType = iota + 1
ClientTypeVPN
ClientTypeCalendar
ClientTypeDrive
)
type AttachmentType int
const (
AttachmentTypeSync AttachmentType = iota
AttachmentTypeAsync
)
type ReportBugReq struct {
OS string
OSVersion string
Browser string
BrowserVersion string
BrowserExtensions string
Resolution string
DisplayMode string
Client string
ClientVersion string
ClientType ClientType
Title string
Description string
Username string
Email string
Country string
ISP string
AsyncAttachments AttachmentType
}
type ReportBugAttachmentReq struct {
Product ClientType
Body string
Token string
}
type ReportBugRes struct {
APIError
Token *string
}
func (req ReportBugReq) toFormData() map[string]string {
b, err := json.Marshal(req)
if err != nil {
panic(err)
}
return bytesToFormData(b)
}
func (req ReportBugAttachmentReq) toFormData() map[string]string {
b, err := json.Marshal(req)
if err != nil {
panic(err)
}
return bytesToFormData(b)
}
func bytesToFormData(buff []byte) map[string]string {
var raw map[string]any
if err := json.Unmarshal(buff, &raw); err != nil {
panic(err)
}
res := make(map[string]string)
for key := range raw {
if val := fmt.Sprint(raw[key]); val != "" {
res[key] = val
}
}
return res
}
type ReportBugAttachment struct {
Name string
Filename string
MIMEType rfc822.MIMEType
Body []byte
}