-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticle.api.go
440 lines (391 loc) · 13.9 KB
/
article.api.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
// Code generated by protoc-gen-go_api(github.com/dev-openapi/protoc-gen-go_api version=v1.0.5). DO NOT EDIT.
// source: bilibili-webapp/article.proto
package bilibili_webapp
import (
context "context"
fmt "fmt"
io "io"
json "encoding/json"
bytes "bytes"
http "net/http"
strings "strings"
url "net/url"
multipart "mime/multipart"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = context.Background
var _ = http.NewRequest
var _ = io.Copy
var _ = bytes.Compare
var _ = json.Marshal
var _ = strings.Compare
var _ = fmt.Errorf
var _ = url.Parse
var _ = multipart.ErrMessageTooLarge
// Client API for Article service
type ArticleService interface {
// AddArticle 文章提交 https://openhome.bilibili.com/doc/4/b14b77b6-8889-8c8b-2e83-17c5a4c550fb
AddArticle(ctx context.Context, in *AddArticleReq, opts ...Option) (*AddArticleRes, error)
// EditArticle 文章编辑 https://openhome.bilibili.com/doc/4/2b5284bd-9a40-247b-8da6-0ef7cd00afd3
EditArticle(ctx context.Context, in *EditArticleReq, opts ...Option) (*EditArticleRes, error)
// DeleteArticle 文章删除 https://openhome.bilibili.com/doc/4/b63f8918-2add-0fbb-0718-d0537329ed1c
DeleteArticle(ctx context.Context, in *DeleteArticleReq, opts ...Option) (*DeleteArticleRes, error)
// GetArticleDetail 查看文章详情 https://openhome.bilibili.com/doc/4/243457f6-9d44-9348-06ef-366cdbb44eb4
GetArticleDetail(ctx context.Context, in *GetArticleDetailReq, opts ...Option) (*GetArticleDetailRes, error)
// BatchGetArticles 查询文章列表 https://openhome.bilibili.com/doc/4/c8057666-2b92-fc72-3607-f4199933dc13
BatchGetArticles(ctx context.Context, in *BatchGetArticlesReq, opts ...Option) (*BatchGetArticlesRes, error)
// GetArticleCategories 获取文章的分类列表 https://openhome.bilibili.com/doc/4/120b97a6-24a1-4e9f-47b7-9a201196e5d3
GetArticleCategories(ctx context.Context, in *GetArticleCategoriesReq, opts ...Option) (*GetArticleCategoriesRes, error)
// GetArticleCard 获取视频、文章卡片信息 https://openhome.bilibili.com/doc/4/225be808-a81a-cd82-7703-1bbd601e243d
GetArticleCard(ctx context.Context, in *GetArticleCardReq, opts ...Option) (*GetArticleCardRes, error)
}
type articleService struct {
// opts
opts *Options
}
func NewArticleService(opts ...Option) ArticleService {
opt := newOptions(opts...)
if len(opt.addr) <= 0 {
opt.addr = "https://member.bilibili.com"
}
return &articleService {
opts: opt,
}
}
func (c *articleService) AddArticle(ctx context.Context, in *AddArticleReq, opts ...Option) (*AddArticleRes, error) {
var res AddArticleRes
// options
opt := buildOptions(c.opts, opts...)
headers := make(map[string]string)
// route
rawURL := fmt.Sprintf("%s/arcopen/fn/article/add", opt.addr)
// body
bodyForms := url.Values{}
if in.GetBody() != nil && in.GetBody().GetBannerUrl() != "" {
bodyForms.Add("banner_url", fmt.Sprintf("%v", in.GetBody().GetBannerUrl()))
}
if in.GetBody() != nil && in.GetBody().GetCategory() != 0 {
bodyForms.Add("category", fmt.Sprintf("%v", in.GetBody().GetCategory()))
}
if in.GetBody() != nil && in.GetBody().GetContent() != "" {
bodyForms.Add("content", fmt.Sprintf("%v", in.GetBody().GetContent()))
}
if in.GetBody() != nil && in.GetBody().GetId() != 0 {
bodyForms.Add("id", fmt.Sprintf("%v", in.GetBody().GetId()))
}
if in.GetBody() != nil && in.GetBody().GetImageUrls() != "" {
bodyForms.Add("image_urls", fmt.Sprintf("%v", in.GetBody().GetImageUrls()))
}
if in.GetBody() != nil && in.GetBody().GetListId() != 0 {
bodyForms.Add("list_id", fmt.Sprintf("%v", in.GetBody().GetListId()))
}
if in.GetBody() != nil && in.GetBody().GetOriginal() != 0 {
bodyForms.Add("original", fmt.Sprintf("%v", in.GetBody().GetOriginal()))
}
if in.GetBody() != nil && in.GetBody().GetSummary() != "" {
bodyForms.Add("summary", fmt.Sprintf("%v", in.GetBody().GetSummary()))
}
if in.GetBody() != nil && in.GetBody().GetTags() != "" {
bodyForms.Add("tags", fmt.Sprintf("%v", in.GetBody().GetTags()))
}
if in.GetBody() != nil && in.GetBody().GetTemplateId() != 0 {
bodyForms.Add("template_id", fmt.Sprintf("%v", in.GetBody().GetTemplateId()))
}
if in.GetBody() != nil && in.GetBody().GetTitle() != "" {
bodyForms.Add("title", fmt.Sprintf("%v", in.GetBody().GetTitle()))
}
if in.GetBody() != nil && in.GetBody().GetTopVideoBvid() != "" {
bodyForms.Add("top_video_bvid", fmt.Sprintf("%v", in.GetBody().GetTopVideoBvid()))
}
if in.GetBody() != nil && in.GetBody().GetUpClosedReply() != 0 {
bodyForms.Add("up_closed_reply", fmt.Sprintf("%v", in.GetBody().GetUpClosedReply()))
}
body := strings.NewReader(bodyForms.Encode())
headers["Content-Type"] = "application/x-www-form-urlencoded"
req, err := http.NewRequest("POST", rawURL, body)
if err != nil {
return nil, err
}
params := req.URL.Query()
if in.GetAccessToken() != "" {
params.Add("access_token", fmt.Sprintf("%v", in.GetAccessToken()))
}
if in.GetClientId() != "" {
params.Add("client_id", fmt.Sprintf("%v", in.GetClientId()))
}
req.URL.RawQuery = params.Encode()
// header
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := opt.DoRequest(ctx, opt.client, req)
if err != nil {
return nil, err
}
err = opt.DoResponse(ctx, resp, &res)
return &res, err
}
func (c *articleService) EditArticle(ctx context.Context, in *EditArticleReq, opts ...Option) (*EditArticleRes, error) {
var res EditArticleRes
// options
opt := buildOptions(c.opts, opts...)
headers := make(map[string]string)
// route
rawURL := fmt.Sprintf("%s/arcopen/fn/article/edit", opt.addr)
// body
bodyForms := url.Values{}
if in.GetBody() != nil && in.GetBody().GetBannerUrl() != "" {
bodyForms.Add("banner_url", fmt.Sprintf("%v", in.GetBody().GetBannerUrl()))
}
if in.GetBody() != nil && in.GetBody().GetCategory() != 0 {
bodyForms.Add("category", fmt.Sprintf("%v", in.GetBody().GetCategory()))
}
if in.GetBody() != nil && in.GetBody().GetContent() != "" {
bodyForms.Add("content", fmt.Sprintf("%v", in.GetBody().GetContent()))
}
if in.GetBody() != nil && in.GetBody().GetId() != 0 {
bodyForms.Add("id", fmt.Sprintf("%v", in.GetBody().GetId()))
}
if in.GetBody() != nil && in.GetBody().GetImageUrls() != "" {
bodyForms.Add("image_urls", fmt.Sprintf("%v", in.GetBody().GetImageUrls()))
}
if in.GetBody() != nil && in.GetBody().GetListId() != 0 {
bodyForms.Add("list_id", fmt.Sprintf("%v", in.GetBody().GetListId()))
}
if in.GetBody() != nil && in.GetBody().GetOriginal() != 0 {
bodyForms.Add("original", fmt.Sprintf("%v", in.GetBody().GetOriginal()))
}
if in.GetBody() != nil && in.GetBody().GetSummary() != "" {
bodyForms.Add("summary", fmt.Sprintf("%v", in.GetBody().GetSummary()))
}
if in.GetBody() != nil && in.GetBody().GetTags() != "" {
bodyForms.Add("tags", fmt.Sprintf("%v", in.GetBody().GetTags()))
}
if in.GetBody() != nil && in.GetBody().GetTemplateId() != 0 {
bodyForms.Add("template_id", fmt.Sprintf("%v", in.GetBody().GetTemplateId()))
}
if in.GetBody() != nil && in.GetBody().GetTitle() != "" {
bodyForms.Add("title", fmt.Sprintf("%v", in.GetBody().GetTitle()))
}
if in.GetBody() != nil && in.GetBody().GetTopVideoBvid() != "" {
bodyForms.Add("top_video_bvid", fmt.Sprintf("%v", in.GetBody().GetTopVideoBvid()))
}
if in.GetBody() != nil && in.GetBody().GetUpClosedReply() != 0 {
bodyForms.Add("up_closed_reply", fmt.Sprintf("%v", in.GetBody().GetUpClosedReply()))
}
body := strings.NewReader(bodyForms.Encode())
headers["Content-Type"] = "application/x-www-form-urlencoded"
req, err := http.NewRequest("POST", rawURL, body)
if err != nil {
return nil, err
}
params := req.URL.Query()
if in.GetAccessToken() != "" {
params.Add("access_token", fmt.Sprintf("%v", in.GetAccessToken()))
}
if in.GetClientId() != "" {
params.Add("client_id", fmt.Sprintf("%v", in.GetClientId()))
}
req.URL.RawQuery = params.Encode()
// header
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := opt.DoRequest(ctx, opt.client, req)
if err != nil {
return nil, err
}
err = opt.DoResponse(ctx, resp, &res)
return &res, err
}
func (c *articleService) DeleteArticle(ctx context.Context, in *DeleteArticleReq, opts ...Option) (*DeleteArticleRes, error) {
var res DeleteArticleRes
// options
opt := buildOptions(c.opts, opts...)
headers := make(map[string]string)
// route
rawURL := fmt.Sprintf("%s/arcopen/fn/article/delete", opt.addr)
// body
bodyForms := url.Values{}
if in.GetBody() != nil && in.GetBody().GetIds() != "" {
bodyForms.Add("ids", fmt.Sprintf("%v", in.GetBody().GetIds()))
}
body := strings.NewReader(bodyForms.Encode())
headers["Content-Type"] = "application/x-www-form-urlencoded"
req, err := http.NewRequest("POST", rawURL, body)
if err != nil {
return nil, err
}
params := req.URL.Query()
if in.GetAccessToken() != "" {
params.Add("access_token", fmt.Sprintf("%v", in.GetAccessToken()))
}
if in.GetClientId() != "" {
params.Add("client_id", fmt.Sprintf("%v", in.GetClientId()))
}
req.URL.RawQuery = params.Encode()
// header
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := opt.DoRequest(ctx, opt.client, req)
if err != nil {
return nil, err
}
err = opt.DoResponse(ctx, resp, &res)
return &res, err
}
func (c *articleService) GetArticleDetail(ctx context.Context, in *GetArticleDetailReq, opts ...Option) (*GetArticleDetailRes, error) {
var res GetArticleDetailRes
// options
opt := buildOptions(c.opts, opts...)
headers := make(map[string]string)
// route
rawURL := fmt.Sprintf("%s/arcopen/fn/article/detail", opt.addr)
// body
bodyForms := url.Values{}
if in.GetBody() != nil && in.GetBody().GetId() != 0 {
bodyForms.Add("id", fmt.Sprintf("%v", in.GetBody().GetId()))
}
body := strings.NewReader(bodyForms.Encode())
headers["Content-Type"] = "application/x-www-form-urlencoded"
req, err := http.NewRequest("GET", rawURL, body)
if err != nil {
return nil, err
}
params := req.URL.Query()
if in.GetAccessToken() != "" {
params.Add("access_token", fmt.Sprintf("%v", in.GetAccessToken()))
}
if in.GetClientId() != "" {
params.Add("client_id", fmt.Sprintf("%v", in.GetClientId()))
}
req.URL.RawQuery = params.Encode()
// header
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := opt.DoRequest(ctx, opt.client, req)
if err != nil {
return nil, err
}
err = opt.DoResponse(ctx, resp, &res)
return &res, err
}
func (c *articleService) BatchGetArticles(ctx context.Context, in *BatchGetArticlesReq, opts ...Option) (*BatchGetArticlesRes, error) {
var res BatchGetArticlesRes
// options
opt := buildOptions(c.opts, opts...)
headers := make(map[string]string)
// route
rawURL := fmt.Sprintf("%s/arcopen/fn/article/list", opt.addr)
// body
bodyForms := url.Values{}
if in.GetBody() != nil && in.GetBody().GetCategory() != 0 {
bodyForms.Add("category", fmt.Sprintf("%v", in.GetBody().GetCategory()))
}
if in.GetBody() != nil && in.GetBody().GetGroup() != 0 {
bodyForms.Add("group", fmt.Sprintf("%v", in.GetBody().GetGroup()))
}
if in.GetBody() != nil && in.GetBody().GetPn() != 0 {
bodyForms.Add("pn", fmt.Sprintf("%v", in.GetBody().GetPn()))
}
if in.GetBody() != nil && in.GetBody().GetPs() != 0 {
bodyForms.Add("ps", fmt.Sprintf("%v", in.GetBody().GetPs()))
}
if in.GetBody() != nil && in.GetBody().GetSort() != 0 {
bodyForms.Add("sort", fmt.Sprintf("%v", in.GetBody().GetSort()))
}
body := strings.NewReader(bodyForms.Encode())
headers["Content-Type"] = "application/x-www-form-urlencoded"
req, err := http.NewRequest("GET", rawURL, body)
if err != nil {
return nil, err
}
params := req.URL.Query()
if in.GetAccessToken() != "" {
params.Add("access_token", fmt.Sprintf("%v", in.GetAccessToken()))
}
if in.GetClientId() != "" {
params.Add("client_id", fmt.Sprintf("%v", in.GetClientId()))
}
req.URL.RawQuery = params.Encode()
// header
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := opt.DoRequest(ctx, opt.client, req)
if err != nil {
return nil, err
}
err = opt.DoResponse(ctx, resp, &res)
return &res, err
}
func (c *articleService) GetArticleCategories(ctx context.Context, in *GetArticleCategoriesReq, opts ...Option) (*GetArticleCategoriesRes, error) {
var res GetArticleCategoriesRes
// options
opt := buildOptions(c.opts, opts...)
headers := make(map[string]string)
// route
rawURL := fmt.Sprintf("%s/arcopen/fn/article/categories", opt.addr)
// body
req, err := http.NewRequest("GET", rawURL, nil)
if err != nil {
return nil, err
}
params := req.URL.Query()
if in.GetAccessToken() != "" {
params.Add("access_token", fmt.Sprintf("%v", in.GetAccessToken()))
}
if in.GetClientId() != "" {
params.Add("client_id", fmt.Sprintf("%v", in.GetClientId()))
}
req.URL.RawQuery = params.Encode()
// header
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := opt.DoRequest(ctx, opt.client, req)
if err != nil {
return nil, err
}
err = opt.DoResponse(ctx, resp, &res)
return &res, err
}
func (c *articleService) GetArticleCard(ctx context.Context, in *GetArticleCardReq, opts ...Option) (*GetArticleCardRes, error) {
var res GetArticleCardRes
// options
opt := buildOptions(c.opts, opts...)
headers := make(map[string]string)
// route
rawURL := fmt.Sprintf("%s/arcopen/fn/article/card", opt.addr)
// body
bodyForms := url.Values{}
if in.GetBody() != nil && in.GetBody().GetResourceId() != 0 {
bodyForms.Add("resource_id", fmt.Sprintf("%v", in.GetBody().GetResourceId()))
}
body := strings.NewReader(bodyForms.Encode())
headers["Content-Type"] = "application/x-www-form-urlencoded"
req, err := http.NewRequest("GET", rawURL, body)
if err != nil {
return nil, err
}
params := req.URL.Query()
if in.GetAccessToken() != "" {
params.Add("access_token", fmt.Sprintf("%v", in.GetAccessToken()))
}
if in.GetClientId() != "" {
params.Add("client_id", fmt.Sprintf("%v", in.GetClientId()))
}
req.URL.RawQuery = params.Encode()
// header
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := opt.DoRequest(ctx, opt.client, req)
if err != nil {
return nil, err
}
err = opt.DoResponse(ctx, resp, &res)
return &res, err
}