rhythia-api 234.0.0 → 235.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/getBeatmaps.ts +122 -92
- package/index.ts +15 -14
- package/package.json +1 -1
package/api/getBeatmaps.ts
CHANGED
|
@@ -23,11 +23,11 @@ export const Schema = {
|
|
|
23
23
|
viewPerPage: z.number(),
|
|
24
24
|
currentPage: z.number(),
|
|
25
25
|
beatmaps: z
|
|
26
|
-
.array(
|
|
27
|
-
z.object({
|
|
28
|
-
id: z.number(),
|
|
29
|
-
playcount: z.number().nullable().optional(),
|
|
30
|
-
created_at: z.string().nullable().optional(),
|
|
26
|
+
.array(
|
|
27
|
+
z.object({
|
|
28
|
+
id: z.number(),
|
|
29
|
+
playcount: z.number().nullable().optional(),
|
|
30
|
+
created_at: z.string().nullable().optional(),
|
|
31
31
|
difficulty: z.number().nullable().optional(),
|
|
32
32
|
noteCount: z.number().nullable().optional(),
|
|
33
33
|
length: z.number().nullable().optional(),
|
|
@@ -36,15 +36,16 @@ export const Schema = {
|
|
|
36
36
|
beatmapFile: z.string().nullable().optional(),
|
|
37
37
|
image: z.string().nullable().optional(),
|
|
38
38
|
starRating: z.number().nullable().optional(),
|
|
39
|
-
owner: z.number().nullable().optional(),
|
|
40
|
-
ownerUsername: z.string().nullable().optional(),
|
|
41
|
-
ownerAvatar: z.string().nullable().optional(),
|
|
42
|
-
status: z.string().nullable().optional(),
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
owner: z.number().nullable().optional(),
|
|
40
|
+
ownerUsername: z.string().nullable().optional(),
|
|
41
|
+
ownerAvatar: z.string().nullable().optional(),
|
|
42
|
+
status: z.string().nullable().optional(),
|
|
43
|
+
qualified: z.boolean().nullable().optional(),
|
|
44
|
+
tags: z.string().nullable().optional(),
|
|
45
|
+
videoUrl: z.string().nullable().optional(),
|
|
46
|
+
})
|
|
47
|
+
)
|
|
48
|
+
.optional(),
|
|
48
49
|
}),
|
|
49
50
|
};
|
|
50
51
|
|
|
@@ -66,24 +67,39 @@ export async function handler(
|
|
|
66
67
|
|
|
67
68
|
const VIEW_PER_PAGE = 50;
|
|
68
69
|
|
|
69
|
-
export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
|
|
70
|
-
const startPage = (data.page - 1) * VIEW_PER_PAGE;
|
|
71
|
-
const endPage = startPage + VIEW_PER_PAGE - 1;
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
70
|
+
export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
|
|
71
|
+
const startPage = (data.page - 1) * VIEW_PER_PAGE;
|
|
72
|
+
const endPage = startPage + VIEW_PER_PAGE - 1;
|
|
73
|
+
const statusFilter = data.status?.toUpperCase();
|
|
74
|
+
let countQry = supabase
|
|
75
|
+
.from("beatmapPages")
|
|
76
|
+
.select(
|
|
77
|
+
`
|
|
78
|
+
id,
|
|
79
|
+
beatmaps!inner(
|
|
80
|
+
title,
|
|
81
|
+
starRating,
|
|
82
|
+
length
|
|
83
|
+
),
|
|
84
|
+
profiles!inner(
|
|
85
|
+
username
|
|
86
|
+
)
|
|
87
|
+
`,
|
|
88
|
+
{ count: "exact", head: true }
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
let qry = supabase.from("beatmapPages").select(
|
|
92
|
+
`
|
|
93
|
+
owner,
|
|
94
|
+
created_at,
|
|
95
|
+
id,
|
|
96
|
+
status,
|
|
97
|
+
qualified,
|
|
98
|
+
tags,
|
|
99
|
+
ranked_at,
|
|
100
|
+
video_url,
|
|
101
|
+
beatmaps!inner(
|
|
102
|
+
playcount,
|
|
87
103
|
ranked,
|
|
88
104
|
beatmapFile,
|
|
89
105
|
image,
|
|
@@ -92,58 +108,71 @@ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
|
|
|
92
108
|
length,
|
|
93
109
|
title
|
|
94
110
|
),
|
|
95
|
-
profiles!inner(
|
|
96
|
-
username
|
|
97
|
-
)`
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
qry = qry.order("ranked_at", { ascending: false });
|
|
102
|
-
} else {
|
|
103
|
-
qry = qry.order("created_at", { ascending: false });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (data.textFilter) {
|
|
107
|
-
qry = qry.ilike("beatmaps.title", `%${data.textFilter}%`);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (data.
|
|
127
|
-
qry = qry.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
111
|
+
profiles!inner(
|
|
112
|
+
username
|
|
113
|
+
)`
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
if (statusFilter === "RANKED") {
|
|
117
|
+
qry = qry.order("ranked_at", { ascending: false });
|
|
118
|
+
} else {
|
|
119
|
+
qry = qry.order("created_at", { ascending: false });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (data.textFilter) {
|
|
123
|
+
qry = qry.ilike("beatmaps.title", `%${data.textFilter}%`);
|
|
124
|
+
countQry = countQry.ilike("beatmaps.title", `%${data.textFilter}%`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (data.authorFilter) {
|
|
128
|
+
qry = qry.ilike("profiles.username", `%${data.authorFilter}%`);
|
|
129
|
+
countQry = countQry.ilike("profiles.username", `%${data.authorFilter}%`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (data.tagsFilter) {
|
|
133
|
+
qry = qry.ilike("tags", `%${data.tagsFilter}%`);
|
|
134
|
+
countQry = countQry.ilike("tags", `%${data.tagsFilter}%`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (data.minStars) {
|
|
138
|
+
qry = qry.gt("beatmaps.starRating", data.minStars);
|
|
139
|
+
countQry = countQry.gt("beatmaps.starRating", data.minStars);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (data.maxStars) {
|
|
143
|
+
qry = qry.lt("beatmaps.starRating", data.maxStars);
|
|
144
|
+
countQry = countQry.lt("beatmaps.starRating", data.maxStars);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (data.minLength) {
|
|
148
|
+
qry = qry.gt("beatmaps.length", data.minLength);
|
|
149
|
+
countQry = countQry.gt("beatmaps.length", data.minLength);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (data.maxLength) {
|
|
153
|
+
qry = qry.lt("beatmaps.length", data.maxLength);
|
|
154
|
+
countQry = countQry.lt("beatmaps.length", data.maxLength);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (statusFilter === "QUALIFIED") {
|
|
158
|
+
qry = qry.eq("qualified", true);
|
|
159
|
+
countQry = countQry.eq("qualified", true);
|
|
160
|
+
} else if (data.status) {
|
|
161
|
+
qry = qry.eq("status", data.status);
|
|
162
|
+
countQry = countQry.eq("status", data.status);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (data.creator !== undefined) {
|
|
166
|
+
qry = qry.eq("owner", data.creator);
|
|
167
|
+
countQry = countQry.eq("owner", data.creator);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const countQuery = await countQry;
|
|
171
|
+
let queryData = await qry.range(startPage, endPage);
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
total: countQuery.count || 0,
|
|
175
|
+
viewPerPage: VIEW_PER_PAGE,
|
|
147
176
|
currentPage: data.page,
|
|
148
177
|
beatmaps: queryData.data?.map((beatmapPage) => ({
|
|
149
178
|
id: beatmapPage.id,
|
|
@@ -156,11 +185,12 @@ export async function getBeatmaps(data: (typeof Schema)["input"]["_type"]) {
|
|
|
156
185
|
length: beatmapPage.beatmaps?.length,
|
|
157
186
|
beatmapFile: beatmapPage.beatmaps?.beatmapFile,
|
|
158
187
|
image: beatmapPage.beatmaps?.image,
|
|
159
|
-
starRating: beatmapPage.beatmaps?.starRating,
|
|
160
|
-
owner: beatmapPage.owner,
|
|
161
|
-
status: beatmapPage.status,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
188
|
+
starRating: beatmapPage.beatmaps?.starRating,
|
|
189
|
+
owner: beatmapPage.owner,
|
|
190
|
+
status: beatmapPage.status,
|
|
191
|
+
qualified: beatmapPage.qualified,
|
|
192
|
+
ownerUsername: beatmapPage.profiles?.username,
|
|
193
|
+
videoUrl: beatmapPage.video_url,
|
|
194
|
+
})),
|
|
195
|
+
};
|
|
196
|
+
}
|
package/index.ts
CHANGED
|
@@ -644,11 +644,11 @@ export const Schema = {
|
|
|
644
644
|
viewPerPage: z.number(),
|
|
645
645
|
currentPage: z.number(),
|
|
646
646
|
beatmaps: z
|
|
647
|
-
.array(
|
|
648
|
-
z.object({
|
|
649
|
-
id: z.number(),
|
|
650
|
-
playcount: z.number().nullable().optional(),
|
|
651
|
-
created_at: z.string().nullable().optional(),
|
|
647
|
+
.array(
|
|
648
|
+
z.object({
|
|
649
|
+
id: z.number(),
|
|
650
|
+
playcount: z.number().nullable().optional(),
|
|
651
|
+
created_at: z.string().nullable().optional(),
|
|
652
652
|
difficulty: z.number().nullable().optional(),
|
|
653
653
|
noteCount: z.number().nullable().optional(),
|
|
654
654
|
length: z.number().nullable().optional(),
|
|
@@ -657,15 +657,16 @@ export const Schema = {
|
|
|
657
657
|
beatmapFile: z.string().nullable().optional(),
|
|
658
658
|
image: z.string().nullable().optional(),
|
|
659
659
|
starRating: z.number().nullable().optional(),
|
|
660
|
-
owner: z.number().nullable().optional(),
|
|
661
|
-
ownerUsername: z.string().nullable().optional(),
|
|
662
|
-
ownerAvatar: z.string().nullable().optional(),
|
|
663
|
-
status: z.string().nullable().optional(),
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
660
|
+
owner: z.number().nullable().optional(),
|
|
661
|
+
ownerUsername: z.string().nullable().optional(),
|
|
662
|
+
ownerAvatar: z.string().nullable().optional(),
|
|
663
|
+
status: z.string().nullable().optional(),
|
|
664
|
+
qualified: z.boolean().nullable().optional(),
|
|
665
|
+
tags: z.string().nullable().optional(),
|
|
666
|
+
videoUrl: z.string().nullable().optional(),
|
|
667
|
+
})
|
|
668
|
+
)
|
|
669
|
+
.optional(),
|
|
669
670
|
}),
|
|
670
671
|
};*/
|
|
671
672
|
import { Schema as GetBeatmaps } from "./api/getBeatmaps"
|