-
Notifications
You must be signed in to change notification settings - Fork 5
/
attachements.go
66 lines (58 loc) · 1.89 KB
/
attachements.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
package crowi
import (
"net/http"
"net/url"
"time"
"golang.org/x/net/context"
)
// AttachmentsService handles communication with the Attachments related
// methods of the Crowi API.
type AttachmentsService service
// Add attaches an image file to the page. This request requires
// page_id and the image file path which you want to attach.
func (s *AttachmentsService) Add(ctx context.Context, id, file string) (*Attachment, error) {
var at Attachment
params := map[string]string{
"access_token": s.client.config.Token,
"page_id": id,
}
err := s.client.newRequestWithFile(ctx, http.MethodPost, "/_api/attachments.add", params, &at, file)
if err != nil {
return nil, err
}
return &at, nil
}
// List shows attachment list of the page. This request requires page_id
func (s *AttachmentsService) List(ctx context.Context, id string) (*Attachments, error) {
var at Attachments
params := url.Values{}
params.Set("access_token", s.client.config.Token)
params.Set("page_id", id)
err := s.client.newRequest(ctx, http.MethodGet, "/_api/attachments.list", params, &at)
if err != nil {
return nil, err
}
return &at, nil
}
type Attachment struct {
Attachment AttachmentInfo `json:"attachment"`
Page interface{} `json:"page"`
OK bool `json:"ok"`
}
type AttachmentInfo struct {
FileFormat string `json:"fileFormat"`
FileName string `json:"fileName"`
OriginalName string `json:"originalName"`
FilePath string `json:"filePath"`
Creator interface{} `json:"creator"`
ID string `json:"_id"`
CreatedAt time.Time `json:"createdAt"`
PageCreated bool `json:"pageCreated"`
URL string `json:"url"`
FileSize int `json:"fileSize"`
V int `json:"__v"`
}
type Attachments struct {
Attachments []AttachmentInfo `json:"attachments"`
OK bool `json:"ok"`
}