-
Notifications
You must be signed in to change notification settings - Fork 5
/
base.ts
284 lines (239 loc) · 7.86 KB
/
base.ts
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
import { Client } from '../../core/client'
import { BaseClass, BaseResource } from '../base'
import { ImageFormatCollection } from '../misc'
export class ContentTitle extends BaseClass {
public readonly default: string
public readonly english: string | null
public readonly japanese: string | null
public readonly german: string | null
public readonly spanish: string | null
public readonly french: string | null
public readonly synonyms: Array<string>
public toString () {
return this.default
}
public constructor (client: Client, data: any) {
super(client)
this.synonyms = []
this.english = null
this.japanese = null
this.german = null
this.spanish = null
this.french = null
this.default = '(no title)'
for (const { type, title } of data) {
const titleTrimmed = title.trim()
if (!titleTrimmed) {
continue
}
switch (type) {
case 'Default':
this.default = titleTrimmed
break
case 'Japanese':
this.japanese = titleTrimmed
break
case 'English':
this.english = titleTrimmed
break
case 'German':
this.german = titleTrimmed
break
case 'Spanish':
this.spanish = titleTrimmed
break
case 'French':
this.french = titleTrimmed
break
case 'Synonym':
this.synonyms.push(titleTrimmed)
break
}
}
}
}
export type TitleArray = Array<{
type: string
title: string
}>
export class Content extends BaseResource {
public readonly image: ImageFormatCollection
public readonly title: ContentTitle
public readonly titles: TitleArray
public readonly score: number | null
public readonly scoredBy: number | null
public readonly rank: number
public readonly popularity: number
public readonly members: number
public readonly favorites: number
public readonly synopsis: string | null
public readonly background: string | null
public readonly approved: boolean
public constructor (client: Client, data: any) {
super(client, data)
this.image = new ImageFormatCollection(client, data.images)
this.title = new ContentTitle(client, data.titles)
this.titles = data.titles
this.score = data.score || data.scored || null
this.scoredBy = data.scored_by || null
this.rank = data.rank
this.popularity = data.popularity
this.members = data.members
this.favorites = data.favorites
this.synopsis = data.synopsis || null
this.background = data.background || null
this.approved = data.approved
}
}
export class ContentStatisticsScore extends BaseClass {
public readonly score: number
public readonly votes: number
public readonly percentage: number
public constructor (client: Client, data: any) {
super(client)
this.score = data.score
this.votes = data.votes
this.percentage = data.percentage
}
}
export class ContentStatistics extends BaseClass {
public readonly completed: number
public readonly onHold: number
public readonly dropped: number
public readonly total: number
public readonly scores: ContentStatisticsScore
public constructor (client: Client, data: any) {
super(client)
this.completed = data.completed
this.onHold = data.on_hold
this.dropped = data.dropped
this.total = data.total
this.scores = data.scores?.map((score: any) => new ContentStatisticsScore(client, score)) || []
}
}
export class ContentNews extends BaseResource {
public readonly title: string
public readonly date: Date
public readonly authorUsername: string
public readonly authorURL: URL
public readonly forumURL: URL
public readonly image: ImageFormatCollection | null
public readonly comments: number
public readonly excerpt: string
public constructor (client: Client, data: any) {
super(client, data)
this.title = data.title
this.date = new Date(data.date)
this.authorUsername = data.author_username
this.authorURL = ContentNews.parseURL(data.author_url)
this.forumURL = ContentNews.parseURL(data.forum_url)
this.image = data.images != null ? new ImageFormatCollection(client, data.images) : null
this.comments = data.comments
this.excerpt = data.excerpt
}
}
export class ContentUser extends BaseClass {
public readonly username: string
public readonly url: URL
public readonly image: ImageFormatCollection | null
public constructor (client: Client, data: any) {
super(client)
this.username = data.username
this.url = ContentUser.parseURL(data.url)
this.image = data.images != null ? new ImageFormatCollection(client, data.images) : null
}
}
export class ContentReactions extends BaseClass {
public readonly overall: number
public readonly nice: number
public readonly loveIt: number
public readonly funny: number
public readonly confusing: number
public readonly informative: number
public readonly wellWritten: number
public readonly creative: number
public constructor (client: Client, data: any) {
super(client)
this.overall = data.overall
this.nice = data.nice
this.loveIt = data.love_it
this.funny = data.funny
this.confusing = data.confusing
this.informative = data.informative
this.wellWritten = data.well_written
this.creative = data.creative
}
}
export class ContentReview extends BaseResource {
public readonly type: string
public readonly score: number
public readonly date: Date
public readonly review: string
public readonly reactions: ContentReactions
public readonly user: ContentUser
public readonly isSpoiler: boolean
public readonly isPreliminary: boolean
public readonly tags: Array<string>
public constructor (client: Client, data: any) {
super(client, data)
this.type = data.type
this.score = data.score
this.date = new Date(data.date)
this.review = data.review
this.reactions = new ContentReactions(client, data.reactions)
this.user = new ContentUser(client, data.user)
this.isSpoiler = data.is_spoiler
this.isPreliminary = data.is_preliminary
this.tags = data.tags
}
}
export class ContentUserUpdate extends BaseClass {
public readonly user: ContentUser
public readonly score: number
public readonly status: string
public readonly date: Date
public constructor (client: Client, data: any) {
super(client)
this.user = new ContentUser(client, data.user)
this.score = data.score
this.status = data.status
this.date = new Date(data.date)
}
}
export type ContentRelationType =
'Adaptation' | 'SideStory' | 'Summary' | 'Sequel' | 'Prequel' | 'Character' | 'Other' |
'AlternativeVersion' | 'AlternativeSetting' | 'SpinOff' | 'ParentStory' | 'FullStory' | 'Unknown'
export class ContentRelationGroup <T extends ContentRelationType> extends BaseClass {
/** @hidden */
public static parseRelation (data: any): ContentRelationType {
switch (data?.toLowerCase().trim() || 'any') {
case 'adaptation': return 'Adaptation'
case 'side story': return 'SideStory'
case 'summary': return 'Summary'
case 'sequel': return 'Sequel'
case 'prequel': return 'Prequel'
case 'character': return 'Character'
case 'other': return 'Other'
case 'alternative setting': return 'AlternativeSetting'
case 'alternative version': return 'AlternativeVersion'
case 'spin-off': return 'SpinOff'
case 'full story': return 'FullStory'
case 'parent story': return 'ParentStory'
default: return 'Unknown'
}
}
public readonly relation: T
public constructor (client: Client, relation: T, data: any) {
super(client)
this.relation = relation
}
}
export class ContentExternal extends BaseClass {
public readonly name: string
public readonly url: URL
public constructor (client: Client, data: any) {
super(client)
this.name = data.name
this.url = data.url && new URL(data.url)
}
}