-
Notifications
You must be signed in to change notification settings - Fork 1
/
structs.go
153 lines (131 loc) · 4.27 KB
/
structs.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package wallhaven
import (
"path"
"path/filepath"
"strconv"
)
// WallpaperID is a string representing a wallpaper
type WallpaperID string
// TagID is an int representing a tag on wh
type TagID int64
func (t TagID) String() string {
return strconv.Itoa(int(t))
}
// CollectionID is a string representing a Collection
type CollectionID string
// Avatar user's avatar
type Avatar struct {
Two00Px string `json:"200px"`
One28Px string `json:"128px"`
Three2Px string `json:"32px"`
Two0Px string `json:"20px"`
}
// Uploader information on who uploaded a given wallpaper
type Uploader struct {
Username string `json:"username"`
Group string `json:"group"`
Avatar Avatar `json:"avatar"`
}
// Tag full data on a given wallpaper tag
type Tag struct {
ID int `json:"id"`
Name string `json:"name"`
Alias string `json:"alias"`
CategoryID int `json:"category_id"`
Category string `json:"category"`
Purity string `json:"purity"`
CreatedAt string `json:"created_at"`
}
// Wallpaper information about a given wallpaper
type Wallpaper struct {
ID WallpaperID `json:"id"`
URL string `json:"url"`
ShortURL string `json:"short_url"`
Uploader Uploader `json:"uploader"`
Views int `json:"views"`
Favorites int `json:"favorites"`
Source string `json:"source"`
Purity string `json:"purity"`
Category string `json:"category"`
DimensionX int `json:"dimension_x"`
DimensionY int `json:"dimension_y"`
Resolution string `json:"resolution"`
Ratio string `json:"ratio"`
FileSize int `json:"file_size"`
FileType string `json:"file_type"`
CreatedAt string `json:"created_at"`
Colors []string `json:"colors"`
Path string `json:"path"`
Thumbs Thumbs `json:"thumbs"`
Tags []Tag `json:"tags"`
}
// Download downloads a wallpaper given the local filepath to save the wallpaper to
func (w *Wallpaper) Download(dir string) error {
resp, err := getAuthedResponse(w.Path)
if err != nil {
return err
}
path := filepath.Join(dir, path.Base(w.Path))
return download(path, resp)
}
// Thumbs paths for thumbnail images of wallpaper
type Thumbs struct {
Large string `json:"large"`
Original string `json:"original"`
Small string `json:"small"`
}
//TODO: (dlasky) add download support for thumbs
// Meta paging and stats metadata for search results
type Meta struct {
CurrentPage int `json:"current_page"`
LastPage int `json:"last_page"`
PerPage int `json:"per_page"`
Total int `json:"total"`
Query interface{} `json:"query"`
}
// User User preference Data (set on wallhaven's user GUI)
type User struct {
ThumbSize string `json:"thumb_size"`
PerPage string `json:"per_page"`
Purity []string `json:"purity"`
Categories []string `json:"categories"`
Resolutions []string `json:"resolutions"`
AspectRatios []string `json:"aspect_ratios"`
ToplistRange string `json:"toplist_range"`
TagBlacklist []string `json:"tag_blacklist"`
UserBlacklist []string `json:"user_blacklist"`
}
type Collection struct {
ID CollectionID `json:"id"`
Label string `json:"label"`
Views string `json:"views"`
Privacy Privacy `json:"public"`
Count int `json:"count"`
}
//Result Structs -- server responses
// SearchResults a wrapper containing search results from wh
type SearchResults struct {
Data []Wallpaper `json:"data"`
Meta Meta `json:"meta"`
}
// TagResult a wrapper containing a single tag result when TagInfo is requested
type TagResult struct {
Data Tag `json:"data"`
}
// UserResult a wrapper containing user preference data
type UserResult struct {
Data User `json:"data"`
}
// WallpaperResult a wrapper containing a single wallpaper result when WallpaperInfo is requested
type WallpaperResult struct {
Data Wallpaper `json:"data"`
}
// CollectionsResult a wrapper containing an array of user's collection.
type CollectionsResult struct {
Data []Collection `json:"data"`
}
// CollectionWallpapersResult a wrapper containing the list of wallpapers for a given user's collection and its Metadata.
type CollectionWallpapersResult struct {
Data []Wallpaper `json:"data"`
Meta Meta `json:"meta"`
}