Repository navigation
Expand file tree
/
Copy pathqueries.go
More file actions
196 lines (168 loc) · 3.92 KB
/
Copy pathqueries.go
File metadata and controls
196 lines (168 loc) · 3.92 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package javdbapi
import "fmt"
type HomeType string
type HomeFilter string
type HomeSort string
const (
HomeTypeAll HomeType = ""
HomeTypeCensored HomeType = "censored"
HomeTypeUncensored HomeType = "uncensored"
HomeTypeWestern HomeType = "western"
)
const (
HomeFilterAll HomeFilter = "0"
HomeFilterDownload HomeFilter = "1"
HomeFilterCNSub HomeFilter = "2"
HomeFilterReview HomeFilter = "3"
)
const (
HomeSortPublishDate HomeSort = "1"
HomeSortMagnetDate HomeSort = "2"
)
func (t HomeType) valid() bool {
switch t {
case HomeTypeAll, HomeTypeCensored, HomeTypeUncensored, HomeTypeWestern:
return true
default:
return false
}
}
func (f HomeFilter) valid() bool {
switch f {
case "", HomeFilterAll, HomeFilterDownload, HomeFilterCNSub, HomeFilterReview:
return true
default:
return false
}
}
func (s HomeSort) valid() bool {
switch s {
case "", HomeSortPublishDate, HomeSortMagnetDate:
return true
default:
return false
}
}
type HomeQuery struct {
Type HomeType
Filter HomeFilter
Sort HomeSort
Page int
}
type SearchQuery struct {
Keyword string
Page int
}
type MakerFilter string
const (
MakerFilterAll MakerFilter = ""
MakerFilterPlayable MakerFilter = "playable"
MakerFilterSingle MakerFilter = "single"
MakerFilterDownload MakerFilter = "download"
MakerFilterCNSub MakerFilter = "cnsub"
MakerFilterPreview MakerFilter = "preview"
)
func (f MakerFilter) valid() bool {
switch f {
case MakerFilterAll, MakerFilterPlayable, MakerFilterSingle, MakerFilterDownload, MakerFilterCNSub, MakerFilterPreview:
return true
default:
return false
}
}
type ActorFilter string
const (
ActorFilterAll ActorFilter = ""
ActorFilterPlayable ActorFilter = "p"
ActorFilterSingle ActorFilter = "s"
ActorFilterDownload ActorFilter = "d"
ActorFilterCNSub ActorFilter = "c"
)
func (f ActorFilter) valid() bool {
switch f {
case ActorFilterAll, ActorFilterPlayable, ActorFilterSingle, ActorFilterDownload, ActorFilterCNSub:
return true
default:
return false
}
}
type ListSort string
const (
ListSortPublished ListSort = "published"
ListSortRating ListSort = "rating"
ListSortPopularity ListSort = "popularity"
ListSortWantCount ListSort = "want_count"
ListSortWatchedCount ListSort = "watched_count"
)
// sortTypeValue maps to the real page's sort_type=0..4 query parameter.
func (s ListSort) sortTypeValue() (int, error) {
switch s {
case "", ListSortPublished:
return 0, nil
case ListSortRating:
return 1, nil
case ListSortPopularity:
return 2, nil
case ListSortWantCount:
return 3, nil
case ListSortWatchedCount:
return 4, nil
default:
return 0, fmt.Errorf("%w: invalid sort %q", ErrInvalidQuery, s)
}
}
type MakerVideosQuery struct {
MakerID MakerID
Filter MakerFilter
Sort ListSort
Page int
}
type ActorVideosQuery struct {
ActorID ActorID
Filters []ActorFilter
Sort ListSort
Page int
}
type RankingPeriod string
type RankingType string
const (
RankingPeriodDaily RankingPeriod = "daily"
RankingPeriodWeekly RankingPeriod = "weekly"
RankingPeriodMonthly RankingPeriod = "monthly"
)
const (
RankingTypeCensored RankingType = "censored"
RankingTypeUncensored RankingType = "uncensored"
RankingTypeWestern RankingType = "western"
)
func (p RankingPeriod) valid() bool {
switch p {
case RankingPeriodDaily, RankingPeriodWeekly, RankingPeriodMonthly:
return true
default:
return false
}
}
func (t RankingType) valid() bool {
switch t {
case RankingTypeCensored, RankingTypeUncensored, RankingTypeWestern:
return true
default:
return false
}
}
type RankingQuery struct {
Period RankingPeriod
Type RankingType
Page int
}
// normalizeQueryPage maps Page == 0 to the first page and rejects negatives.
func normalizeQueryPage(page int) (int, error) {
if page < 0 {
return 0, fmt.Errorf("%w: negative page %d", ErrInvalidQuery, page)
}
if page == 0 {
return 1, nil
}
return page, nil
}