rhythia-api 141.0.0 → 142.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/getBadgedUsers.ts +1 -2
- package/api/submitScore.ts +29 -28
- package/api/updateBeatmapPage.ts +1 -0
- package/package.json +1 -1
package/api/getBadgedUsers.ts
CHANGED
|
@@ -40,8 +40,7 @@ export async function handler(
|
|
|
40
40
|
export async function getLeaderboard(badge: string) {
|
|
41
41
|
let { data: queryData, error } = await supabase
|
|
42
42
|
.from("profiles")
|
|
43
|
-
.select("flag,id,username,badges")
|
|
44
|
-
.neq("ban", "excluded");
|
|
43
|
+
.select("flag,id,username,badges");
|
|
45
44
|
|
|
46
45
|
const users = queryData?.filter((e) =>
|
|
47
46
|
((e.badges || []) as string[]).includes(badge)
|
package/api/submitScore.ts
CHANGED
|
@@ -11,14 +11,10 @@ export const Schema = {
|
|
|
11
11
|
relayHwid: z.string(),
|
|
12
12
|
songId: z.string(),
|
|
13
13
|
misses: z.number(),
|
|
14
|
-
|
|
14
|
+
hits: z.number(),
|
|
15
15
|
mapHash: z.string(),
|
|
16
|
-
mapTitle: z.string(),
|
|
17
|
-
mapDifficulty: z.number(),
|
|
18
16
|
mapNoteCount: z.number(),
|
|
19
|
-
|
|
20
|
-
passed: z.boolean(),
|
|
21
|
-
sspp: z.number(),
|
|
17
|
+
speed: z.number(),
|
|
22
18
|
}),
|
|
23
19
|
}),
|
|
24
20
|
output: z.object({
|
|
@@ -26,6 +22,19 @@ export const Schema = {
|
|
|
26
22
|
}),
|
|
27
23
|
};
|
|
28
24
|
|
|
25
|
+
function easeInExpoDeq(x: number) {
|
|
26
|
+
return x === 0 ? 0 : Math.pow(2, 50 * x - 50);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function calculatePerformancePoints(
|
|
30
|
+
starRating: number,
|
|
31
|
+
accuracy: number
|
|
32
|
+
) {
|
|
33
|
+
return Math.round(
|
|
34
|
+
Math.pow((starRating * easeInExpoDeq(accuracy) * 100) / 2, 2) / 1000
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
29
38
|
export async function POST(request: Request): Promise<NextResponse> {
|
|
30
39
|
return protectedApi({
|
|
31
40
|
request,
|
|
@@ -79,8 +88,6 @@ export async function handler({
|
|
|
79
88
|
);
|
|
80
89
|
}
|
|
81
90
|
|
|
82
|
-
let newPlaycount = 1;
|
|
83
|
-
|
|
84
91
|
if (!beatmaps) {
|
|
85
92
|
return NextResponse.json(
|
|
86
93
|
{
|
|
@@ -90,14 +97,6 @@ export async function handler({
|
|
|
90
97
|
);
|
|
91
98
|
}
|
|
92
99
|
|
|
93
|
-
if (beatmaps.noteCount !== data.mapNoteCount) {
|
|
94
|
-
return NextResponse.json(
|
|
95
|
-
{
|
|
96
|
-
error: "Wrong map",
|
|
97
|
-
},
|
|
98
|
-
{ status: 500 }
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
100
|
if (beatmaps.noteCount !== data.mapNoteCount) {
|
|
102
101
|
return NextResponse.json(
|
|
103
102
|
{
|
|
@@ -107,18 +106,22 @@ export async function handler({
|
|
|
107
106
|
);
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
newPlaycount = (beatmaps.playcount || 1) + 1;
|
|
111
109
|
await supabase.from("beatmaps").upsert({
|
|
112
110
|
beatmapHash: data.mapHash,
|
|
113
|
-
|
|
114
|
-
playcount: newPlaycount,
|
|
115
|
-
difficulty: data.mapDifficulty,
|
|
116
|
-
noteCount: data.mapNoteCount,
|
|
117
|
-
length: data.mapLength,
|
|
111
|
+
playcount: (beatmaps.playcount || 1) + 1,
|
|
118
112
|
});
|
|
119
113
|
|
|
114
|
+
const passed =
|
|
115
|
+
data.misses == 0 && data.misses + data.hits == beatmaps.noteCount;
|
|
116
|
+
const accurracy = data.hits / beatmaps.noteCount;
|
|
117
|
+
let awarded_sp = 0;
|
|
118
|
+
|
|
119
|
+
if (beatmaps.starRating) {
|
|
120
|
+
awarded_sp = calculatePerformancePoints(beatmaps.starRating, accurracy);
|
|
121
|
+
}
|
|
122
|
+
|
|
120
123
|
if (beatmapPages.status == "UNRANKED") {
|
|
121
|
-
|
|
124
|
+
awarded_sp = 0;
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
console.log("p1");
|
|
@@ -127,9 +130,9 @@ export async function handler({
|
|
|
127
130
|
replayHwid: data.relayHwid,
|
|
128
131
|
songId: data.songId,
|
|
129
132
|
userId: userData.id,
|
|
130
|
-
passed
|
|
133
|
+
passed,
|
|
131
134
|
misses: data.misses,
|
|
132
|
-
awarded_sp: Math.round(
|
|
135
|
+
awarded_sp: Math.round(awarded_sp * 100) / 100,
|
|
133
136
|
});
|
|
134
137
|
console.log("p2");
|
|
135
138
|
|
|
@@ -172,11 +175,9 @@ export async function handler({
|
|
|
172
175
|
id: userData.id,
|
|
173
176
|
play_count: (userData.play_count || 0) + 1,
|
|
174
177
|
skill_points: Math.round(totalSp * 100) / 100,
|
|
175
|
-
squares_hit: (userData.squares_hit || 0) + data.
|
|
178
|
+
squares_hit: (userData.squares_hit || 0) + data.hits,
|
|
176
179
|
});
|
|
177
180
|
console.log("p3");
|
|
178
181
|
|
|
179
|
-
// await Promise.all([p1, p2, p3]);
|
|
180
|
-
|
|
181
182
|
return NextResponse.json({});
|
|
182
183
|
}
|
package/api/updateBeatmapPage.ts
CHANGED