rhythia-api 141.0.0 → 143.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.
@@ -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)
@@ -11,14 +11,10 @@ export const Schema = {
11
11
  relayHwid: z.string(),
12
12
  songId: z.string(),
13
13
  misses: z.number(),
14
- squareHits: z.number(),
14
+ hits: z.number(),
15
15
  mapHash: z.string(),
16
- mapTitle: z.string(),
17
- mapDifficulty: z.number(),
18
16
  mapNoteCount: z.number(),
19
- mapLength: z.number(),
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,36 @@ 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
- title: data.mapTitle,
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
+ let passed = true;
115
+
116
+ // Pass invalidation
117
+ if (data.misses + data.hits !== beatmaps.noteCount) {
118
+ passed = false;
119
+ }
120
+
121
+ const accurracy = data.hits / beatmaps.noteCount;
122
+ let awarded_sp = 0;
123
+
124
+ console.log(
125
+ data.misses + data.hits == beatmaps.noteCount,
126
+ data.misses + data.hits,
127
+ beatmaps.noteCount
128
+ );
129
+
130
+ if (beatmaps.starRating) {
131
+ awarded_sp = calculatePerformancePoints(
132
+ data.speed * beatmaps.starRating,
133
+ accurracy
134
+ );
135
+ }
136
+
120
137
  if (beatmapPages.status == "UNRANKED") {
121
- data.sspp = 0;
138
+ awarded_sp = 0;
122
139
  }
123
140
 
124
141
  console.log("p1");
@@ -127,9 +144,10 @@ export async function handler({
127
144
  replayHwid: data.relayHwid,
128
145
  songId: data.songId,
129
146
  userId: userData.id,
130
- passed: data.passed,
147
+ passed,
131
148
  misses: data.misses,
132
- awarded_sp: Math.round(data.sspp * 100) / 100,
149
+ awarded_sp: Math.round(awarded_sp * 100) / 100,
150
+ speed: data.speed,
133
151
  });
134
152
  console.log("p2");
135
153
 
@@ -172,11 +190,9 @@ export async function handler({
172
190
  id: userData.id,
173
191
  play_count: (userData.play_count || 0) + 1,
174
192
  skill_points: Math.round(totalSp * 100) / 100,
175
- squares_hit: (userData.squares_hit || 0) + data.squareHits,
193
+ squares_hit: (userData.squares_hit || 0) + data.hits,
176
194
  });
177
195
  console.log("p3");
178
196
 
179
- // await Promise.all([p1, p2, p3]);
180
-
181
197
  return NextResponse.json({});
182
198
  }
@@ -73,6 +73,7 @@ export async function handler({
73
73
  owner: userData.id,
74
74
  description,
75
75
  tags,
76
+ nominations: [],
76
77
  })
77
78
  .select("*")
78
79
  .single();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "141.0.0",
3
+ "version": "143.0.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "update": "bun ./scripts/update.ts",