-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_models.go
131 lines (113 loc) · 5.29 KB
/
api_models.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
package ydfs
import (
"fmt"
"strings"
"time"
)
// DiskInfo provides basic information about the disk
type diskInfo struct {
TrashSize int64 `json:"trash_size,omitempty"` // this and below are in bytes
TotalSpace int64 `json:"total_space,omitempty"`
UsedSpace int64 `json:"used_space,omitempty"`
SystemFolders systemFolders `json:"system_folders,omitempty"`
User user `json:"user,omitempty"`
Revision int64 `json:"revision,omitempty"`
}
func (d *diskInfo) String() string {
user := d.User.String()
space := fmt.Sprintf("Total space:\t%d", d.TotalSpace)
used := fmt.Sprintf("Used space:\t%d", d.UsedSpace)
trash := fmt.Sprintf("Trash size:\t%d", d.TrashSize)
return strings.Join([]string{user, space, used, trash}, "\n")
}
// SystemFolders is a list of system folders on the disk
type systemFolders map[string]string
// Link contains URL to request Resource metadata
type link struct {
OperationID string `json:"operation_id,omitempty"`
Href string `json:"href,omitempty"`
Method string `json:"method,omitempty"`
Templated bool `json:"templated,omitempty"`
}
// Resource holds information about the resource (either directory or file)
type resource struct {
PubLicKey string `json:"public_key,omitempty"`
PublicURL string `json:"public_url,omitempty"`
Embedded resourceList `json:"_embedded,omitempty"`
Name string `json:"name,omitempty"`
Exif map[string]string `json:"exif,omitempty"` // seems to only appear in photos
PhotosliceTime time.Time `json:"photoslice_time,omitempty"` // seems to only appear in photos
DownloadLink string `json:"file,omitempty"` // download link (for photos only?)
PreviewLink string `json:"preview,omitempty"` // preview link (for photos only?)
MediaType string `json:"media_type,omitempty"` // appears in photos and videos (only?)
ResourceID string `json:"resource_id,omitempty"` // unique id of a file
Created time.Time `json:"created,omitempty"`
Modified time.Time `json:"modified,omitempty"`
CustomProperties map[string]string `json:"custom_properties,omitempty"`
OriginPath string `json:"origin_path,omitempty"`
Path string `json:"path,omitempty"`
MD5 string `json:"md5,omitempty"`
SHA256 string `json:"sha26,omitempty"`
CommentIDs CommentIDs `json:"comment_ids,omitempty"` // undocumented :)
Type string `json:"type,omitempty"` // "dir" or "file"
MimeType string `json:"mime_type,omitempty"` // "image/jpeg", "video/mp4" etc.
Size int64 `json:"size,omitempty"` // size in bytes (?)
Revision int64 `json:"revision,omitempty"` // dunno?
AntivirusStatus string `json:"antivirus_status,omitempty"` // "clean", "not-scanned" etc.
}
// ResourceList represents a list of resources
type resourceList struct {
Sort string `json:"sort,omitempty"` // list is sorted by this field
PubLicKey string `json:"public_key,omitempty"`
Items []resource `json:"items,omitempty"`
Path string `json:"path,omitempty"`
Limit int `json:"limit,omitempty"` // this max elements are in Items above
Offset int `json:"offset,omitempty"` // offset from first resource in directory
Total int `json:"total,omitempty"` // total number of elements in directory
}
type CommentIDs struct {
PrivateResourceID string `json:"private_resource,omitempty"`
PublicResourseID string `json:"public_resource,omitempty"`
}
// FileResourceList is a flat list of all files on disk sorted alphabetically
type filesResourceList struct {
Items []resource `json:"items,omitempty"`
Limit int `json:"limit,omitempty"` // this max elements are in Items above
Offset int `json:"offset,omitempty"` // offset from first resource in directory
}
// LastUploadedResourceList is a list of uploaded files sorted by
// upload time from oldest to newest
type lastUploadedResourceList struct {
Items []resource `json:"items,omitempty"`
Limit int `json:"limit,omitempty"`
}
// PublicResourcesList represents a list of publicly available resources
type publicResourcesList struct {
Items []resource `json:"items,omitempty"`
Type string `json:"type,omitempty"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
}
type operation struct {
Status string `json:"status,omitempty"`
}
type user struct {
Country string `json:"country,omitempty"`
Login string `json:"login,omitempty"`
Name string `json:"display_name,omitempty"`
UID string `json:"uid,omitempty"`
}
func (u *user) String() string {
return fmt.Sprintf("Username:\t%s", u.Login)
}
type errAPI struct {
Message string `json:"message,omitempty"`
Description string `json:"description,omitempty"`
Err string `json:"error,omitempty"`
}
func (e *errAPI) Error() string {
return strings.Join([]string{e.Message, e.Description}, " ")
}
func (e *errAPI) NotFound() bool {
return e.Err == "DiskNotFoundError"
}