rhythia-api 156.0.0 → 158.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/getBeatmapStarRating.ts +53 -0
- package/api/getTimestamp.ts +2 -2
- package/api/submitScore.ts +13 -1
- package/index.ts +22 -0
- package/package.json +2 -2
- package/types/database.ts +9 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
+
import { supabase } from "../utils/supabase";
|
|
5
|
+
|
|
6
|
+
export const Schema = {
|
|
7
|
+
input: z.strictObject({
|
|
8
|
+
session: z.string(),
|
|
9
|
+
mapId: z.string(),
|
|
10
|
+
}),
|
|
11
|
+
output: z.object({
|
|
12
|
+
error: z.string().optional(),
|
|
13
|
+
beatmap: z
|
|
14
|
+
.object({
|
|
15
|
+
starRating: z.number().nullable().optional(),
|
|
16
|
+
})
|
|
17
|
+
.optional(),
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
22
|
+
return protectedApi({
|
|
23
|
+
request,
|
|
24
|
+
schema: Schema,
|
|
25
|
+
authorization: () => {},
|
|
26
|
+
activity: handler,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function handler(
|
|
31
|
+
data: (typeof Schema)["input"]["_type"],
|
|
32
|
+
req: Request
|
|
33
|
+
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
34
|
+
let { data: beatmapPage, error: errorlast } = await supabase
|
|
35
|
+
.from("beatmapPages")
|
|
36
|
+
.select(
|
|
37
|
+
`
|
|
38
|
+
beatmaps (
|
|
39
|
+
starRating
|
|
40
|
+
)
|
|
41
|
+
`
|
|
42
|
+
)
|
|
43
|
+
.eq("latestBeatmapHash", data.mapId)
|
|
44
|
+
.single();
|
|
45
|
+
|
|
46
|
+
if (!beatmapPage) return NextResponse.json({});
|
|
47
|
+
|
|
48
|
+
return NextResponse.json({
|
|
49
|
+
beatmap: {
|
|
50
|
+
starRating: beatmapPage.beatmaps?.starRating,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
package/api/getTimestamp.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
2
|
import z from "zod";
|
|
3
|
-
import { protectedApi
|
|
3
|
+
import { protectedApi } from "../utils/requestUtils";
|
|
4
4
|
|
|
5
5
|
export const Schema = {
|
|
6
6
|
input: z.strictObject({}),
|
|
@@ -13,7 +13,7 @@ export async function POST(request: Request) {
|
|
|
13
13
|
return protectedApi({
|
|
14
14
|
request,
|
|
15
15
|
schema: Schema,
|
|
16
|
-
authorization:
|
|
16
|
+
authorization: () => {},
|
|
17
17
|
activity: handler,
|
|
18
18
|
});
|
|
19
19
|
}
|
package/api/submitScore.ts
CHANGED
|
@@ -18,6 +18,7 @@ export const Schema = {
|
|
|
18
18
|
hits: z.number(),
|
|
19
19
|
mapHash: z.string(),
|
|
20
20
|
speed: z.number(),
|
|
21
|
+
mods: z.array(z.string()),
|
|
21
22
|
}),
|
|
22
23
|
}),
|
|
23
24
|
output: z.object({
|
|
@@ -67,6 +68,7 @@ export async function handler({
|
|
|
67
68
|
hits: data.hits,
|
|
68
69
|
mapHash: data.mapHash,
|
|
69
70
|
speed: data.speed,
|
|
71
|
+
mods: data.mods,
|
|
70
72
|
})
|
|
71
73
|
) {
|
|
72
74
|
return NextResponse.json(
|
|
@@ -155,9 +157,18 @@ export async function handler({
|
|
|
155
157
|
beatmaps.noteCount
|
|
156
158
|
);
|
|
157
159
|
|
|
160
|
+
let multiplierMod = 1;
|
|
161
|
+
if (data.mods.includes("mod_hardrock")) {
|
|
162
|
+
multiplierMod *= 1.12;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (data.mods.includes("mod_nofail")) {
|
|
166
|
+
multiplierMod *= Math.pow(0.95, data.misses);
|
|
167
|
+
}
|
|
168
|
+
|
|
158
169
|
if (beatmaps.starRating) {
|
|
159
170
|
awarded_sp = calculatePerformancePoints(
|
|
160
|
-
data.speed * beatmaps.starRating,
|
|
171
|
+
data.speed * beatmaps.starRating * multiplierMod,
|
|
161
172
|
accurracy
|
|
162
173
|
);
|
|
163
174
|
}
|
|
@@ -176,6 +187,7 @@ export async function handler({
|
|
|
176
187
|
misses: data.misses,
|
|
177
188
|
awarded_sp: Math.round(awarded_sp * 100) / 100,
|
|
178
189
|
speed: data.speed,
|
|
190
|
+
mods: data.mods,
|
|
179
191
|
});
|
|
180
192
|
console.log("p2");
|
|
181
193
|
|
package/index.ts
CHANGED
|
@@ -300,6 +300,27 @@ import { Schema as GetBeatmaps } from "./api/getBeatmaps"
|
|
|
300
300
|
export { Schema as SchemaGetBeatmaps } from "./api/getBeatmaps"
|
|
301
301
|
export const getBeatmaps = handleApi({url:"/api/getBeatmaps",...GetBeatmaps})
|
|
302
302
|
|
|
303
|
+
// ./api/getBeatmapStarRating.ts API
|
|
304
|
+
|
|
305
|
+
/*
|
|
306
|
+
export const Schema = {
|
|
307
|
+
input: z.strictObject({
|
|
308
|
+
session: z.string(),
|
|
309
|
+
mapId: z.string(),
|
|
310
|
+
}),
|
|
311
|
+
output: z.object({
|
|
312
|
+
error: z.string().optional(),
|
|
313
|
+
beatmap: z
|
|
314
|
+
.object({
|
|
315
|
+
starRating: z.number().nullable().optional(),
|
|
316
|
+
})
|
|
317
|
+
.optional(),
|
|
318
|
+
}),
|
|
319
|
+
};*/
|
|
320
|
+
import { Schema as GetBeatmapStarRating } from "./api/getBeatmapStarRating"
|
|
321
|
+
export { Schema as SchemaGetBeatmapStarRating } from "./api/getBeatmapStarRating"
|
|
322
|
+
export const getBeatmapStarRating = handleApi({url:"/api/getBeatmapStarRating",...GetBeatmapStarRating})
|
|
323
|
+
|
|
303
324
|
// ./api/getLeaderboard.ts API
|
|
304
325
|
|
|
305
326
|
/*
|
|
@@ -664,6 +685,7 @@ export const Schema = {
|
|
|
664
685
|
hits: z.number(),
|
|
665
686
|
mapHash: z.string(),
|
|
666
687
|
speed: z.number(),
|
|
688
|
+
mods: z.array(z.string()),
|
|
667
689
|
}),
|
|
668
690
|
}),
|
|
669
691
|
output: z.object({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rhythia-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "158.0.0",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"update": "bun ./scripts/update.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"osu-standard-stable": "^5.0.0",
|
|
40
40
|
"sharp": "^0.33.5",
|
|
41
41
|
"simple-git": "^3.25.0",
|
|
42
|
-
"supabase": "^
|
|
42
|
+
"supabase": "^2.0.0",
|
|
43
43
|
"tsx": "^4.17.0",
|
|
44
44
|
"utf-8-validate": "^6.0.4",
|
|
45
45
|
"zod": "^3.23.8"
|
package/types/database.ts
CHANGED
|
@@ -184,8 +184,10 @@ export type Database = {
|
|
|
184
184
|
created_at: number | null
|
|
185
185
|
flag: string | null
|
|
186
186
|
id: number
|
|
187
|
+
mu_rank: number
|
|
187
188
|
play_count: number | null
|
|
188
189
|
profile_image: string | null
|
|
190
|
+
sigma_rank: number | null
|
|
189
191
|
skill_points: number | null
|
|
190
192
|
squares_hit: number | null
|
|
191
193
|
total_score: number | null
|
|
@@ -203,8 +205,10 @@ export type Database = {
|
|
|
203
205
|
created_at?: number | null
|
|
204
206
|
flag?: string | null
|
|
205
207
|
id?: number
|
|
208
|
+
mu_rank?: number
|
|
206
209
|
play_count?: number | null
|
|
207
210
|
profile_image?: string | null
|
|
211
|
+
sigma_rank?: number | null
|
|
208
212
|
skill_points?: number | null
|
|
209
213
|
squares_hit?: number | null
|
|
210
214
|
total_score?: number | null
|
|
@@ -222,8 +226,10 @@ export type Database = {
|
|
|
222
226
|
created_at?: number | null
|
|
223
227
|
flag?: string | null
|
|
224
228
|
id?: number
|
|
229
|
+
mu_rank?: number
|
|
225
230
|
play_count?: number | null
|
|
226
231
|
profile_image?: string | null
|
|
232
|
+
sigma_rank?: number | null
|
|
227
233
|
skill_points?: number | null
|
|
228
234
|
squares_hit?: number | null
|
|
229
235
|
total_score?: number | null
|
|
@@ -240,6 +246,7 @@ export type Database = {
|
|
|
240
246
|
created_at: string
|
|
241
247
|
id: number
|
|
242
248
|
misses: number | null
|
|
249
|
+
mods: Json
|
|
243
250
|
passed: boolean | null
|
|
244
251
|
replayHwid: string | null
|
|
245
252
|
songId: string | null
|
|
@@ -252,6 +259,7 @@ export type Database = {
|
|
|
252
259
|
created_at?: string
|
|
253
260
|
id?: number
|
|
254
261
|
misses?: number | null
|
|
262
|
+
mods?: Json
|
|
255
263
|
passed?: boolean | null
|
|
256
264
|
replayHwid?: string | null
|
|
257
265
|
songId?: string | null
|
|
@@ -264,6 +272,7 @@ export type Database = {
|
|
|
264
272
|
created_at?: string
|
|
265
273
|
id?: number
|
|
266
274
|
misses?: number | null
|
|
275
|
+
mods?: Json
|
|
267
276
|
passed?: boolean | null
|
|
268
277
|
replayHwid?: string | null
|
|
269
278
|
songId?: string | null
|