rhythia-api 186.0.0 → 188.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.
Files changed (60) hide show
  1. package/.prettierrc.json +6 -6
  2. package/api/acceptInvite.ts +79 -0
  3. package/api/addCollectionMap.ts +82 -82
  4. package/api/approveMap.ts +78 -78
  5. package/api/chartPublicStats.ts +32 -32
  6. package/api/createBeatmap.ts +208 -168
  7. package/api/createBeatmapPage.ts +64 -64
  8. package/api/createClan.ts +81 -81
  9. package/api/createCollection.ts +58 -58
  10. package/api/createInvite.ts +66 -0
  11. package/api/deleteBeatmapPage.ts +77 -77
  12. package/api/deleteCollection.ts +59 -59
  13. package/api/deleteCollectionMap.ts +71 -71
  14. package/api/editAboutMe.ts +91 -91
  15. package/api/editClan.ts +90 -90
  16. package/api/editCollection.ts +77 -77
  17. package/api/editProfile.ts +123 -123
  18. package/api/getAvatarUploadUrl.ts +85 -85
  19. package/api/getBadgedUsers.ts +56 -56
  20. package/api/getBeatmapComments.ts +57 -57
  21. package/api/getBeatmapPage.ts +106 -106
  22. package/api/getBeatmapPageById.ts +99 -99
  23. package/api/getBeatmapStarRating.ts +53 -53
  24. package/api/getBeatmaps.ts +159 -159
  25. package/api/getClan.ts +77 -77
  26. package/api/getClans.ts +44 -0
  27. package/api/getCollection.ts +130 -130
  28. package/api/getCollections.ts +132 -132
  29. package/api/getLeaderboard.ts +136 -136
  30. package/api/getMapUploadUrl.ts +93 -93
  31. package/api/getPassToken.ts +55 -55
  32. package/api/getProfile.ts +146 -146
  33. package/api/getPublicStats.ts +180 -180
  34. package/api/getRawStarRating.ts +57 -57
  35. package/api/getScore.ts +85 -85
  36. package/api/getTimestamp.ts +23 -23
  37. package/api/getUserScores.ts +175 -175
  38. package/api/nominateMap.ts +82 -82
  39. package/api/postBeatmapComment.ts +62 -59
  40. package/api/rankMapsArchive.ts +64 -64
  41. package/api/searchUsers.ts +56 -56
  42. package/api/setPasskey.ts +59 -59
  43. package/api/submitScore.ts +433 -433
  44. package/api/updateBeatmapPage.ts +229 -229
  45. package/handleApi.ts +21 -20
  46. package/index.html +2 -2
  47. package/index.ts +914 -863
  48. package/package.json +5 -2
  49. package/types/database.ts +43 -0
  50. package/utils/getUserBySession.ts +48 -48
  51. package/utils/requestUtils.ts +87 -87
  52. package/utils/security.ts +20 -20
  53. package/utils/star-calc/index.ts +72 -72
  54. package/utils/star-calc/osuUtils.ts +53 -53
  55. package/utils/star-calc/sspmParser.ts +398 -398
  56. package/utils/star-calc/sspmv1Parser.ts +165 -165
  57. package/utils/supabase.ts +13 -13
  58. package/utils/test +4 -4
  59. package/utils/validateToken.ts +7 -7
  60. package/vercel.json +12 -12
