-
Notifications
You must be signed in to change notification settings - Fork 86
/
api_getSignedFileUrls.go
52 lines (46 loc) · 1.34 KB
/
api_getSignedFileUrls.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
package notionapi
type permissionRecord struct {
ID string `json:"id"`
Table string `json:"table"`
SpaceID string `json:"spaceId"`
}
type signedURLRequest struct {
URL string `json:"url"`
PermissionRecord *permissionRecord `json:"permissionRecord"`
}
// /api/v3/getSignedFileUrls request
type getSignedFileURLsRequest struct {
URLs []signedURLRequest `json:"urls"`
}
// GetSignedURLsResponse represents response to /api/v3/getSignedFileUrls api
// Note: it depends on Table type in request
type GetSignedURLsResponse struct {
SignedURLS []string `json:"signedUrls"`
RawJSON map[string]interface{} `json:"-"`
}
// GetSignedURLs executes a raw API call /api/v3/getSignedFileUrls
func (c *Client) GetSignedURLs(urls []string, block *Block) (*GetSignedURLsResponse, error) {
permRec := &permissionRecord{
ID: block.ID,
Table: block.ParentTable,
SpaceID: block.SpaceID,
}
var recs []signedURLRequest
for _, url := range urls {
srec := signedURLRequest{
URL: url,
PermissionRecord: permRec,
}
recs = append(recs, srec)
}
req := &getSignedFileURLsRequest{
URLs: recs,
}
var rsp GetSignedURLsResponse
var err error
apiURL := "/api/v3/getSignedFileUrls"
if err = c.doNotionAPI(apiURL, req, &rsp, &rsp.RawJSON); err != nil {
return nil, err
}
return &rsp, nil
}