rhythia-api 135.0.0 → 136.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.
@@ -0,0 +1,97 @@
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
+ mapId: z.string(),
10
+ }),
11
+ output: z.object({
12
+ error: z.string().optional(),
13
+ beatmap: z
14
+ .object({
15
+ id: z.number().nullable().optional(),
16
+ nominations: z.array(z.number()).nullable().optional(),
17
+ playcount: z.number().nullable().optional(),
18
+ created_at: z.string().nullable().optional(),
19
+ difficulty: z.number().nullable().optional(),
20
+ noteCount: z.number().nullable().optional(),
21
+ length: z.number().nullable().optional(),
22
+ title: z.string().nullable().optional(),
23
+ ranked: z.boolean().nullable().optional(),
24
+ beatmapFile: z.string().nullable().optional(),
25
+ image: z.string().nullable().optional(),
26
+ starRating: z.number().nullable().optional(),
27
+ owner: z.number().nullable().optional(),
28
+ ownerUsername: z.string().nullable().optional(),
29
+ ownerAvatar: z.string().nullable().optional(),
30
+ status: z.string().nullable().optional(),
31
+ })
32
+ .optional(),
33
+ }),
34
+ };
35
+
36
+ export async function POST(request: Request): Promise<NextResponse> {
37
+ return protectedApi({
38
+ request,
39
+ schema: Schema,
40
+ authorization: () => {},
41
+ activity: handler,
42
+ });
43
+ }
44
+
45
+ export async function handler(
46
+ data: (typeof Schema)["input"]["_type"],
47
+ req: Request
48
+ ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
49
+ let { data: beatmapPage, error: errorlast } = await supabase
50
+ .from("beatmapPages")
51
+ .select(
52
+ `
53
+ *,
54
+ beatmaps (
55
+ created_at,
56
+ playcount,
57
+ length,
58
+ ranked,
59
+ beatmapFile,
60
+ image,
61
+ starRating,
62
+ difficulty,
63
+ noteCount,
64
+ title
65
+ ),
66
+ profiles (
67
+ username,
68
+ avatar_url
69
+ )
70
+ `
71
+ )
72
+ .eq("latestBeatmapHash", data.mapId)
73
+ .single();
74
+
75
+ if (!beatmapPage) return NextResponse.json({});
76
+
77
+ return NextResponse.json({
78
+ beatmap: {
79
+ playcount: beatmapPage.beatmaps?.playcount,
80
+ created_at: beatmapPage.created_at,
81
+ difficulty: beatmapPage.beatmaps?.difficulty,
82
+ noteCount: beatmapPage.beatmaps?.noteCount,
83
+ length: beatmapPage.beatmaps?.length,
84
+ title: beatmapPage.beatmaps?.title,
85
+ ranked: beatmapPage.beatmaps?.ranked,
86
+ beatmapFile: beatmapPage.beatmaps?.beatmapFile,
87
+ image: beatmapPage.beatmaps?.image,
88
+ starRating: beatmapPage.beatmaps?.starRating,
89
+ owner: beatmapPage.owner,
90
+ ownerUsername: beatmapPage.profiles?.username,
91
+ ownerAvatar: beatmapPage.profiles?.avatar_url,
92
+ id: beatmapPage.id,
93
+ status: beatmapPage.status,
94
+ nominations: beatmapPage.nominations as number[],
95
+ },
96
+ });
97
+ }
package/index.ts CHANGED
@@ -45,6 +45,11 @@ import { Schema as GetBeatmapPage } from "./api/getBeatmapPage"
45
45
  export { Schema as SchemaGetBeatmapPage } from "./api/getBeatmapPage"
46
46
  export const getBeatmapPage = handleApi({url:"/api/getBeatmapPage",...GetBeatmapPage})
47
47
 
48
+ // ./api/getBeatmapPageById.ts API
49
+ import { Schema as GetBeatmapPageById } from "./api/getBeatmapPageById"
50
+ export { Schema as SchemaGetBeatmapPageById } from "./api/getBeatmapPageById"
51
+ export const getBeatmapPageById = handleApi({url:"/api/getBeatmapPageById",...GetBeatmapPageById})
52
+
48
53
  // ./api/getBeatmaps.ts API
49
54
  import { Schema as GetBeatmaps } from "./api/getBeatmaps"
50
55
  export { Schema as SchemaGetBeatmaps } from "./api/getBeatmaps"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "135.0.0",
3
+ "version": "136.0.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "update": "bun ./scripts/update.ts",