-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
127 lines (113 loc) · 3.36 KB
/
types.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
package go_hidrive
import (
"encoding/json"
"net/url"
"strconv"
"time"
)
// Time represents date and time information for the API.
type Time time.Time
// MarshalJSON turns Time into JSON (in Unix-time/UTC).
func (t *Time) MarshalJSON() ([]byte, error) {
secs := time.Time(*t).Unix()
return []byte(strconv.FormatInt(secs, 10)), nil
}
// UnmarshalJSON turns JSON into Time.
func (t *Time) UnmarshalJSON(data []byte) error {
secs, err := strconv.ParseInt(string(data), 10, 64)
if err != nil {
return err
}
*t = Time(time.Unix(secs, 0))
return nil
}
// Object represents HiDrive object - directory or file
type Object struct {
Path string `json:"path"`
Type string `json:"type"`
ID string `json:"id"`
ParentID string `json:"parent_id"`
Name string `json:"name"`
Size int64 `json:"size"`
MemberCount int64 `json:"nmembers"`
Members []*Object `json:"members"`
MTime Time `json:"mtime"`
CTime Time `json:"ctime"`
MetaHash string `json:"mhash"`
MetaOnlyHash string `json:"mohash"`
NHash string `json:"nhash"`
CHash string `json:"chash"`
Teamfolder bool `json:"teamfolder"`
Readable bool `json:"readable"`
Writable bool `json:"writable"`
Shareable bool `json:"shareable"`
MIMEType string `json:"mime_type"`
RShare []*ShareObject `json:"rshare"`
}
func (h *Object) UnmarshalJSON(b []byte) error {
type HiDriveObjectAlias Object
defaultObject := HiDriveObjectAlias{
Size: -1,
MemberCount: -1,
}
err := json.Unmarshal(b, &defaultObject)
if err != nil {
return err
}
name, err := url.PathUnescape(defaultObject.Name)
if err == nil {
defaultObject.Name = name
}
*h = Object(defaultObject)
return nil
}
// ShareObject represents HiDrive Share object
type ShareObject struct {
ID string `json:"id"`
Path string `json:"path"`
Status string `json:"status"`
FileType string `json:"file_type"`
Count int `json:"count"`
Created Time `json:"created"`
HasPassword bool `json:"has_password"`
Encrypted bool `json:"is_encrypted"`
LastModified Time `json:"last_modified"`
MaxCount int `json:"maxcount"`
Name string `json:"name"`
Password string `json:"password"`
PID string `json:"pid"`
Readable bool `json:"readable"`
Remaining int `json:"remaining"`
ShareType string `json:"share_type"`
Size int `json:"size"`
TTL int `json:"ttl"`
URI string `json:"uri"`
ValidUntil Time `json:"valid_until"`
ViewMode string `json:"viewmode"`
Writable bool `json:"writable"`
}
func (s *ShareObject) UnmarshalJSON(b []byte) error {
type HiDriveShareObjectAlias ShareObject
defaultObject := HiDriveShareObjectAlias{
Size: -1,
TTL: -1,
MaxCount: -1,
Count: -1,
Remaining: -1,
}
err := json.Unmarshal(b, &defaultObject)
if err != nil {
return err
}
*s = ShareObject(defaultObject)
return nil
}
type ShareInviteStatus struct {
To string `json:"to"`
Code int `json:"code"`
Message string `json:"msg"`
}
type ShareInviteResponse struct {
Done []ShareInviteStatus `json:"done"`
Failed []ShareInviteStatus `json:"failed"`
}