rhythia-api 152.0.0 → 154.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.
@@ -3,7 +3,6 @@ import z from "zod";
3
3
  import { Database } from "../types/database";
4
4
  import { protectedApi, validUser } from "../utils/requestUtils";
5
5
  import { supabase } from "../utils/supabase";
6
- import md5 from "md5";
7
6
  import { encryptString } from "../utils/security";
8
7
  export const Schema = {
9
8
  input: z.strictObject({
package/api/getProfile.ts CHANGED
@@ -4,6 +4,8 @@ import z from "zod";
4
4
  import { Database } from "../types/database";
5
5
  import { protectedApi } from "../utils/requestUtils";
6
6
  import { supabase } from "../utils/supabase";
7
+ import { getUserBySession } from "../utils/getUserBySession";
8
+ import { User } from "@supabase/supabase-js";
7
9
 
8
10
  export const Schema = {
9
11
  input: z.strictObject({
@@ -71,7 +73,7 @@ export async function handler(
71
73
  profiles = queryData;
72
74
  } else {
73
75
  // Fetch by session id
74
- const user = (await supabase.auth.getUser(data.session)).data.user;
76
+ const user = (await getUserBySession(data.session)) as User;
75
77
 
76
78
  if (user) {
77
79
  let { data: queryData, error } = await supabase
@@ -9,6 +9,26 @@ export const Schema = {
9
9
  profiles: z.number(),
10
10
  beatmaps: z.number(),
11
11
  scores: z.number(),
12
+ lastBeatmaps: z.array(
13
+ z.object({
14
+ id: z.number().nullable().optional(),
15
+ nominations: z.array(z.number()).nullable().optional(),
16
+ playcount: z.number().nullable().optional(),
17
+ created_at: z.string().nullable().optional(),
18
+ difficulty: z.number().nullable().optional(),
19
+ noteCount: z.number().nullable().optional(),
20
+ length: z.number().nullable().optional(),
21
+ title: z.string().nullable().optional(),
22
+ ranked: z.boolean().nullable().optional(),
23
+ beatmapFile: z.string().nullable().optional(),
24
+ image: z.string().nullable().optional(),
25
+ starRating: z.number().nullable().optional(),
26
+ owner: z.number().nullable().optional(),
27
+ ownerUsername: z.string().nullable().optional(),
28
+ ownerAvatar: z.string().nullable().optional(),
29
+ status: z.string().nullable().optional(),
30
+ })
31
+ ),
12
32
  }),
13
33
  };
14
34
 
@@ -30,6 +50,33 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
30
50
  .from("beatmaps")
31
51
  .select("*", { count: "exact", head: true });
32
52
 
53
+ let { data: beatmapPage, error: errorlast } = await supabase
54
+ .from("beatmapPages")
55
+ .select(
56
+ `
57
+ *,
58
+ beatmaps (
59
+ created_at,
60
+ playcount,
61
+ length,
62
+ ranked,
63
+ beatmapFile,
64
+ image,
65
+ starRating,
66
+ difficulty,
67
+ noteCount,
68
+ title
69
+ ),
70
+ profiles (
71
+ username,
72
+ avatar_url
73
+ )
74
+ `
75
+ )
76
+ .eq("status", "RANKED")
77
+ .order("created_at", { ascending: false })
78
+ .limit(4);
79
+
33
80
  const countScoresQuery = await supabase
34
81
  .from("scores")
35
82
  .select("*", { count: "exact", head: true });
@@ -38,5 +85,23 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
38
85
  beatmaps: countBeatmapsQuery.count,
39
86
  profiles: countProfilesQuery.count,
40
87
  scores: countScoresQuery.count,
88
+ lastBeatmaps: beatmapPage?.map((e) => ({
89
+ playcount: e.beatmaps?.playcount,
90
+ created_at: e.created_at,
91
+ difficulty: e.beatmaps?.difficulty,
92
+ noteCount: e.beatmaps?.noteCount,
93
+ length: e.beatmaps?.length,
94
+ title: e.beatmaps?.title,
95
+ ranked: e.beatmaps?.ranked,
96
+ beatmapFile: e.beatmaps?.beatmapFile,
97
+ image: e.beatmaps?.image,
98
+ starRating: e.beatmaps?.starRating,
99
+ owner: e.owner,
100
+ ownerUsername: e.profiles?.username,
101
+ ownerAvatar: e.profiles?.avatar_url,
102
+ id: e.id,
103
+ status: e.status,
104
+ nominations: e.nominations as number[],
105
+ })),
41
106
  });
42
107
  }
package/api/setPasskey.ts CHANGED
@@ -3,7 +3,6 @@ import z from "zod";
3
3
  import { Database } from "../types/database";
4
4
  import { protectedApi, validUser } from "../utils/requestUtils";
5
5
  import { supabase } from "../utils/supabase";
6
- import md5 from "md5";
7
6
  import { getUserBySession } from "../utils/getUserBySession";
8
7
  import { User } from "@supabase/supabase-js";
9
8
  export const Schema = {
@@ -53,7 +52,7 @@ export async function handler(
53
52
  await supabase.from("passkeys").upsert({
54
53
  id: userData.id!,
55
54
  email: user.email!,
56
- passkey: md5(data.data.passkey),
55
+ passkey: data.data.passkey,
57
56
  });
58
57
 
59
58
  return NextResponse.json({});
@@ -17,7 +17,6 @@ export const Schema = {
17
17
  misses: z.number(),
18
18
  hits: z.number(),
19
19
  mapHash: z.string(),
20
- mapNoteCount: z.number(),
21
20
  speed: z.number(),
22
21
  }),
23
22
  }),
@@ -26,8 +25,10 @@ export const Schema = {
26
25
  }),
27
26
  };
