rhythia-api 162.0.0 → 164.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/getProfile.ts +14 -1
- package/api/getUserScores.ts +17 -1
- package/index.ts +7 -0
- package/package.json +1 -1
- package/types/database.ts +15 -0
- package/utils/requestUtils.ts +15 -1
package/api/getProfile.ts
CHANGED
|
@@ -32,6 +32,7 @@ export const Schema = {
|
|
|
32
32
|
squares_hit: z.number().nullable(),
|
|
33
33
|
total_score: z.number().nullable(),
|
|
34
34
|
position: z.number().nullable(),
|
|
35
|
+
is_online: z.boolean(),
|
|
35
36
|
})
|
|
36
37
|
.optional(),
|
|
37
38
|
}),
|
|
@@ -51,7 +52,7 @@ export async function handler(
|
|
|
51
52
|
req: Request
|
|
52
53
|
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
53
54
|
let profiles: Database["public"]["Tables"]["profiles"]["Row"][] = [];
|
|
54
|
-
|
|
55
|
+
let isOnline = false;
|
|
55
56
|
// Fetch by id
|
|
56
57
|
if (data.id !== undefined && data.id !== null) {
|
|
57
58
|
let { data: queryData, error } = await supabase
|
|
@@ -112,6 +113,17 @@ export async function handler(
|
|
|
112
113
|
|
|
113
114
|
const user = profiles[0];
|
|
114
115
|
|
|
116
|
+
const { data: activityData } = await supabase
|
|
117
|
+
.from("profileActivities")
|
|
118
|
+
.select("*")
|
|
119
|
+
.eq("uid", user.uid || "")
|
|
120
|
+
.single();
|
|
121
|
+
|
|
122
|
+
//last 30 minutes
|
|
123
|
+
if (activityData && activityData.last_activity) {
|
|
124
|
+
isOnline = Date.now() - activityData.last_activity < 1800000;
|
|
125
|
+
}
|
|
126
|
+
|
|
115
127
|
// Query to count how many players have more skill points than the specific player
|
|
116
128
|
const { count: playersWithMorePoints, error: rankError } = await supabase
|
|
117
129
|
.from("profiles")
|
|
@@ -123,6 +135,7 @@ export async function handler(
|
|
|
123
135
|
user: {
|
|
124
136
|
...user,
|
|
125
137
|
position: (playersWithMorePoints || 0) + 1,
|
|
138
|
+
is_online: isOnline,
|
|
126
139
|
},
|
|
127
140
|
});
|
|
128
141
|
}
|
package/api/getUserScores.ts
CHANGED
|
@@ -50,6 +50,12 @@ export const Schema = {
|
|
|
50
50
|
})
|
|
51
51
|
)
|
|
52
52
|
.optional(),
|
|
53
|
+
stats: z
|
|
54
|
+
.object({
|
|
55
|
+
totalScores: z.number(),
|
|
56
|
+
spinScores: z.number(),
|
|
57
|
+
})
|
|
58
|
+
.optional(),
|
|
53
59
|
}),
|
|
54
60
|
};
|
|
55
61
|
|
|
@@ -105,13 +111,19 @@ export async function handler(
|
|
|
105
111
|
|
|
106
112
|
if (scores2 == null) return NextResponse.json({ error: "No scores" });
|
|
107
113
|
|
|
114
|
+
let spinScores = 0;
|
|
115
|
+
let totalScores = scores2.length;
|
|
108
116
|
let hashMap: Record<string, { awarded_sp: number; score: any }> = {};
|
|
109
117
|
|
|
110
118
|
for (const score of scores2) {
|
|
111
|
-
const { beatmapHash, awarded_sp } = score;
|
|
119
|
+
const { beatmapHash, awarded_sp, spin } = score;
|
|
112
120
|
|
|
113
121
|
if (!beatmapHash || !awarded_sp) continue;
|
|
114
122
|
|
|
123
|
+
if (score.spin) {
|
|
124
|
+
spinScores++;
|
|
125
|
+
}
|
|
126
|
+
|
|
115
127
|
if (!hashMap[beatmapHash] || hashMap[beatmapHash].awarded_sp < awarded_sp) {
|
|
116
128
|
hashMap[beatmapHash] = { awarded_sp, score };
|
|
117
129
|
}
|
|
@@ -155,5 +167,9 @@ export async function handler(
|
|
|
155
167
|
speed: s.speed,
|
|
156
168
|
spin: s.spin,
|
|
157
169
|
})),
|
|
170
|
+
stats: {
|
|
171
|
+
totalScores,
|
|
172
|
+
spinScores,
|
|
173
|
+
},
|
|
158
174
|
});
|
|
159
175
|
}
|
package/index.ts
CHANGED
|
@@ -425,6 +425,7 @@ export const Schema = {
|
|
|
425
425
|
squares_hit: z.number().nullable(),
|
|
426
426
|
total_score: z.number().nullable(),
|
|
427
427
|
position: z.number().nullable(),
|
|
428
|
+
is_online: z.boolean(),
|
|
428
429
|
})
|
|
429
430
|
.optional(),
|
|
430
431
|
}),
|
|
@@ -582,6 +583,12 @@ export const Schema = {
|
|
|
582
583
|
})
|
|
583
584
|
)
|
|
584
585
|
.optional(),
|
|
586
|
+
stats: z
|
|
587
|
+
.object({
|
|
588
|
+
totalScores: z.number(),
|
|
589
|
+
spinScores: z.number(),
|
|
590
|
+
})
|
|
591
|
+
.optional(),
|
|
585
592
|
}),
|
|
586
593
|
};*/
|
|
587
594
|
import { Schema as GetUserScores } from "./api/getUserScores"
|
package/package.json
CHANGED
package/types/database.ts
CHANGED
|
@@ -179,6 +179,21 @@ export type Database = {
|
|
|
179
179
|
},
|
|
180
180
|
]
|
|
181
181
|
}
|
|
182
|
+
profileActivities: {
|
|
183
|
+
Row: {
|
|
184
|
+
last_activity: number | null
|
|
185
|
+
uid: string
|
|
186
|
+
}
|
|
187
|
+
Insert: {
|
|
188
|
+
last_activity?: number | null
|
|
189
|
+
uid: string
|
|
190
|
+
}
|
|
191
|
+
Update: {
|
|
192
|
+
last_activity?: number | null
|
|
193
|
+
uid?: string
|
|
194
|
+
}
|
|
195
|
+
Relationships: []
|
|
196
|
+
}
|
|
182
197
|
profiles: {
|
|
183
198
|
Row: {
|
|
184
199
|
about_me: string | null
|
package/utils/requestUtils.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
|
-
import { ZodObject } from "zod";
|
|
2
|
+
import { set, ZodObject } from "zod";
|
|
3
3
|
import { getUserBySession } from "./getUserBySession";
|
|
4
|
+
import { supabase } from "./supabase";
|
|
4
5
|
|
|
5
6
|
interface Props<
|
|
6
7
|
K = (...args: any[]) => Promise<NextResponse<any>>,
|
|
@@ -21,6 +22,7 @@ export async function protectedApi({
|
|
|
21
22
|
try {
|
|
22
23
|
const toParse = await request.json();
|
|
23
24
|
const data = schema.input.parse(toParse);
|
|
25
|
+
setActivity(data);
|
|
24
26
|
if (authorization) {
|
|
25
27
|
const authorizationResponse = await authorization(data);
|
|
26
28
|
if (authorizationResponse) {
|
|
@@ -33,6 +35,18 @@ export async function protectedApi({
|
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
export async function setActivity(data: Record<string, any>) {
|
|
39
|
+
if (data.session) {
|
|
40
|
+
const user = (await supabase.auth.getUser(data.session)).data.user;
|
|
41
|
+
if (user) {
|
|
42
|
+
await supabase.from("profileActivities").upsert({
|
|
43
|
+
uid: user.id,
|
|
44
|
+
last_activity: Date.now(),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
36
50
|
export async function validUser(data) {
|
|
37
51
|
if (!data.session) {
|
|
38
52
|
return NextResponse.json(
|