rhythia-api 152.0.0 → 153.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/getPassToken.ts +0 -1
- package/api/getProfile.ts +3 -1
- package/api/setPasskey.ts +1 -2
- package/api/submitScore.ts +3 -4
- package/index.ts +0 -1
- package/package.json +1 -1
- package/utils/getUserBySession.ts +14 -3
package/api/getPassToken.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 { 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
|
|
76
|
+
const user = (await getUserBySession(data.session)) as User;
|
|
75
77
|
|
|
76
78
|
if (user) {
|
|
77
79
|
let { data: queryData, error } = await supabase
|
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:
|
|
55
|
+
passkey: data.data.passkey,
|
|
57
56
|
});
|
|
58
57
|
|
|
59
58
|
return NextResponse.json({});
|
package/api/submitScore.ts
CHANGED
|
@@ -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
|
}),
|
|
@@ -62,7 +61,6 @@ export async function handler({
|
|
|
62
61
|
misses: data.misses,
|
|
63
62
|
hits: data.hits,
|
|
64
63
|
mapHash: data.mapHash,
|
|
65
|
-
mapNoteCount: data.mapNoteCount,
|
|
66
64
|
speed: data.speed,
|
|
67
65
|
})
|
|
68
66
|
) {
|
|
@@ -121,7 +119,8 @@ export async function handler({
|
|
|
121
119
|
);
|
|
122
120
|
}
|
|
123
121
|
|
|
124
|
-
|
|
122
|
+
const noteCount = data.misses + data.hits;
|
|
123
|
+
if (noteCount !== beatmaps.noteCount) {
|
|
125
124
|
return NextResponse.json(
|
|
126
125
|
{
|
|
127
126
|
error: "Wrong map",
|
|
@@ -142,7 +141,7 @@ export async function handler({
|
|
|
142
141
|
passed = false;
|
|
143
142
|
}
|
|
144
143
|
|
|
145
|
-
const accurracy = data.hits /
|
|
144
|
+
const accurracy = data.hits / noteCount;
|
|
146
145
|
let awarded_sp = 0;
|
|
147
146
|
|
|
148
147
|
console.log(
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -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
|
|
24
|
-
.eq("email", decryptedToken.email
|
|
25
|
-
.eq("passkey", decryptedToken.passKey
|
|
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
|
}
|