28
27
 
29
- function easeInExpoDeq(x: number) {
30
- return x === 0 ? 0 : Math.pow(2, 50 * x - 50);
28
+ function easeInExpoDeqHard(x: number, star: number) {
29
+ let exponent = 100 - 12 * star;
30
+ if (exponent < 5) exponent = 5;
31
+ return x === 0 ? 0 : Math.pow(2, exponent * x - exponent);
31
32
  }
32
33
 
33
34
  export function calculatePerformancePoints(
@@ -35,7 +36,10 @@ export function calculatePerformancePoints(
35
36
  accuracy: number
36
37
  ) {
37
38
  return Math.round(
38
- Math.pow((starRating * easeInExpoDeq(accuracy) * 100) / 2, 2) / 1000
39
+ Math.pow(
40
+ (starRating * easeInExpoDeqHard(accuracy, starRating) * 100) / 2,
41
+ 2
42
+ ) / 1000
39
43
  );
40
44
  }
41
45
 
@@ -62,7 +66,6 @@ export async function handler({
62
66
  misses: data.misses,
63
67
  hits: data.hits,
64
68
  mapHash: data.mapHash,
65
- mapNoteCount: data.mapNoteCount,
66
69
  speed: data.speed,
67
70
  })
68
71
  ) {
@@ -121,7 +124,8 @@ export async function handler({
121
124
  );
122
125
  }
123
126
 
124
- if (beatmaps.noteCount !== data.mapNoteCount) {
127
+ const noteCount = data.misses + data.hits;
128
+ if (noteCount !== beatmaps.noteCount) {
125
129
  return NextResponse.json(
126
130
  {
127
131
  error: "Wrong map",
@@ -142,7 +146,7 @@ export async function handler({
142
146
  passed = false;
143
147
  }
144
148
 
145
- const accurracy = data.hits / beatmaps.noteCount;
149
+ const accurracy = data.hits / noteCount;
146
150
  let awarded_sp = 0;
147
151
 
148
152
  console.log(
@@ -203,9 +207,9 @@ export async function handler({
203
207
 
204
208
  for (const score of values) {
205
209
  totalSp += ((score || 0) * weight) / 100;
206
- weight -= 1;
210
+ weight = weight * 0.97;
207
211
 
208
- if (weight == 0) {
212
+ if (weight < 5) {
209
213
  break;
210
214
  }
211
215
  }
package/index.ts CHANGED
@@ -418,6 +418,26 @@ export const Schema = {
418
418
  profiles: z.number(),
419
419
  beatmaps: z.number(),
420
420
  scores: z.number(),
421
+ lastBeatmaps: z.array(
422
+ z.object({
423
+ id: z.number().nullable().optional(),
424
+ nominations: z.array(z.number()).nullable().optional(),
425
+ playcount: z.number().nullable().optional(),
426
+ created_at: z.string().nullable().optional(),
427
+ difficulty: z.number().nullable().optional(),
428
+ noteCount: z.number().nullable().optional(),
429
+ length: z.number().nullable().optional(),
430
+ title: z.string().nullable().optional(),
431
+ ranked: z.boolean().nullable().optional(),
432
+ beatmapFile: z.string().nullable().optional(),
433
+ image: z.string().nullable().optional(),
434
+ starRating: z.number().nullable().optional(),
435
+ owner: z.number().nullable().optional(),
436
+ ownerUsername: z.string().nullable().optional(),
437
+ ownerAvatar: z.string().nullable().optional(),
438
+ status: z.string().nullable().optional(),
439
+ })
440
+ ),
421
441
  }),
422
442
  };*/
423
443
  import { Schema as GetPublicStats } from "./api/getPublicStats"
@@ -613,7 +633,6 @@ export const Schema = {
613
633
  misses: z.number(),
614
634
  hits: z.number(),
615
635
  mapHash: z.string(),
616
- mapNoteCount: z.number(),
617
636
  speed: z.number(),
618
637
  }),
619
638
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "152.0.0",
3
+ "version": "154.0.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "update": "bun ./scripts/update.ts",
@@ -10,6 +10,7 @@ export async function getUserBySession(session: string): Promise<User | null> {
10
10
  }
11
11
 
12
12
  try {
13
+ console.log("trying legacy token");
13
14
  const decryptedToken = JSON.parse(decryptString(session)) as {
14
15
  userId: number;
15
16
  email: string;
@@ -17,14 +18,24 @@ export async function getUserBySession(session: string): Promise<User | null> {
17
18
  computerName: string;
18
19
  };
19
20
 
21
+ for (const key of Object.keys(decryptedToken)) {
22
+ if (decryptedToken[key] === undefined || decryptedToken[key] === null) {
23
+ return null;
24
+ }
25
+ }
26
+
27
+ console.log(decryptedToken);
28
+
20
29
  let { data: queryPasskey, error } = await supabase
21
30
  .from("passkeys")
22
31
  .select("*,profiles(uid)")
23
- .eq("id", decryptedToken.userId || "nil")
24
- .eq("email", decryptedToken.email || "nil")
25
- .eq("passkey", decryptedToken.passKey || "nil")
32
+ .eq("id", decryptedToken.userId)
33
+ .eq("email", decryptedToken.email)
34
+ .eq("passkey", decryptedToken.passKey)
26
35
  .single();
27
36
 
37
+ console.log(queryPasskey);
38
+
28
39
  if (!queryPasskey) {
29
40
  return null;
30
41
  }