rhythia-api 202.0.0 → 204.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.
@@ -197,13 +197,17 @@ export async function handler(
197
197
  .select();
198
198
  break;
199
199
  case "changeBadges":
200
- result = await supabase
201
- .from("profiles")
202
- .upsert({
203
- id: params.userId,
204
- badges: JSON.parse(params.badges),
205
- })
206
- .select();
200
+ // Allow only developers to modify badges.
201
+ if ((queryUserData.badges as string[]).includes("Developer")) {
202
+ result = await supabase
203
+ .from("profiles")
204
+ .upsert({
205
+ id: params.userId,
206
+ badges: JSON.parse(params.badges),
207
+ })
208
+ .select();
209
+ }
210
+
207
211
  break;
208
212
  }
209
213
 
@@ -0,0 +1,111 @@
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
+ const STORY_BEATMAPS = [
7
+ { id: 7623, requiresHardrock: true },
8
+ { id: 7031, requiresHardrock: false }
9
+ ];
10
+
11
+ export const Schema = {
12
+ input: z.strictObject({
13
+ session: z.string(),
14
+ }),
15
+ output: z.object({
16
+ error: z.string().optional(),
17
+ beatmaps: z
18
+ .array(
19
+ z.object({
20
+ id: z.number().nullable().optional(),
21
+ nominations: z.array(z.number()).nullable().optional(),
22
+ playcount: z.number().nullable().optional(),
23
+ created_at: z.string().nullable().optional(),
24
+ updated_at: z.number().nullable().optional(),
25
+ difficulty: z.number().nullable().optional(),
26
+ noteCount: z.number().nullable().optional(),
27
+ length: z.number().nullable().optional(),
28
+ title: z.string().nullable().optional(),
29
+ ranked: z.boolean().nullable().optional(),
30
+ beatmapFile: z.string().nullable().optional(),
31
+ image: z.string().nullable().optional(),
32
+ starRating: z.number().nullable().optional(),
33
+ owner: z.number().nullable().optional(),
34
+ ownerUsername: z.string().nullable().optional(),
35
+ ownerAvatar: z.string().nullable().optional(),
36
+ status: z.string().nullable().optional(),
37
+ requiresHardrock: z.boolean(),
38
+ })
39
+ )
40
+ .optional(),
41
+ }),
42
+ };
43
+
44
+ export async function POST(request: Request): Promise<NextResponse> {
45
+ return protectedApi({
46
+ request,
47
+ schema: Schema,
48
+ authorization: () => {},
49
+ activity: handler,
50
+ });
51
+ }
52
+
53
+ export async function handler(
54
+ data: (typeof Schema)["input"]["_type"],
55
+ req: Request
56
+ ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
57
+ const { data: beatmapPages, error } = await supabase
58
+ .from("beatmapPages")
59
+ .select(
60
+ `
61
+ *,
62
+ beatmaps (
63
+ created_at,
64
+ playcount,
65
+ length,
66
+ ranked,
67
+ beatmapFile,
68
+ image,
69
+ starRating,
70
+ difficulty,
71
+ noteCount,
72
+ title
73
+ ),
74
+ profiles (
75
+ username,
76
+ avatar_url
77
+ )
78
+ `
79
+ )
80
+ .in("id", STORY_BEATMAPS.map(sb => sb.id));
81
+
82
+ if (error) {
83
+ return NextResponse.json({ error: JSON.stringify(error) });
84
+ }
85
+
86
+ const beatmaps =
87
+ beatmapPages?.map((beatmapPage: any) => ({
88
+ playcount: beatmapPage.beatmaps?.playcount,
89
+ created_at: beatmapPage.created_at,
90
+ updated_at: beatmapPage.updated_at,
91
+ difficulty: beatmapPage.beatmaps?.difficulty,
92
+ noteCount: beatmapPage.beatmaps?.noteCount,
93
+ length: beatmapPage.beatmaps?.length,
94
+ title: beatmapPage.beatmaps?.title,
95
+ ranked: beatmapPage.beatmaps?.ranked,
96
+ beatmapFile: beatmapPage.beatmaps?.beatmapFile,
97
+ image: beatmapPage.beatmaps?.image,
98
+ starRating: beatmapPage.beatmaps?.starRating,
99
+ owner: beatmapPage.owner,
100
+ ownerUsername: beatmapPage.profiles?.username,
101
+ ownerAvatar: beatmapPage.profiles?.avatar_url,
102
+ id: beatmapPage.id,
103
+ status: beatmapPage.status,
104
+ nominations: beatmapPage.nominations as number[],
105
+ requiresHardrock: STORY_BEATMAPS.find(sb => sb.id === beatmapPage.id)?.requiresHardrock || false,
106
+ })) || [];
107
+
108
+ return NextResponse.json({
109
+ beatmaps,
110
+ });
111
+ }
package/index.ts CHANGED
@@ -994,6 +994,45 @@ import { Schema as GetScore } from "./api/getScore"
994
994
  export { Schema as SchemaGetScore } from "./api/getScore"
995
995
  export const getScore = handleApi({url:"/api/getScore",...GetScore})
996
996
 
997
+ // ./api/getStoryBeatmaps.ts API
998
+
999
+ /*
1000
+ export const Schema = {
1001
+ input: z.strictObject({
1002
+ session: z.string(),
1003
+ }),
1004
+ output: z.object({
1005
+ error: z.string().optional(),
1006
+ beatmaps: z
1007
+ .array(
1008
+ z.object({
1009
+ id: z.number().nullable().optional(),
1010
+ nominations: z.array(z.number()).nullable().optional(),
1011
+ playcount: z.number().nullable().optional(),
1012
+ created_at: z.string().nullable().optional(),
1013
+ updated_at: z.number().nullable().optional(),
1014
+ difficulty: z.number().nullable().optional(),
1015
+ noteCount: z.number().nullable().optional(),
1016
+ length: z.number().nullable().optional(),
1017
+ title: z.string().nullable().optional(),
1018
+ ranked: z.boolean().nullable().optional(),
1019
+ beatmapFile: z.string().nullable().optional(),
1020
+ image: z.string().nullable().optional(),
1021
+ starRating: z.number().nullable().optional(),
1022
+ owner: z.number().nullable().optional(),
1023
+ ownerUsername: z.string().nullable().optional(),
1024
+ ownerAvatar: z.string().nullable().optional(),
1025
+ status: z.string().nullable().optional(),
1026
+ requiresHardrock: z.boolean(),
1027
+ })
1028
+ )
1029
+ .optional(),
1030
+ }),
1031
+ };*/
1032
+ import { Schema as GetStoryBeatmaps } from "./api/getStoryBeatmaps"
1033
+ export { Schema as SchemaGetStoryBeatmaps } from "./api/getStoryBeatmaps"
1034
+ export const getStoryBeatmaps = handleApi({url:"/api/getStoryBeatmaps",...GetStoryBeatmaps})
1035
+
997
1036
  // ./api/getTimestamp.ts API
998
1037
 
999
1038
  /*
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "202.0.0",
3
+ "version": "204.0.0",
4
4
  "main": "index.ts",
5
5
  "author": "online-contributors-cunev",
6
6
  "scripts": {