rhythia-api 185.0.0 → 187.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/.prettierrc.json +6 -6
- package/api/addCollectionMap.ts +82 -82
- package/api/approveMap.ts +78 -78
- package/api/chartPublicStats.ts +32 -32
- package/api/createBeatmap.ts +168 -168
- package/api/createBeatmapPage.ts +64 -64
- package/api/createClan.ts +81 -81
- package/api/createCollection.ts +58 -58
- package/api/deleteBeatmapPage.ts +77 -77
- package/api/deleteCollection.ts +59 -59
- package/api/deleteCollectionMap.ts +71 -71
- package/api/editAboutMe.ts +91 -91
- package/api/editClan.ts +90 -90
- package/api/editCollection.ts +77 -77
- package/api/editProfile.ts +123 -123
- package/api/getAvatarUploadUrl.ts +85 -85
- package/api/getBadgedUsers.ts +56 -56
- package/api/getBeatmapComments.ts +57 -57
- package/api/getBeatmapPage.ts +106 -106
- package/api/getBeatmapPageById.ts +99 -99
- package/api/getBeatmapStarRating.ts +53 -53
- package/api/getBeatmaps.ts +159 -159
- package/api/getClan.ts +77 -77
- package/api/getCollection.ts +130 -130
- package/api/getCollections.ts +132 -130
- package/api/getLeaderboard.ts +136 -136
- package/api/getMapUploadUrl.ts +93 -93
- package/api/getPassToken.ts +55 -55
- package/api/getProfile.ts +146 -146
- package/api/getPublicStats.ts +180 -180
- package/api/getRawStarRating.ts +57 -57
- package/api/getScore.ts +85 -85
- package/api/getTimestamp.ts +23 -23
- package/api/getUserScores.ts +175 -175
- package/api/nominateMap.ts +82 -82
- package/api/postBeatmapComment.ts +59 -59
- package/api/rankMapsArchive.ts +64 -64
- package/api/searchUsers.ts +56 -56
- package/api/setPasskey.ts +59 -59
- package/api/submitScore.ts +433 -433
- package/api/updateBeatmapPage.ts +229 -229
- package/handleApi.ts +21 -20
- package/index.html +2 -2
- package/index.ts +867 -866
- package/package.json +1 -1
- package/types/database.ts +800 -798
- package/utils/getUserBySession.ts +48 -48
- package/utils/requestUtils.ts +87 -87
- package/utils/security.ts +20 -20
- package/utils/star-calc/index.ts +72 -72
- package/utils/star-calc/osuUtils.ts +53 -53
- package/utils/star-calc/sspmParser.ts +398 -398
- package/utils/star-calc/sspmv1Parser.ts +165 -165
- package/utils/supabase.ts +13 -13
- package/utils/test +4 -4
- package/utils/validateToken.ts +7 -7
- package/vercel.json +12 -12
package/api/getRawStarRating.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
-
import { rateMapNotes } from "../utils/star-calc";
|
|
5
|
-
import { calculatePerformancePoints } from "./submitScore";
|
|
6
|
-
|
|
7
|
-
export const Schema = {
|
|
8
|
-
input: z.strictObject({
|
|
9
|
-
session: z.string(),
|
|
10
|
-
rawMap: z.string(),
|
|
11
|
-
}),
|
|
12
|
-
output: z.object({
|
|
13
|
-
error: z.string().optional(),
|
|
14
|
-
beatmap: z
|
|
15
|
-
.object({
|
|
16
|
-
starRating: z.number().nullable().optional(),
|
|
17
|
-
})
|
|
18
|
-
.optional(),
|
|
19
|
-
}),
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export async function POST(request: Request): Promise<NextResponse> {
|
|
23
|
-
return protectedApi({
|
|
24
|
-
request,
|
|
25
|
-
schema: Schema,
|
|
26
|
-
authorization: () => {},
|
|
27
|
-
activity: handler,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function handler(
|
|
32
|
-
data: (typeof Schema)["input"]["_type"],
|
|
33
|
-
req: Request
|
|
34
|
-
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
35
|
-
const notes = data.rawMap.split(",");
|
|
36
|
-
notes.shift();
|
|
37
|
-
|
|
38
|
-
const rawNotes = notes.map(
|
|
39
|
-
(e) => e.split("|").map((e) => Number(e)) as [number, number, number]
|
|
40
|
-
);
|
|
41
|
-
const starRating = rateMapNotes(rawNotes);
|
|
42
|
-
return NextResponse.json({
|
|
43
|
-
beatmap: {
|
|
44
|
-
starRating,
|
|
45
|
-
rp: {
|
|
46
|
-
"S---": calculatePerformancePoints((starRating * 1) / 1.35, 1),
|
|
47
|
-
"S--": calculatePerformancePoints((starRating * 1) / 1.25, 1),
|
|
48
|
-
"S-": calculatePerformancePoints((starRating * 1) / 1.15, 1),
|
|
49
|
-
S: calculatePerformancePoints(starRating * 1, 1),
|
|
50
|
-
"S+": calculatePerformancePoints(starRating * 1.15, 1),
|
|
51
|
-
"S++": calculatePerformancePoints(starRating * 1.25, 1),
|
|
52
|
-
"S+++": calculatePerformancePoints(starRating * 1.35, 1),
|
|
53
|
-
"S++++": calculatePerformancePoints(starRating * 1.45, 1),
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
}
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
+
import { rateMapNotes } from "../utils/star-calc";
|
|
5
|
+
import { calculatePerformancePoints } from "./submitScore";
|
|
6
|
+
|
|
7
|
+
export const Schema = {
|
|
8
|
+
input: z.strictObject({
|
|
9
|
+
session: z.string(),
|
|
10
|
+
rawMap: z.string(),
|
|
11
|
+
}),
|
|
12
|
+
output: z.object({
|
|
13
|
+
error: z.string().optional(),
|
|
14
|
+
beatmap: z
|
|
15
|
+
.object({
|
|
16
|
+
starRating: z.number().nullable().optional(),
|
|
17
|
+
})
|
|
18
|
+
.optional(),
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
23
|
+
return protectedApi({
|
|
24
|
+
request,
|
|
25
|
+
schema: Schema,
|
|
26
|
+
authorization: () => {},
|
|
27
|
+
activity: handler,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function handler(
|
|
32
|
+
data: (typeof Schema)["input"]["_type"],
|
|
33
|
+
req: Request
|
|
34
|
+
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
35
|
+
const notes = data.rawMap.split(",");
|
|
36
|
+
notes.shift();
|
|
37
|
+
|
|
38
|
+
const rawNotes = notes.map(
|
|
39
|
+
(e) => e.split("|").map((e) => Number(e)) as [number, number, number]
|
|
40
|
+
);
|
|
41
|
+
const starRating = rateMapNotes(rawNotes);
|
|
42
|
+
return NextResponse.json({
|
|
43
|
+
beatmap: {
|
|
44
|
+
starRating,
|
|
45
|
+
rp: {
|
|
46
|
+
"S---": calculatePerformancePoints((starRating * 1) / 1.35, 1),
|
|
47
|
+
"S--": calculatePerformancePoints((starRating * 1) / 1.25, 1),
|
|
48
|
+
"S-": calculatePerformancePoints((starRating * 1) / 1.15, 1),
|
|
49
|
+
S: calculatePerformancePoints(starRating * 1, 1),
|
|
50
|
+
"S+": calculatePerformancePoints(starRating * 1.15, 1),
|
|
51
|
+
"S++": calculatePerformancePoints(starRating * 1.25, 1),
|
|
52
|
+
"S+++": calculatePerformancePoints(starRating * 1.35, 1),
|
|
53
|
+
"S++++": calculatePerformancePoints(starRating * 1.45, 1),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
package/api/getScore.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
-
import { supabase } from "../utils/supabase";
|
|
5
|
-
|
|
6
|
-
export const Schema = {
|
|
7
|
-
input: z.strictObject({
|
|
8
|
-
session: z.string(),
|
|
9
|
-
id: z.number(),
|
|
10
|
-
}),
|
|
11
|
-
output: z.object({
|
|
12
|
-
error: z.string().optional(),
|
|
13
|
-
score: z
|
|
14
|
-
.object({
|
|
15
|
-
awarded_sp: z.number().nullable(),
|
|
16
|
-
beatmapHash: z.string().nullable(),
|
|
17
|
-
created_at: z.string(),
|
|
18
|
-
id: z.number(),
|
|
19
|
-
misses: z.number().nullable(),
|
|
20
|
-
passed: z.boolean().nullable(),
|
|
21
|
-
songId: z.string().nullable(),
|
|
22
|
-
userId: z.number().nullable(),
|
|
23
|
-
beatmapDifficulty: z.number().optional().nullable(),
|
|
24
|
-
beatmapNotes: z.number().optional().nullable(),
|
|
25
|
-
beatmapTitle: z.string().optional().nullable(),
|
|
26
|
-
username: z.string().optional().nullable(),
|
|
27
|
-
speed: z.number().optional().nullable(),
|
|
28
|
-
spin: z.boolean().optional().nullable(),
|
|
29
|
-
})
|
|
30
|
-
.optional(),
|
|
31
|
-
}),
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export async function POST(request: Request): Promise<NextResponse> {
|
|
35
|
-
return protectedApi({
|
|
36
|
-
request,
|
|
37
|
-
schema: Schema,
|
|
38
|
-
authorization: () => {},
|
|
39
|
-
activity: handler,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export async function handler(
|
|
44
|
-
data: (typeof Schema)["input"]["_type"],
|
|
45
|
-
req: Request
|
|
46
|
-
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
47
|
-
let { data: score, error: errorlast } = await supabase
|
|
48
|
-
.from("scores")
|
|
49
|
-
.select(
|
|
50
|
-
`
|
|
51
|
-
*,
|
|
52
|
-
beatmaps (
|
|
53
|
-
difficulty,
|
|
54
|
-
noteCount,
|
|
55
|
-
title
|
|
56
|
-
),
|
|
57
|
-
profiles (
|
|
58
|
-
username
|
|
59
|
-
)
|
|
60
|
-
`
|
|
61
|
-
)
|
|
62
|
-
.eq("id", data.id)
|
|
63
|
-
.single();
|
|
64
|
-
|
|
65
|
-
if (!score) return NextResponse.json({});
|
|
66
|
-
|
|
67
|
-
return NextResponse.json({
|
|
68
|
-
score: {
|
|
69
|
-
created_at: score.created_at,
|
|
70
|
-
id: score.id,
|
|
71
|
-
passed: score.passed,
|
|
72
|
-
userId: score.userId,
|
|
73
|
-
awarded_sp: score.awarded_sp,
|
|
74
|
-
beatmapHash: score.beatmapHash,
|
|
75
|
-
misses: score.misses,
|
|
76
|
-
songId: score.songId,
|
|
77
|
-
beatmapDifficulty: score.beatmaps?.difficulty,
|
|
78
|
-
beatmapNotes: score.beatmaps?.noteCount,
|
|
79
|
-
beatmapTitle: score.beatmaps?.title,
|
|
80
|
-
username: score.profiles?.username,
|
|
81
|
-
speed: score.speed,
|
|
82
|
-
spin: score.spin,
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
}
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
+
import { supabase } from "../utils/supabase";
|
|
5
|
+
|
|
6
|
+
export const Schema = {
|
|
7
|
+
input: z.strictObject({
|
|
8
|
+
session: z.string(),
|
|
9
|
+
id: z.number(),
|
|
10
|
+
}),
|
|
11
|
+
output: z.object({
|
|
12
|
+
error: z.string().optional(),
|
|
13
|
+
score: z
|
|
14
|
+
.object({
|
|
15
|
+
awarded_sp: z.number().nullable(),
|
|
16
|
+
beatmapHash: z.string().nullable(),
|
|
17
|
+
created_at: z.string(),
|
|
18
|
+
id: z.number(),
|
|
19
|
+
misses: z.number().nullable(),
|
|
20
|
+
passed: z.boolean().nullable(),
|
|
21
|
+
songId: z.string().nullable(),
|
|
22
|
+
userId: z.number().nullable(),
|
|
23
|
+
beatmapDifficulty: z.number().optional().nullable(),
|
|
24
|
+
beatmapNotes: z.number().optional().nullable(),
|
|
25
|
+
beatmapTitle: z.string().optional().nullable(),
|
|
26
|
+
username: z.string().optional().nullable(),
|
|
27
|
+
speed: z.number().optional().nullable(),
|
|
28
|
+
spin: z.boolean().optional().nullable(),
|
|
29
|
+
})
|
|
30
|
+
.optional(),
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
35
|
+
return protectedApi({
|
|
36
|
+
request,
|
|
37
|
+
schema: Schema,
|
|
38
|
+
authorization: () => {},
|
|
39
|
+
activity: handler,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function handler(
|
|
44
|
+
data: (typeof Schema)["input"]["_type"],
|
|
45
|
+
req: Request
|
|
46
|
+
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
47
|
+
let { data: score, error: errorlast } = await supabase
|
|
48
|
+
.from("scores")
|
|
49
|
+
.select(
|
|
50
|
+
`
|
|
51
|
+
*,
|
|
52
|
+
beatmaps (
|
|
53
|
+
difficulty,
|
|
54
|
+
noteCount,
|
|
55
|
+
title
|
|
56
|
+
),
|
|
57
|
+
profiles (
|
|
58
|
+
username
|
|
59
|
+
)
|
|
60
|
+
`
|
|
61
|
+
)
|
|
62
|
+
.eq("id", data.id)
|
|
63
|
+
.single();
|
|
64
|
+
|
|
65
|
+
if (!score) return NextResponse.json({});
|
|
66
|
+
|
|
67
|
+
return NextResponse.json({
|
|
68
|
+
score: {
|
|
69
|
+
created_at: score.created_at,
|
|
70
|
+
id: score.id,
|
|
71
|
+
passed: score.passed,
|
|
72
|
+
userId: score.userId,
|
|
73
|
+
awarded_sp: score.awarded_sp,
|
|
74
|
+
beatmapHash: score.beatmapHash,
|
|
75
|
+
misses: score.misses,
|
|
76
|
+
songId: score.songId,
|
|
77
|
+
beatmapDifficulty: score.beatmaps?.difficulty,
|
|
78
|
+
beatmapNotes: score.beatmaps?.noteCount,
|
|
79
|
+
beatmapTitle: score.beatmaps?.title,
|
|
80
|
+
username: score.profiles?.username,
|
|
81
|
+
speed: score.speed,
|
|
82
|
+
spin: score.spin,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
package/api/getTimestamp.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
-
|
|
5
|
-
export const Schema = {
|
|
6
|
-
input: z.strictObject({}),
|
|
7
|
-
output: z.object({
|
|
8
|
-
time: z.number(),
|
|
9
|
-
}),
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export async function POST(request: Request) {
|
|
13
|
-
return protectedApi({
|
|
14
|
-
request,
|
|
15
|
-
schema: Schema,
|
|
16
|
-
authorization: () => {},
|
|
17
|
-
activity: handler,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
22
|
-
return NextResponse.json({ time: Date.now() });
|
|
23
|
-
}
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
+
|
|
5
|
+
export const Schema = {
|
|
6
|
+
input: z.strictObject({}),
|
|
7
|
+
output: z.object({
|
|
8
|
+
time: z.number(),
|
|
9
|
+
}),
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export async function POST(request: Request) {
|
|
13
|
+
return protectedApi({
|
|
14
|
+
request,
|
|
15
|
+
schema: Schema,
|
|
16
|
+
authorization: () => {},
|
|
17
|
+
activity: handler,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
22
|
+
return NextResponse.json({ time: Date.now() });
|
|
23
|
+
}
|
package/api/getUserScores.ts
CHANGED
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
-
import { supabase } from "../utils/supabase";
|
|
5
|
-
|
|
6
|
-
export const Schema = {
|
|
7
|
-
input: z.strictObject({
|
|
8
|
-
session: z.string(),
|
|
9
|
-
id: z.number(),
|
|
10
|
-
limit: z.number().default(10),
|
|
11
|
-
}),
|
|
12
|
-
output: z.object({
|
|
13
|
-
error: z.string().optional(),
|
|
14
|
-
lastDay: z
|
|
15
|
-
.array(
|
|
16
|
-
z.object({
|
|
17
|
-
awarded_sp: z.number().nullable(),
|
|
18
|
-
beatmapHash: z.string().nullable(),
|
|
19
|
-
created_at: z.string(),
|
|
20
|
-
id: z.number(),
|
|
21
|
-
misses: z.number().nullable(),
|
|
22
|
-
passed: z.boolean().nullable(),
|
|
23
|
-
songId: z.string().nullable(),
|
|
24
|
-
userId: z.number().nullable(),
|
|
25
|
-
beatmapDifficulty: z.number().optional().nullable(),
|
|
26
|
-
beatmapNotes: z.number().optional().nullable(),
|
|
27
|
-
beatmapTitle: z.string().optional().nullable(),
|
|
28
|
-
speed: z.number().optional().nullable(),
|
|
29
|
-
spin: z.boolean().optional().nullable(),
|
|
30
|
-
})
|
|
31
|
-
)
|
|
32
|
-
.optional(),
|
|
33
|
-
top: z
|
|
34
|
-
.array(
|
|
35
|
-
z.object({
|
|
36
|
-
awarded_sp: z.number().nullable(),
|
|
37
|
-
beatmapHash: z.string().nullable(),
|
|
38
|
-
created_at: z.string(),
|
|
39
|
-
id: z.number(),
|
|
40
|
-
misses: z.number().nullable(),
|
|
41
|
-
passed: z.boolean().nullable(),
|
|
42
|
-
rank: z.string().nullable(),
|
|
43
|
-
songId: z.string().nullable(),
|
|
44
|
-
userId: z.number().nullable(),
|
|
45
|
-
beatmapDifficulty: z.number().optional().nullable(),
|
|
46
|
-
beatmapNotes: z.number().optional().nullable(),
|
|
47
|
-
beatmapTitle: z.string().optional().nullable(),
|
|
48
|
-
speed: z.number().optional().nullable(),
|
|
49
|
-
spin: z.boolean().optional().nullable(),
|
|
50
|
-
})
|
|
51
|
-
)
|
|
52
|
-
.optional(),
|
|
53
|
-
stats: z
|
|
54
|
-
.object({
|
|
55
|
-
totalScores: z.number(),
|
|
56
|
-
spinScores: z.number(),
|
|
57
|
-
})
|
|
58
|
-
.optional(),
|
|
59
|
-
}),
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export async function POST(request: Request): Promise<NextResponse> {
|
|
63
|
-
return protectedApi({
|
|
64
|
-
request,
|
|
65
|
-
schema: Schema,
|
|
66
|
-
authorization: () => {},
|
|
67
|
-
activity: handler,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function handler(
|
|
72
|
-
data: (typeof Schema)["input"]["_type"],
|
|
73
|
-
req: Request
|
|
74
|
-
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
75
|
-
if (data.limit > 100) {
|
|
76
|
-
return NextResponse.json({ error: "Limit breached" });
|
|
77
|
-
}
|
|
78
|
-
let { data: scores1, error: errorlast } = await supabase
|
|
79
|
-
.from("scores")
|
|
80
|
-
.select(
|
|
81
|
-
`
|
|
82
|
-
*,
|
|
83
|
-
beatmaps (
|
|
84
|
-
difficulty,
|
|
85
|
-
noteCount,
|
|
86
|
-
title
|
|
87
|
-
)
|
|
88
|
-
`
|
|
89
|
-
)
|
|
90
|
-
.eq("userId", data.id)
|
|
91
|
-
.eq("passed", true)
|
|
92
|
-
.order("created_at", { ascending: false })
|
|
93
|
-
.limit(data.limit);
|
|
94
|
-
|
|
95
|
-
let { data: scores2, error: errorsp } = await supabase
|
|
96
|
-
.from("scores")
|
|
97
|
-
.select(
|
|
98
|
-
`
|
|
99
|
-
*,
|
|
100
|
-
beatmaps (
|
|
101
|
-
difficulty,
|
|
102
|
-
noteCount,
|
|
103
|
-
title
|
|
104
|
-
)
|
|
105
|
-
`
|
|
106
|
-
)
|
|
107
|
-
.eq("userId", data.id)
|
|
108
|
-
.neq("awarded_sp", 0)
|
|
109
|
-
.eq("passed", true)
|
|
110
|
-
.order("awarded_sp", { ascending: false });
|
|
111
|
-
|
|
112
|
-
if (scores2 == null) return NextResponse.json({ error: "No scores" });
|
|
113
|
-
|
|
114
|
-
let spinScores = 0;
|
|
115
|
-
let totalScores = scores2.length;
|
|
116
|
-
let hashMap: Record<string, { awarded_sp: number; score: any }> = {};
|
|
117
|
-
|
|
118
|
-
for (const score of scores2) {
|
|
119
|
-
const { beatmapHash, awarded_sp, spin } = score;
|
|
120
|
-
|
|
121
|
-
if (!beatmapHash || !awarded_sp) continue;
|
|
122
|
-
|
|
123
|
-
if (score.spin) {
|
|
124
|
-
spinScores++;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (!hashMap[beatmapHash] || hashMap[beatmapHash].awarded_sp < awarded_sp) {
|
|
128
|
-
hashMap[beatmapHash] = { awarded_sp, score };
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const values = Object.values(hashMap);
|
|
133
|
-
let vals = values
|
|
134
|
-
.sort((a, b) => b.awarded_sp - a.awarded_sp)
|
|
135
|
-
.slice(0, data.limit)
|
|
136
|
-
.map((e) => e.score);
|
|
137
|
-
|
|
138
|
-
return NextResponse.json({
|
|
139
|
-
lastDay: scores1?.map((s) => ({
|
|
140
|
-
created_at: s.created_at,
|
|
141
|
-
id: s.id,
|
|
142
|
-
passed: s.passed,
|
|
143
|
-
userId: s.userId,
|
|
144
|
-
awarded_sp: s.awarded_sp,
|
|
145
|
-
beatmapHash: s.beatmapHash,
|
|
146
|
-
misses: s.misses,
|
|
147
|
-
songId: s.songId,
|
|
148
|
-
beatmapDifficulty: s.beatmaps?.difficulty,
|
|
149
|
-
beatmapNotes: s.beatmaps?.noteCount,
|
|
150
|
-
beatmapTitle: s.beatmaps?.title,
|
|
151
|
-
speed: s.speed,
|
|
152
|
-
spin: s.spin,
|
|
153
|
-
})),
|
|
154
|
-
top: vals?.map((s) => ({
|
|
155
|
-
created_at: s.created_at,
|
|
156
|
-
id: s.id,
|
|
157
|
-
passed: s.passed,
|
|
158
|
-
userId: s.userId,
|
|
159
|
-
awarded_sp: s.awarded_sp,
|
|
160
|
-
beatmapHash: s.beatmapHash,
|
|
161
|
-
misses: s.misses,
|
|
162
|
-
rank: s.rank,
|
|
163
|
-
songId: s.songId,
|
|
164
|
-
beatmapDifficulty: s.beatmaps?.difficulty,
|
|
165
|
-
beatmapNotes: s.beatmaps?.noteCount,
|
|
166
|
-
beatmapTitle: s.beatmaps?.title,
|
|
167
|
-
speed: s.speed,
|
|
168
|
-
spin: s.spin,
|
|
169
|
-
})),
|
|
170
|
-
stats: {
|
|
171
|
-
totalScores,
|
|
172
|
-
spinScores,
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
}
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
+
import { supabase } from "../utils/supabase";
|
|
5
|
+
|
|
6
|
+
export const Schema = {
|
|
7
|
+
input: z.strictObject({
|
|
8
|
+
session: z.string(),
|
|
9
|
+
id: z.number(),
|
|
10
|
+
limit: z.number().default(10),
|
|
11
|
+
}),
|
|
12
|
+
output: z.object({
|
|
13
|
+
error: z.string().optional(),
|
|
14
|
+
lastDay: z
|
|
15
|
+
.array(
|
|
16
|
+
z.object({
|
|
17
|
+
awarded_sp: z.number().nullable(),
|
|
18
|
+
beatmapHash: z.string().nullable(),
|
|
19
|
+
created_at: z.string(),
|
|
20
|
+
id: z.number(),
|
|
21
|
+
misses: z.number().nullable(),
|
|
22
|
+
passed: z.boolean().nullable(),
|
|
23
|
+
songId: z.string().nullable(),
|
|
24
|
+
userId: z.number().nullable(),
|
|
25
|
+
beatmapDifficulty: z.number().optional().nullable(),
|
|
26
|
+
beatmapNotes: z.number().optional().nullable(),
|
|
27
|
+
beatmapTitle: z.string().optional().nullable(),
|
|
28
|
+
speed: z.number().optional().nullable(),
|
|
29
|
+
spin: z.boolean().optional().nullable(),
|
|
30
|
+
})
|
|
31
|
+
)
|
|
32
|
+
.optional(),
|
|
33
|
+
top: z
|
|
34
|
+
.array(
|
|
35
|
+
z.object({
|
|
36
|
+
awarded_sp: z.number().nullable(),
|
|
37
|
+
beatmapHash: z.string().nullable(),
|
|
38
|
+
created_at: z.string(),
|
|
39
|
+
id: z.number(),
|
|
40
|
+
misses: z.number().nullable(),
|
|
41
|
+
passed: z.boolean().nullable(),
|
|
42
|
+
rank: z.string().nullable(),
|
|
43
|
+
songId: z.string().nullable(),
|
|
44
|
+
userId: z.number().nullable(),
|
|
45
|
+
beatmapDifficulty: z.number().optional().nullable(),
|
|
46
|
+
beatmapNotes: z.number().optional().nullable(),
|
|
47
|
+
beatmapTitle: z.string().optional().nullable(),
|
|
48
|
+
speed: z.number().optional().nullable(),
|
|
49
|
+
spin: z.boolean().optional().nullable(),
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
.optional(),
|
|
53
|
+
stats: z
|
|
54
|
+
.object({
|
|
55
|
+
totalScores: z.number(),
|
|
56
|
+
spinScores: z.number(),
|
|
57
|
+
})
|
|
58
|
+
.optional(),
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
63
|
+
return protectedApi({
|
|
64
|
+
request,
|
|
65
|
+
schema: Schema,
|
|
66
|
+
authorization: () => {},
|
|
67
|
+
activity: handler,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function handler(
|
|
72
|
+
data: (typeof Schema)["input"]["_type"],
|
|
73
|
+
req: Request
|
|
74
|
+
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
75
|
+
if (data.limit > 100) {
|
|
76
|
+
return NextResponse.json({ error: "Limit breached" });
|
|
77
|
+
}
|
|
78
|
+
let { data: scores1, error: errorlast } = await supabase
|
|
79
|
+
.from("scores")
|
|
80
|
+
.select(
|
|
81
|
+
`
|
|
82
|
+
*,
|
|
83
|
+
beatmaps (
|
|
84
|
+
difficulty,
|
|
85
|
+
noteCount,
|
|
86
|
+
title
|
|
87
|
+
)
|
|
88
|
+
`
|
|
89
|
+
)
|
|
90
|
+
.eq("userId", data.id)
|
|
91
|
+
.eq("passed", true)
|
|
92
|
+
.order("created_at", { ascending: false })
|
|
93
|
+
.limit(data.limit);
|
|
94
|
+
|
|
95
|
+
let { data: scores2, error: errorsp } = await supabase
|
|
96
|
+
.from("scores")
|
|
97
|
+
.select(
|
|
98
|
+
`
|
|
99
|
+
*,
|
|
100
|
+
beatmaps (
|
|
101
|
+
difficulty,
|
|
102
|
+
noteCount,
|
|
103
|
+
title
|
|
104
|
+
)
|
|
105
|
+
`
|
|
106
|
+
)
|
|
107
|
+
.eq("userId", data.id)
|
|
108
|
+
.neq("awarded_sp", 0)
|
|
109
|
+
.eq("passed", true)
|
|
110
|
+
.order("awarded_sp", { ascending: false });
|
|
111
|
+
|
|
112
|
+
if (scores2 == null) return NextResponse.json({ error: "No scores" });
|
|
113
|
+
|
|
114
|
+
let spinScores = 0;
|
|
115
|
+
let totalScores = scores2.length;
|
|
116
|
+
let hashMap: Record<string, { awarded_sp: number; score: any }> = {};
|
|
117
|
+
|
|
118
|
+
for (const score of scores2) {
|
|
119
|
+
const { beatmapHash, awarded_sp, spin } = score;
|
|
120
|
+
|
|
121
|
+
if (!beatmapHash || !awarded_sp) continue;
|
|
122
|
+
|
|
123
|
+
if (score.spin) {
|
|
124
|
+
spinScores++;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!hashMap[beatmapHash] || hashMap[beatmapHash].awarded_sp < awarded_sp) {
|
|
128
|
+
hashMap[beatmapHash] = { awarded_sp, score };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const values = Object.values(hashMap);
|
|
133
|
+
let vals = values
|
|
134
|
+
.sort((a, b) => b.awarded_sp - a.awarded_sp)
|
|
135
|
+
.slice(0, data.limit)
|
|
136
|
+
.map((e) => e.score);
|
|
137
|
+
|
|
138
|
+
return NextResponse.json({
|
|
139
|
+
lastDay: scores1?.map((s) => ({
|
|
140
|
+
created_at: s.created_at,
|
|
141
|
+
id: s.id,
|
|
142
|
+
passed: s.passed,
|
|
143
|
+
userId: s.userId,
|
|
144
|
+
awarded_sp: s.awarded_sp,
|
|
145
|
+
beatmapHash: s.beatmapHash,
|
|
146
|
+
misses: s.misses,
|
|
147
|
+
songId: s.songId,
|
|
148
|
+
beatmapDifficulty: s.beatmaps?.difficulty,
|
|
149
|
+
beatmapNotes: s.beatmaps?.noteCount,
|
|
150
|
+
beatmapTitle: s.beatmaps?.title,
|
|
151
|
+
speed: s.speed,
|
|
152
|
+
spin: s.spin,
|
|
153
|
+
})),
|
|
154
|
+
top: vals?.map((s) => ({
|
|
155
|
+
created_at: s.created_at,
|
|
156
|
+
id: s.id,
|
|
157
|
+
passed: s.passed,
|
|
158
|
+
userId: s.userId,
|
|
159
|
+
awarded_sp: s.awarded_sp,
|
|
160
|
+
beatmapHash: s.beatmapHash,
|
|
161
|
+
misses: s.misses,
|
|
162
|
+
rank: s.rank,
|
|
163
|
+
songId: s.songId,
|
|
164
|
+
beatmapDifficulty: s.beatmaps?.difficulty,
|
|
165
|
+
beatmapNotes: s.beatmaps?.noteCount,
|
|
166
|
+
beatmapTitle: s.beatmaps?.title,
|
|
167
|
+
speed: s.speed,
|
|
168
|
+
spin: s.spin,
|
|
169
|
+
})),
|
|
170
|
+
stats: {
|
|
171
|
+
totalScores,
|
|
172
|
+
spinScores,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
}
|