-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.go
83 lines (73 loc) · 2.69 KB
/
file.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
package box
import "net/http"
type FileService struct {
*Client
}
type FileVersion struct {
Type string `json:"type"`
ID string `json:"id"`
Sha1 string `json:"sha1"`
}
type FileEntry struct {
Type string `json:"type"`
ID string `json:"id"`
SequenceID interface{} `json:"sequence_id"`
Etag interface{} `json:"etag"`
Name string `json:"name"`
}
type FilePathCollection struct {
TotalCount int `json:"total_count"`
Entries *[]FileEntry `json:"entries"`
}
type SharedLinkPermissions struct {
CanDownload bool `json:"can_download"`
CanPreview bool `json:"can_preview"`
}
type SharedLink struct {
URL string `json:"url"`
DownloadURL string `json:"download_url"`
VanityURL interface{} `json:"vanity_url"`
IsPasswordEnabled bool `json:"is_password_enabled"`
UnsharedAt interface{} `json:"unshared_at"`
DownloadCount int `json:"download_count"`
PreviewCount int `json:"preview_count"`
Access string `json:"access"`
Permissions *SharedLinkPermissions `json:"permissions"`
}
type FileParent struct {
Type string `json:"type"`
ID string `json:"id"`
SequenceID string `json:"sequence_id"`
Etag string `json:"etag"`
Name string `json:"name"`
}
type File struct {
Type string `json:"type"`
ID string `json:"id"`
FileVersion *FileVersion `json:"file_version"`
SequenceID string `json:"sequence_id"`
Etag string `json:"etag"`
Sha1 string `json:"sha1"`
Name string `json:"name"`
Description string `json:"description"`
Size int `json:"size"`
PathCollection *FilePathCollection `json:"path_collection"`
CreatedAt string `json:"created_at"`
ModifiedAt string `json:"modified_at"`
CreatedBy *User `json:"created_by"`
ModifiedBy *User `json:"modified_by"`
OwnedBy *User `json:"owned_by"`
SharedLink *SharedLink `json:"shared_link"`
Parent *ItemParent `json:"parent"`
ItemStatus string `json:"item_status"`
}
func (f *FileService) GetFileHash(fileID string) (string, error) {
var respFileJSON File
req, err := http.NewRequest("GET", f.BaseUrl.String()+"/files/"+fileID, nil)
req.Header.Add("Authorization", "Bearer "+f.Token)
_, err = f.Do(req, &respFileJSON)
if err != nil {
return "", err
}
return respFileJSON.Sha1, nil
}