-
Notifications
You must be signed in to change notification settings - Fork 2
/
files.pb.go
194 lines (179 loc) · 4.89 KB
/
files.pb.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Code generated by go-rest-client. DO NOT EDIT.
// source: files.proto
package kahla
import (
"bytes"
"encoding/json"
"io"
"mime/multipart"
"net/http"
"net/url"
"strconv"
"strings"
)
type Files_UploadIconRequest struct {
File multipart.File `json:"File,omitempty"`
Name string `json:"Name,omitempty"`
}
type Files_UploadIconResponse struct {
Code int32 `json:"code,omitempty"`
Message string `json:"message,omitempty"`
FileKey uint32 `json:"fileKey,omitempty"`
DownloadPath string `json:"downloadPath,omitempty"`
}
type Files_UploadMediaRequest struct {
File multipart.File `json:"File,omitempty"`
Name string `json:"Name,omitempty"`
}
type Files_UploadMediaResponse struct {
Code int32 `json:"code,omitempty"`
Message string `json:"message,omitempty"`
FileKey string `json:"FileKey,omitempty"`
DownloadPath string `json:"downloadPath,omitempty"`
}
type Files_UploadFileRequest struct {
ConversationId uint32 `json:"ConversationId,omitempty"`
File multipart.File `json:"File,omitempty"`
Name string `json:"Name,omitempty"`
}
type Files_UploadFileResponse struct {
Code int32 `json:"code,omitempty"`
Message string `json:"message,omitempty"`
SavedFileName string `json:"savedFileName,omitempty"`
FileKey uint32 `json:"fileKey,omitempty"`
FileSize uint64 `json:"fileSize,omitempty"`
}
type Files_FileDownloadAddressRequest struct {
FileKey uint32 `json:"FileKey,omitempty"`
}
type Files_FileDownloadAddressResponse struct {
Code int32 `json:"code,omitempty"`
Message string `json:"message,omitempty"`
FileName string `json:"fileName,omitempty"`
DownloadPath string `json:"downloadPath,omitempty"`
}
type FilesService struct {
client *http.Client
baseUrl string
}
func NewFilesService(client *http.Client, baseUrl string) *FilesService {
return &FilesService{
client: client,
baseUrl: baseUrl,
}
}
func (s *FilesService) UploadIcon(in *Files_UploadIconRequest) (out *Files_UploadIconResponse, resp *http.Response, err error) {
var b bytes.Buffer
w := multipart.NewWriter(&b)
file := in.File
writerFile, err := w.CreateFormFile("File", in.Name)
if err != nil {
return nil, nil, err
}
_, err = io.Copy(writerFile, file)
if err != nil {
return nil, nil, err
}
w.Close()
req, err := http.NewRequest("POST", s.baseUrl+"/Files/UploadIcon", &b)
if err != nil {
return
}
req.Header.Set("Content-Type", w.FormDataContentType())
resp, err = s.client.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
out = &Files_UploadIconResponse{}
err = json.NewDecoder(resp.Body).Decode(out)
if err != nil {
return
}
return
}
func (s *FilesService) UploadMedia(in *Files_UploadMediaRequest) (out *Files_UploadMediaResponse, resp *http.Response, err error) {
var b bytes.Buffer
w := multipart.NewWriter(&b)
file := in.File
writerFile, err := w.CreateFormFile("File", in.Name)
if err != nil {
return nil, nil, err
}
_, err = io.Copy(writerFile, file)
if err != nil {
return nil, nil, err
}
w.Close()
req, err := http.NewRequest("POST", s.baseUrl+"/Files/UploadMedia", &b)
if err != nil {
return
}
req.Header.Set("Content-Type", w.FormDataContentType())
resp, err = s.client.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
out = &Files_UploadMediaResponse{}
err = json.NewDecoder(resp.Body).Decode(out)
if err != nil {
return
}
return
}
func (s *FilesService) UploadFile(in *Files_UploadFileRequest) (out *Files_UploadFileResponse, resp *http.Response, err error) {
v := url.Values{}
v.Add("ConversationId", strconv.FormatUint(uint64(in.ConversationId), 10))
var b bytes.Buffer
w := multipart.NewWriter(&b)
if err != nil {
return nil, nil, err
}
file := in.File
writerFile, err := w.CreateFormFile("File", in.Name)
if err != nil {
return nil, nil, err
}
_, err = io.Copy(writerFile, file)
if err != nil {
return nil, nil, err
}
w.Close()
req, err := http.NewRequest("POST", s.baseUrl+"/Files/UploadFile?"+v.Encode(), &b)
if err != nil {
return
}
req.Header.Set("Content-Type", w.FormDataContentType())
resp, err = s.client.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
out = &Files_UploadFileResponse{}
err = json.NewDecoder(resp.Body).Decode(out)
if err != nil {
return
}
return
}
func (s *FilesService) FileDownloadAddress(in *Files_FileDownloadAddressRequest) (out *Files_FileDownloadAddressResponse, resp *http.Response, err error) {
v := url.Values{}
v.Add("FileKey", strconv.FormatUint(uint64(in.FileKey), 10))
req, err := http.NewRequest("POST", s.baseUrl+"/Files/FileDownloadAddress", strings.NewReader(v.Encode()))
if err != nil {
return
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err = s.client.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
out = &Files_FileDownloadAddressResponse{}
err = json.NewDecoder(resp.Body).Decode(out)
if err != nil {
return
}
return
}