rhythia-api 113.0.0 → 115.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/getBeatmaps.ts +109 -0
- package/api/getLeaderboard.ts +0 -1
- package/index.ts +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
page: z.number().default(1),
|
|
10
|
+
}),
|
|
11
|
+
output: z.object({
|
|
12
|
+
error: z.string().optional(),
|
|
13
|
+
total: z.number(),
|
|
14
|
+
viewPerPage: z.number(),
|
|
15
|
+
currentPage: z.number(),
|
|
16
|
+
beatmaps: z
|
|
17
|
+
.array(
|
|
18
|
+
z.object({
|
|
19
|
+
id: z.number(),
|
|
20
|
+
playcount: z.number().nullable().optional(),
|
|
21
|
+
created_at: z.string().nullable().optional(),
|
|
22
|
+
difficulty: z.number().nullable().optional(),
|
|
23
|
+
noteCount: z.number().nullable().optional(),
|
|
24
|
+
length: z.number().nullable().optional(),
|
|
25
|
+
title: z.string().nullable().optional(),
|
|
26
|
+
ranked: z.boolean().nullable().optional(),
|
|
27
|
+
beatmapFile: z.string().nullable().optional(),
|
|
28
|
+
image: z.string().nullable().optional(),
|
|
29
|
+
starRating: z.number().nullable().optional(),
|
|
30
|
+
owner: z.number().nullable().optional(),
|
|
31
|
+
ownerUsername: z.string().nullable().optional(),
|
|
32
|
+
ownerAvatar: z.string().nullable().optional(),
|
|
33
|
+
})
|
|
34
|
+
)
|
|
35
|
+
.optional(),
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
40
|
+
return protectedApi({
|
|
41
|
+
request,
|
|
42
|
+
schema: Schema,
|
|
43
|
+
authorization: () => {},
|
|
44
|
+
activity: handler,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function handler(
|
|
49
|
+
data: (typeof Schema)["input"]["_type"]
|
|
50
|
+
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
51
|
+
const result = await getBeatmaps(data.page, data.session);
|
|
52
|
+
return NextResponse.json(result);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const VIEW_PER_PAGE = 50;
|
|
56
|
+
|
|
57
|
+
export async function getBeatmaps(page = 1, session: string) {
|
|
58
|
+
const startPage = (page - 1) * VIEW_PER_PAGE;
|
|
59
|
+
const endPage = startPage + VIEW_PER_PAGE - 1;
|
|
60
|
+
const countQuery = await supabase
|
|
61
|
+
.from("beatmapPages")
|
|
62
|
+
.select("*", { count: "exact", head: true });
|
|
63
|
+
|
|
64
|
+
let { data: queryData, error } = await supabase
|
|
65
|
+
.from("beatmapPages")
|
|
66
|
+
.select(
|
|
67
|
+
`
|
|
68
|
+
*,
|
|
69
|
+
beatmaps (
|
|
70
|
+
created_at,
|
|
71
|
+
playcount,
|
|
72
|
+
length,
|
|
73
|
+
ranked,
|
|
74
|
+
beatmapFile,
|
|
75
|
+
image,
|
|
76
|
+
starRating,
|
|
77
|
+
difficulty,
|
|
78
|
+
noteCount,
|
|
79
|
+
title
|
|
80
|
+
),
|
|
81
|
+
profiles (
|
|
82
|
+
username,
|
|
83
|
+
avatar_url
|
|
84
|
+
)`
|
|
85
|
+
)
|
|
86
|
+
.range(startPage, endPage);
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
total: countQuery.count || 0,
|
|
90
|
+
viewPerPage: VIEW_PER_PAGE,
|
|
91
|
+
currentPage: page,
|
|
92
|
+
beatmaps: queryData?.map((beatmapPage) => ({
|
|
93
|
+
id: beatmapPage.id,
|
|
94
|
+
playcount: beatmapPage.beatmaps?.playcount,
|
|
95
|
+
created_at: beatmapPage.created_at,
|
|
96
|
+
difficulty: beatmapPage.beatmaps?.difficulty,
|
|
97
|
+
noteCount: beatmapPage.beatmaps?.noteCount,
|
|
98
|
+
length: beatmapPage.beatmaps?.length,
|
|
99
|
+
title: beatmapPage.beatmaps?.title,
|
|
100
|
+
ranked: beatmapPage.beatmaps?.ranked,
|
|
101
|
+
beatmapFile: beatmapPage.beatmaps?.beatmapFile,
|
|
102
|
+
image: beatmapPage.beatmaps?.image,
|
|
103
|
+
starRating: beatmapPage.beatmaps?.starRating,
|
|
104
|
+
owner: beatmapPage.owner,
|
|
105
|
+
ownerUsername: beatmapPage.profiles?.username,
|
|
106
|
+
ownerAvatar: beatmapPage.profiles?.avatar_url,
|
|
107
|
+
})),
|
|
108
|
+
};
|
|
109
|
+
}
|
package/api/getLeaderboard.ts
CHANGED
|
@@ -71,7 +71,6 @@ export async function getLeaderboard(page = 1, session: string) {
|
|
|
71
71
|
|
|
72
72
|
const startPage = (page - 1) * VIEW_PER_PAGE;
|
|
73
73
|
const endPage = startPage + VIEW_PER_PAGE - 1;
|
|
74
|
-
console.log(startPage, endPage);
|
|
75
74
|
const countQuery = await supabase
|
|
76
75
|
.from("profiles")
|
|
77
76
|
.select("*", { count: "exact", head: true })
|
package/index.ts
CHANGED
|
@@ -30,6 +30,11 @@ import { Schema as GetBeatmapPage } from "./api/getBeatmapPage"
|
|
|
30
30
|
export { Schema as SchemaGetBeatmapPage } from "./api/getBeatmapPage"
|
|
31
31
|
export const getBeatmapPage = handleApi({url:"/api/getBeatmapPage",...GetBeatmapPage})
|
|
32
32
|
|
|
33
|
+
// ./api/getBeatmaps.ts API
|
|
34
|
+
import { Schema as GetBeatmaps } from "./api/getBeatmaps"
|
|
35
|
+
export { Schema as SchemaGetBeatmaps } from "./api/getBeatmaps"
|
|
36
|
+
export const getBeatmaps = handleApi({url:"/api/getBeatmaps",...GetBeatmaps})
|
|
37
|
+
|
|
33
38
|
// ./api/getLeaderboard.ts API
|
|
34
39
|
import { Schema as GetLeaderboard } from "./api/getLeaderboard"
|
|
35
40
|
export { Schema as SchemaGetLeaderboard } from "./api/getLeaderboard"
|