@@ -1,123 +1,123 @@
1
- import { NextResponse } from "next/server";
2
- import z from "zod";
3
- import { Database } from "../types/database";
4
- import { protectedApi, validUser } from "../utils/requestUtils";
5
- import { supabase } from "../utils/supabase";
6
- import { getUserBySession } from "../utils/getUserBySession";
7
- import { User } from "@supabase/supabase-js";
8
- import validator from "validator";
9
- import removeZeroWidth from "zero-width";
10
-
11
- export const Schema = {
12
- input: z.strictObject({
13
- session: z.string(),
14
- data: z.object({
15
- avatar_url: z.string().optional(),
16
- profile_image: z.string().optional(),
17
- username: z.string().optional(),
18
- }),
19
- }),
20
- output: z.object({
21
- error: z.string().optional(),
22
- }),
23
- };
24
-
25
- export async function POST(request: Request): Promise<NextResponse> {
26
- return protectedApi({
27
- request,
28
- schema: Schema,
29
- authorization: validUser,
30
- activity: handler,
31
- });
32
- }
33
-
34
- export async function handler(
35
- data: (typeof Schema)["input"]["_type"]
36
- ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
37
- if (data.data.username !== undefined && data.data.username.length === 0) {
38
- return NextResponse.json(
39
- {
40
- error: "Username can't be empty",
41
- },
42
- { status: 404 }
43
- );
44
- }
45
-
46
- if (data.data.username && data.data.username.length > 20) {
47
- return NextResponse.json(
48
- {
49
- error: "Username too long.",
50
- },
51
- { status: 404 }
52
- );
53
- }
54
-
55
- if (validator.trim(data.data.username || "") !== (data.data.username || "")) {
56
- return NextResponse.json(
57
- {
58
- error: "Username can't start or end with spaces.",
59
- },
60
- { status: 404 }
61
- );
62
- }
63
-
64
- data.data.username = removeZeroWidth(data.data.username || "");
65
-
66
- const user = (await getUserBySession(data.session)) as User;
67
-
68
- let userData: Database["public"]["Tables"]["profiles"]["Update"];
69
-
70
- // Find user's entry
71
- {
72
- let { data: queryUserData, error } = await supabase
73
- .from("profiles")
74
- .select("*")
75
- .eq("uid", user.id);
76
-
77
- if (!queryUserData?.length) {
78
- return NextResponse.json(
79
- {
80
- error: "User cannot be retrieved from session",
81
- },
82
- { status: 404 }
83
- );
84
- }
85
- userData = queryUserData[0];
86
- }
87
-
88
- if (
89
- userData.ban == "excluded" ||
90
- userData.ban == "restricted" ||
91
- userData.ban == "silenced"
92
- ) {
93
- return NextResponse.json(
94
- {
95
- error:
96
- "Silenced, restricted or excluded players can't update their profile.",
97
- },
98
- { status: 404 }
99
- );
100
- }
101
-
102
- const upsertPayload: Database["public"]["Tables"]["profiles"]["Update"] = {
103
- id: userData.id,
104
- computedUsername: data.data.username?.toLowerCase(),
105
- ...data.data,
106
- };
107
-
108
- const upsertResult = await supabase
109
- .from("profiles")
110
- .upsert(upsertPayload)
111
- .select();
112
-
113
- if (upsertResult.error) {
114
- return NextResponse.json(
115
- {
116
- error: "Can't update, username might be used by someone else!",
117
- },
118
- { status: 404 }
119
- );
120
- }
121
-
122
- return NextResponse.json({});
123
- }
1
+ import { NextResponse } from "next/server";
2
+ import z from "zod";
3
+ import { Database } from "../types/database";
4
+ import { protectedApi, validUser } from "../utils/requestUtils";
5
+ import { supabase } from "../utils/supabase";
6
+ import { getUserBySession } from "../utils/getUserBySession";
7
+ import { User } from "@supabase/supabase-js";
8
+ import validator from "validator";
9
+ import removeZeroWidth from "zero-width";
10
+
11
+ export const Schema = {
12
+ input: z.strictObject({
13
+ session: z.string(),
14
+ data: z.object({
15
+ avatar_url: z.string().optional(),
16
+ profile_image: z.string().optional(),
17
+ username: z.string().optional(),
18
+ }),
19
+ }),
20
+ output: z.object({
21
+ error: z.string().optional(),
22
+ }),
23
+ };
24
+
25
+ export async function POST(request: Request): Promise<NextResponse> {
26
+ return protectedApi({
27
+ request,
28
+ schema: Schema,
29
+ authorization: validUser,
30
+ activity: handler,
31
+ });
32
+ }
33
+
34
+ export async function handler(
35
+ data: (typeof Schema)["input"]["_type"]
36
+ ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
37
+ if (data.data.username !== undefined && data.data.username.length === 0) {
38
+ return NextResponse.json(
39
+ {
40
+ error: "Username can't be empty",
41
+ },
42
+ { status: 404 }
43
+ );
44
+ }
45
+
46
+ if (data.data.username && data.data.username.length > 20) {
47
+ return NextResponse.json(
48
+ {
49
+ error: "Username too long.",
50
+ },
51
+ { status: 404 }
52
+ );
53
+ }
54
+
55
+ if (validator.trim(data.data.username || "") !== (data.data.username || "")) {
56
+ return NextResponse.json(
57
+ {
58
+ error: "Username can't start or end with spaces.",
59
+ },
60
+ { status: 404 }
61
+ );
62
+ }
63
+
64
+ data.data.username = removeZeroWidth(data.data.username || "");
65
+
66
+ const user = (await getUserBySession(data.session)) as User;
67
+
68
+ let userData: Database["public"]["Tables"]["profiles"]["Update"];
69
+
70
+ // Find user's entry
71
+ {
72
+ let { data: queryUserData, error } = await supabase
73
+ .from("profiles")
74
+ .select("*")
75
+ .eq("uid", user.id);
76
+
77
+ if (!queryUserData?.length) {
78
+ return NextResponse.json(
79
+ {
80
+ error: "User cannot be retrieved from session",
81
+ },
82
+ { status: 404 }
83
+ );
84
+ }
85
+ userData = queryUserData[0];
86
+ }
87
+
88
+ if (
89
+ userData.ban == "excluded" ||
90
+ userData.ban == "restricted" ||
91
+ userData.ban == "silenced"
92
+ ) {
93
+ return NextResponse.json(
94
+ {
95
+ error:
96
+ "Silenced, restricted or excluded players can't update their profile.",
97
+ },
98
+ { status: 404 }
99
+ );
100
+ }
101
+
102
+ const upsertPayload: Database["public"]["Tables"]["profiles"]["Update"] = {
103
+ id: userData.id,
104
+ computedUsername: data.data.username?.toLowerCase(),
105
+ ...data.data,
106
+ };
107
+
108
+ const upsertResult = await supabase
109
+ .from("profiles")
110
+ .upsert(upsertPayload)
111
+ .select();
112
+
113
+ if (upsertResult.error) {
114
+ return NextResponse.json(
115
+ {
116
+ error: "Can't update, username might be used by someone else!",
117
+ },
118
+ { status: 404 }
119
+ );
120
+ }
121
+
122
+ return NextResponse.json({});
123
+ }
@@ -1,85 +1,85 @@
1
- import { NextResponse } from "next/server";
2
- import z from "zod";
3
- import { protectedApi, validUser } from "../utils/requestUtils";
4
- import { supabase } from "../utils/supabase";
5
-
6
- import {
7
- PutBucketCorsCommand,
8
- PutObjectCommand,
9
- S3Client,
10
- } from "@aws-sdk/client-s3";
11
- import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
12
- import { validateIntrinsicToken } from "../utils/validateToken";
13
- import { getUserBySession } from "../utils/getUserBySession";
14
- import { User } from "@supabase/supabase-js";
15
-
16
- const s3Client = new S3Client({
17
- region: "auto",
18
- endpoint: "https://s3.eu-central-003.backblazeb2.com",
19
- credentials: {
20
- secretAccessKey: process.env.SECRET_BUCKET || "",
21
- accessKeyId: process.env.ACCESS_BUCKET || "",
22
- },
23
- });
24
-
25
- export const Schema = {
26
- input: z.strictObject({
27
- session: z.string(),
28
- contentLength: z.number(),
29
- contentType: z.string(),
30
- intrinsicToken: z.string(),
31
- }),
32
- output: z.strictObject({
33
- error: z.string().optional(),
34
- url: z.string().optional(),
35
- objectKey: z.string().optional(),
36
- }),
37
- };
38
-
39
- export async function POST(request: Request): Promise<NextResponse> {
40
- return protectedApi({
41
- request,
42
- schema: Schema,
43
- authorization: validUser,
44
- activity: handler,
45
- });
46
- }
47
-
48
- export async function handler({
49
- session,
50
- contentLength,
51
- contentType,
52
- intrinsicToken,
53
- }: (typeof Schema)["input"]["_type"]): Promise<
54
- NextResponse<(typeof Schema)["output"]["_type"]>
55
- > {
56
- const user = (await getUserBySession(session)) as User;
57
-
58
- if (!validateIntrinsicToken(intrinsicToken)) {
59
- return NextResponse.json({
60
- error: "Invalid intrinsic token",
61
- });
62
- }
63
-
64
- if (contentLength > 5000000) {
65
- return NextResponse.json({
66
- error: "Max content length exceeded.",
67
- });
68
- }
69
-
70
- const key = `user-avatar-${Date.now()}-${user.id}`;
71
- const command = new PutObjectCommand({
72
- Bucket: "rhthia-avatars",
73
- Key: key,
74
- ContentLength: contentLength,
75
- ContentType: contentType,
76
- });
77
-
78
- const presigned = await getSignedUrl(s3Client, command, {
79
- expiresIn: 3600,
80
- });
81
- return NextResponse.json({
82
- url: presigned,
83
- objectKey: key,
84
- });
85
- }
1
+ import { NextResponse } from "next/server";
2
+ import z from "zod";
3
+ import { protectedApi, validUser } from "../utils/requestUtils";
4
+ import { supabase } from "../utils/supabase";
5
+
6
+ import {
7
+ PutBucketCorsCommand,
8
+ PutObjectCommand,
9
+ S3Client,
10
+ } from "@aws-sdk/client-s3";
11
+ import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
12
+ import { validateIntrinsicToken } from "../utils/validateToken";
13
+ import { getUserBySession } from "../utils/getUserBySession";
14
+ import { User } from "@supabase/supabase-js";
15
+
16
+ const s3Client = new S3Client({
17
+ region: "auto",
18
+ endpoint: "https://s3.eu-central-003.backblazeb2.com",
19
+ credentials: {
20
+ secretAccessKey: process.env.SECRET_BUCKET || "",
21
+ accessKeyId: process.env.ACCESS_BUCKET || "",
22
+ },
23
+ });
24
+
25
+ export const Schema = {
26
+ input: z.strictObject({
27
+ session: z.string(),
28
+ contentLength: z.number(),
29
+ contentType: z.string(),
30
+ intrinsicToken: z.string(),
31
+ }),
32
+ output: z.strictObject({
33
+ error: z.string().optional(),
34
+ url: z.string().optional(),
35
+ objectKey: z.string().optional(),
36
+ }),
37
+ };
38
+
39
+ export async function POST(request: Request): Promise<NextResponse> {
40
+ return protectedApi({
41
+ request,
42
+ schema: Schema,
43
+ authorization: validUser,
44
+ activity: handler,
45
+ });
46
+ }
47
+
48
+ export async function handler({
49
+ session,
50
+ contentLength,
51
+ contentType,
52
+ intrinsicToken,
53
+ }: (typeof Schema)["input"]["_type"]): Promise<
54
+ NextResponse<(typeof Schema)["output"]["_type"]>
55
+ > {
56
+ const user = (await getUserBySession(session)) as User;
57
+
58
+ if (!validateIntrinsicToken(intrinsicToken)) {
59
+ return NextResponse.json({
60
+ error: "Invalid intrinsic token",
61
+ });
62
+ }
63
+
64
+ if (contentLength > 5000000) {
65
+ return NextResponse.json({
66
+ error: "Max content length exceeded.",
67
+ });
68
+ }
69
+
70
+ const key = `user-avatar-${Date.now()}-${user.id}`;
71
+ const command = new PutObjectCommand({
72
+ Bucket: "rhthia-avatars",
73
+ Key: key,
74
+ ContentLength: contentLength,
75
+ ContentType: contentType,
76
+ });
77
+
78
+ const presigned = await getSignedUrl(s3Client, command, {
79
+ expiresIn: 3600,
80
+ });
81
+ return NextResponse.json({
82
+ url: presigned,
83
+ objectKey: key,
84
+ });
85
+ }
@@ -1,56 +1,56 @@
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
- badge: z.string(),
9
- }),
10
- output: z.object({
11
- error: z.string().optional(),
12
- leaderboard: z
13
- .array(
14
- z.object({
15
- flag: z.string().nullable(),
16
- id: z.number(),
17
- username: z.string().nullable(),
18
- })
19
- )
20
- .optional(),
21
- }),
22
- };
23
-
24
- export async function POST(request: Request): Promise<NextResponse> {
25
- return protectedApi({
26
- request,
27
- schema: Schema,
28
- authorization: () => {},
29
- activity: handler,
30
- });
31
- }
32
-
33
- export async function handler(
34
- data: (typeof Schema)["input"]["_type"]
35
- ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
36
- const result = await getLeaderboard(data.badge);
37
- return NextResponse.json(result);
38
- }
39
-
40
- export async function getLeaderboard(badge: string) {
41
- let { data: queryData, error } = await supabase
42
- .from("profiles")
43
- .select("flag,id,username,badges");
44
-
45
- const users = queryData?.filter((e) =>
46
- ((e.badges || []) as string[]).includes(badge)
47
- );
48
-
49
- return {
50
- leaderboard: users?.map((user) => ({
51
- flag: user.flag,
52
- id: user.id,
53
- username: user.username,
54
- })),
55
- };
56
- }
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
+ badge: z.string(),
9
+ }),
10
+ output: z.object({
11
+ error: z.string().optional(),
12
+ leaderboard: z
13
+ .array(
14
+ z.object({
15
+ flag: z.string().nullable(),
16
+ id: z.number(),
17
+ username: z.string().nullable(),
18
+ })
19
+ )
20
+ .optional(),
21
+ }),
22
+ };
23
+
24
+ export async function POST(request: Request): Promise<NextResponse> {
25
+ return protectedApi({
26
+ request,
27
+ schema: Schema,
28
+ authorization: () => {},
29
+ activity: handler,
30
+ });
31
+ }
32
+
33
+ export async function handler(
34
+ data: (typeof Schema)["input"]["_type"]
35
+ ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
36
+ const result = await getLeaderboard(data.badge);
37
+ return NextResponse.json(result);
38
+ }
39
+
40
+ export async function getLeaderboard(badge: string) {
41
+ let { data: queryData, error } = await supabase
42
+ .from("profiles")
43
+ .select("flag,id,username,badges");
44
+
45
+ const users = queryData?.filter((e) =>
46
+ ((e.badges || []) as string[]).includes(badge)
47
+ );
48
+
49
+ return {
50
+ leaderboard: users?.map((user) => ({
51
+ flag: user.flag,
52
+ id: user.id,
53
+ username: user.username,
54
+ })),
55
+ };
56
+ }
@@ -1,57 +1,57 @@
1
- import { NextResponse } from "next/server";
2
- import z from "zod";
3
- import { protectedApi, validUser } from "../utils/requestUtils";
4
- import { supabase } from "../utils/supabase";
5
-
6
- export const Schema = {
7
- input: z.strictObject({
8
- page: z.number(),
9
- }),
10
- output: z.strictObject({
11
- error: z.string().optional(),
12
- comments: z.array(
13
- z.object({
14
- beatmapPage: z.number(),
15
- content: z.string().nullable(),
16
- owner: z.number(),
17
- created_at: z.string(),
18
- profiles: z.object({
19
- avatar_url: z.string().nullable(),
20
- username: z.string().nullable(),
21
- badges: z.any().nullable(),
22
- }),
23
- })
24
- ),
25
- }),
26
- };
27
-
28
- export async function POST(request: Request): Promise<NextResponse> {
29
- return protectedApi({
30
- request,
31
- schema: Schema,
32
- authorization: () => {},
33
- activity: handler,
34
- });
35
- }
36
-
37
- export async function handler({
38
- page,
39
- }: (typeof Schema)["input"]["_type"]): Promise<
40
- NextResponse<(typeof Schema)["output"]["_type"]>
41
- > {
42
- let { data: userData, error: userError } = await supabase
43
- .from("beatmapPageComments")
44
- .select(
45
- `
46
- *,
47
- profiles!inner(
48
- username,
49
- avatar_url,
50
- badges
51
- )
52
- `
53
- )
54
- .eq("beatmapPage", page);
55
-
56
- return NextResponse.json({ comments: userData! });
57
- }
1
+ import { NextResponse } from "next/server";
2
+ import z from "zod";
3
+ import { protectedApi, validUser } from "../utils/requestUtils";
4
+ import { supabase } from "../utils/supabase";
5
+
6
+ export const Schema = {
7
+ input: z.strictObject({
8
+ page: z.number(),
9
+ }),
10
+ output: z.strictObject({
11
+ error: z.string().optional(),
12
+ comments: z.array(
13
+ z.object({
14
+ beatmapPage: z.number(),
15
+ content: z.string().nullable(),
16
+ owner: z.number(),
17
+ created_at: z.string(),
18
+ profiles: z.object({
19
+ avatar_url: z.string().nullable(),
20
+ username: z.string().nullable(),
21
+ badges: z.any().nullable(),
22
+ }),
23
+ })
24
+ ),
25
+ }),
26
+ };
27
+
28
+ export async function POST(request: Request): Promise<NextResponse> {
29
+ return protectedApi({
30
+ request,
31
+ schema: Schema,
32
+ authorization: () => {},
33
+ activity: handler,
34
+ });
35
+ }
36
+
37
+ export async function handler({
38
+ page,
39
+ }: (typeof Schema)["input"]["_type"]): Promise<
40
+ NextResponse<(typeof Schema)["output"]["_type"]>
41
+ > {
42
+ let { data: userData, error: userError } = await supabase
43
+ .from("beatmapPageComments")
44
+ .select(
45
+ `
46
+ *,
47
+ profiles!inner(
48
+ username,
49
+ avatar_url,
50
+ badges
51
+ )
52
+ `
53
+ )
54
+ .eq("beatmapPage", page);
55
+
56
+ return NextResponse.json({ comments: userData! });
57
+ }