rhythia-api 183.0.0 → 184.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 (58) hide show
  1. package/.prettierrc.json +6 -6
  2. package/api/addCollectionMap.ts +82 -82
  3. package/api/approveMap.ts +78 -78
  4. package/api/chartPublicStats.ts +32 -32
  5. package/api/createBeatmap.ts +168 -168
  6. package/api/createBeatmapPage.ts +64 -64
  7. package/api/createClan.ts +81 -81
  8. package/api/createCollection.ts +58 -58
  9. package/api/deleteBeatmapPage.ts +77 -77
  10. package/api/deleteCollection.ts +59 -59
  11. package/api/deleteCollectionMap.ts +71 -71
  12. package/api/editAboutMe.ts +91 -91
  13. package/api/editClan.ts +90 -90
  14. package/api/editCollection.ts +77 -77
  15. package/api/editProfile.ts +123 -123
  16. package/api/getAvatarUploadUrl.ts +85 -85
  17. package/api/getBadgedUsers.ts +56 -56
  18. package/api/getBeatmapComments.ts +57 -57
  19. package/api/getBeatmapPage.ts +106 -106
  20. package/api/getBeatmapPageById.ts +99 -99
  21. package/api/getBeatmapStarRating.ts +53 -53
  22. package/api/getBeatmaps.ts +159 -159
  23. package/api/getClan.ts +77 -77
  24. package/api/getCollection.ts +130 -130
  25. package/api/getCollections.ts +126 -128
  26. package/api/getLeaderboard.ts +136 -136
  27. package/api/getMapUploadUrl.ts +93 -93
  28. package/api/getPassToken.ts +55 -55
  29. package/api/getProfile.ts +146 -146
  30. package/api/getPublicStats.ts +180 -180
  31. package/api/getRawStarRating.ts +57 -57
  32. package/api/getScore.ts +85 -85
  33. package/api/getTimestamp.ts +23 -23
  34. package/api/getUserScores.ts +175 -175
  35. package/api/nominateMap.ts +82 -82
  36. package/api/postBeatmapComment.ts +59 -59
  37. package/api/rankMapsArchive.ts +64 -64
  38. package/api/searchUsers.ts +56 -56
  39. package/api/setPasskey.ts +59 -59
  40. package/api/submitScore.ts +433 -433
  41. package/api/updateBeatmapPage.ts +229 -229
  42. package/handleApi.ts +22 -20
  43. package/index.html +2 -2
  44. package/index.ts +864 -865
  45. package/package-lock.json +8913 -0
  46. package/package.json +2 -2
  47. package/types/database.ts +0 -39
  48. package/utils/getUserBySession.ts +48 -48
  49. package/utils/requestUtils.ts +87 -87
  50. package/utils/security.ts +20 -20
  51. package/utils/star-calc/index.ts +72 -72
  52. package/utils/star-calc/osuUtils.ts +53 -53
  53. package/utils/star-calc/sspmParser.ts +398 -398
  54. package/utils/star-calc/sspmv1Parser.ts +165 -165
  55. package/utils/supabase.ts +13 -13
  56. package/utils/test +4 -4
  57. package/utils/validateToken.ts +7 -7
  58. package/vercel.json +12 -12
@@ -1,91 +1,91 @@
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
- export const Schema = {
9
- input: z.strictObject({
10
- session: z.string(),
11
- data: z.object({
12
- about_me: z.string().optional(),
13
- }),
14
- }),
15
- output: z.object({
16
- error: z.string().optional(),
17
- }),
18
- };
19
-
20
- export async function POST(request: Request): Promise<NextResponse> {
21
- return protectedApi({
22
- request,
23
- schema: Schema,
24
- authorization: validUser,
25
- activity: handler,
26
- });
27
- }
28
-
29
- export async function handler(
30
- data: (typeof Schema)["input"]["_type"]
31
- ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
32
- if (!data.data.about_me) {
33
- return NextResponse.json(
34
- {
35
- error: "Missing body.",
36
- },
37
- { status: 404 }
38
- );
39
- }
40
-
41
- if (data.data.about_me.length > 10000) {
42
- return NextResponse.json(
43
- {
44
- error: "Too long.",
45
- },
46
- { status: 404 }
47
- );
48
- }
49
-
50
- const user = (await getUserBySession(data.session)) as User;
51
- let userData: Database["public"]["Tables"]["profiles"]["Update"];
52
-
53
- // Find user's entry
54
- {
55
- let { data: queryUserData, error } = await supabase
56
- .from("profiles")
57
- .select("*")
58
- .eq("uid", user.id);
59
-
60
- if (!queryUserData?.length) {
61
- return NextResponse.json(
62
- {
63
- error: "User cannot be retrieved from session",
64
- },
65
- { status: 404 }
66
- );
67
- }
68
- userData = queryUserData[0];
69
- }
70
-
71
- const upsertPayload: Database["public"]["Tables"]["profiles"]["Update"] = {
72
- id: userData.id,
73
- about_me: data.data.about_me,
74
- };
75
-
76
- const upsertResult = await supabase
77
- .from("profiles")
78
- .upsert(upsertPayload)
79
- .select();
80
-
81
- if (upsertResult.error) {
82
- return NextResponse.json(
83
- {
84
- error: "Can't update..",
85
- },
86
- { status: 404 }
87
- );
88
- }
89
-
90
- return NextResponse.json({});
91
- }
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
+ export const Schema = {
9
+ input: z.strictObject({
10
+ session: z.string(),
11
+ data: z.object({
12
+ about_me: z.string().optional(),
13
+ }),
14
+ }),
15
+ output: z.object({
16
+ error: z.string().optional(),
17
+ }),
18
+ };
19
+
20
+ export async function POST(request: Request): Promise<NextResponse> {
21
+ return protectedApi({
22
+ request,
23
+ schema: Schema,
24
+ authorization: validUser,
25
+ activity: handler,
26
+ });
27
+ }
28
+
29
+ export async function handler(
30
+ data: (typeof Schema)["input"]["_type"]
31
+ ): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
32
+ if (!data.data.about_me) {
33
+ return NextResponse.json(
34
+ {
35
+ error: "Missing body.",
36
+ },
37
+ { status: 404 }
38
+ );
39
+ }
40
+
41
+ if (data.data.about_me.length > 10000) {
42
+ return NextResponse.json(
43
+ {
44
+ error: "Too long.",
45
+ },
46
+ { status: 404 }
47
+ );
48
+ }
49
+
50
+ const user = (await getUserBySession(data.session)) as User;
51
+ let userData: Database["public"]["Tables"]["profiles"]["Update"];
52
+
53
+ // Find user's entry
54
+ {
55
+ let { data: queryUserData, error } = await supabase
56
+ .from("profiles")
57
+ .select("*")
58
+ .eq("uid", user.id);
59
+
60
+ if (!queryUserData?.length) {
61
+ return NextResponse.json(
62
+ {
63
+ error: "User cannot be retrieved from session",
64
+ },
65
+ { status: 404 }
66
+ );
67
+ }
68
+ userData = queryUserData[0];
69
+ }
70
+
71
+ const upsertPayload: Database["public"]["Tables"]["profiles"]["Update"] = {
72
+ id: userData.id,
73
+ about_me: data.data.about_me,
74
+ };
75
+
76
+ const upsertResult = await supabase
77
+ .from("profiles")
78
+ .upsert(upsertPayload)
79
+ .select();
80
+
81
+ if (upsertResult.error) {
82
+ return NextResponse.json(
83
+ {
84
+ error: "Can't update..",
85
+ },
86
+ { status: 404 }
87
+ );
88
+ }
89
+
90
+ return NextResponse.json({});
91
+ }
package/api/editClan.ts CHANGED
@@ -1,90 +1,90 @@
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
- import { getUserBySession } from "../utils/getUserBySession";
6
- import { User } from "@supabase/supabase-js";
7
-
8
- export const Schema = {
9
- input: z.strictObject({
10
- session: z.string(),
11
- id: z.number(),
12
- name: z.string(),
13
- avatar_url: z.string(),
14
- description: z.string(),
15
- acronym: z.string(),
16
- }),
17
- output: z.object({
18
- error: z.string().optional(),
19
- }),
20
- };
21
-
22
- export async function POST(request: Request) {
23
- return protectedApi({
24
- request,
25
- schema: Schema,
26
- authorization: validUser,
27
- activity: handler,
28
- });
29
- }
30
-
31
- export async function handler(data: (typeof Schema)["input"]["_type"]) {
32
- const user = (await getUserBySession(data.session)) as User;
33
- let { data: queryUserData, error: userError } = await supabase
34
- .from("profiles")
35
- .select("*")
36
- .eq("uid", user.id)
37
- .single();
38
-
39
- if (!queryUserData) {
40
- return NextResponse.json({ error: "Can't find user" });
41
- }
42
-
43
- let { data: queryClanData, error: clanError } = await supabase
44
- .from("clans")
45
- .select("*")
46
- .eq("id", data.id)
47
- .single();
48
-
49
- if (!queryClanData) {
50
- return NextResponse.json({ error: "No such clan ID" });
51
- }
52
-
53
- if (queryClanData.owner !== queryUserData.id) {
54
- return NextResponse.json({ error: "You are not the owner" });
55
- }
56
-
57
- if (queryUserData.ban !== "cool") {
58
- return NextResponse.json({
59
- error: "You are have an active ban, can't edit a clan.",
60
- });
61
- }
62
-
63
- if (data.name.length < 3 || data.name.length > 32) {
64
- return NextResponse.json({
65
- error: "Clan name must be between 3 and 32 characters.",
66
- });
67
- }
68
-
69
- if (data.acronym.length < 3 || data.acronym.length > 6) {
70
- return NextResponse.json({
71
- error: "Acronyms must be of length between 3 and 6",
72
- });
73
- }
74
-
75
- if (data.description.length > 24000) {
76
- return NextResponse.json({
77
- error: "Description length exceeds 24000 characters",
78
- });
79
- }
80
-
81
- await supabase.from("clans").upsert({
82
- id: data.id,
83
- name: data.name,
84
- avatar_url: data.avatar_url,
85
- description: data.description,
86
- acronym: data.acronym.toUpperCase(),
87
- });
88
-
89
- return NextResponse.json({});
90
- }
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
+ import { getUserBySession } from "../utils/getUserBySession";
6
+ import { User } from "@supabase/supabase-js";
7
+
8
+ export const Schema = {
9
+ input: z.strictObject({
10
+ session: z.string(),
11
+ id: z.number(),
12
+ name: z.string(),
13
+ avatar_url: z.string(),
14
+ description: z.string(),
15
+ acronym: z.string(),
16
+ }),
17
+ output: z.object({
18
+ error: z.string().optional(),
19
+ }),
20
+ };
21
+
22
+ export async function POST(request: Request) {
23
+ return protectedApi({
24
+ request,
25
+ schema: Schema,
26
+ authorization: validUser,
27
+ activity: handler,
28
+ });
29
+ }
30
+
31
+ export async function handler(data: (typeof Schema)["input"]["_type"]) {
32
+ const user = (await getUserBySession(data.session)) as User;
33
+ let { data: queryUserData, error: userError } = await supabase
34
+ .from("profiles")
35
+ .select("*")
36
+ .eq("uid", user.id)
37
+ .single();
38
+
39
+ if (!queryUserData) {
40
+ return NextResponse.json({ error: "Can't find user" });
41
+ }
42
+
43
+ let { data: queryClanData, error: clanError } = await supabase
44
+ .from("clans")
45
+ .select("*")
46
+ .eq("id", data.id)
47
+ .single();
48
+
49
+ if (!queryClanData) {
50
+ return NextResponse.json({ error: "No such clan ID" });
51
+ }
52
+
53
+ if (queryClanData.owner !== queryUserData.id) {
54
+ return NextResponse.json({ error: "You are not the owner" });
55
+ }
56
+
57
+ if (queryUserData.ban !== "cool") {
58
+ return NextResponse.json({
59
+ error: "You are have an active ban, can't edit a clan.",
60
+ });
61
+ }
62
+
63
+ if (data.name.length < 3 || data.name.length > 32) {
64
+ return NextResponse.json({
65
+ error: "Clan name must be between 3 and 32 characters.",
66
+ });
67
+ }
68
+
69
+ if (data.acronym.length < 3 || data.acronym.length > 6) {
70
+ return NextResponse.json({
71
+ error: "Acronyms must be of length between 3 and 6",
72
+ });
73
+ }
74
+
75
+ if (data.description.length > 24000) {
76
+ return NextResponse.json({
77
+ error: "Description length exceeds 24000 characters",
78
+ });
79
+ }
80
+
81
+ await supabase.from("clans").upsert({
82
+ id: data.id,
83
+ name: data.name,
84
+ avatar_url: data.avatar_url,
85
+ description: data.description,
86
+ acronym: data.acronym.toUpperCase(),
87
+ });
88
+
89
+ return NextResponse.json({});
90
+ }
@@ -1,77 +1,77 @@
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
- import { getUserBySession } from "../utils/getUserBySession";
6
- import { User } from "@supabase/supabase-js";
7
- import { describe } from "node:test";
8
-
9
- export const Schema = {
10
- input: z.strictObject({
11
- session: z.string(),
12
- collection: z.number(),
13
- title: z.string(),
14
- description: z.string(),
15
- isList: z.boolean(),
16
- }),
17
- output: z.object({
18
- error: z.string().optional(),
19
- }),
20
- };
21
-
22
- export async function POST(request: Request) {
23
- return protectedApi({
24
- request,
25
- schema: Schema,
26
- authorization: validUser,
27
- activity: handler,
28
- });
29
- }
30
-
31
- export async function handler(data: (typeof Schema)["input"]["_type"]) {
32
- const user = (await getUserBySession(data.session)) as User;
33
- let { data: queryUserData, error: userError } = await supabase
34
- .from("profiles")
35
- .select("*")
36
- .eq("uid", user.id)
37
- .single();
38
-
39
- if (!queryUserData) {
40
- return NextResponse.json({ error: "Can't find user" });
41
- }
42
-
43
- let { data: queryCollectionData, error: collectionError } = await supabase
44
- .from("beatmapCollections")
45
- .select("*")
46
- .eq("id", data.collection)
47
- .single();
48
-
49
- if (!queryCollectionData) {
50
- return NextResponse.json({ error: "Can't find collection" });
51
- }
52
-
53
- if (queryCollectionData.owner !== queryUserData.id) {
54
- return NextResponse.json({ error: "You can't update foreign collections" });
55
- }
56
-
57
- if (data.title.length < 3) {
58
- return NextResponse.json({
59
- error: "Collection title should be longer than 3",
60
- });
61
- }
62
-
63
- if (data.description.length > 128) {
64
- return NextResponse.json({
65
- error: "Description too long",
66
- });
67
- }
68
-
69
- await supabase.from("beatmapCollections").upsert({
70
- id: data.collection,
71
- title: data.title,
72
- description: data.description,
73
- is_list: data.isList,
74
- owner: queryUserData.id,
75
- });
76
- return NextResponse.json({});
77
- }
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
+ import { getUserBySession } from "../utils/getUserBySession";
6
+ import { User } from "@supabase/supabase-js";
7
+ import { describe } from "node:test";
8
+
9
+ export const Schema = {
10
+ input: z.strictObject({
11
+ session: z.string(),
12
+ collection: z.number(),
13
+ title: z.string(),
14
+ description: z.string(),
15
+ isList: z.boolean(),
16
+ }),
17
+ output: z.object({
18
+ error: z.string().optional(),
19
+ }),
20
+ };
21
+
22
+ export async function POST(request: Request) {
23
+ return protectedApi({
24
+ request,
25
+ schema: Schema,
26
+ authorization: validUser,
27
+ activity: handler,
28
+ });
29
+ }
30
+
31
+ export async function handler(data: (typeof Schema)["input"]["_type"]) {
32
+ const user = (await getUserBySession(data.session)) as User;
33
+ let { data: queryUserData, error: userError } = await supabase
34
+ .from("profiles")
35
+ .select("*")
36
+ .eq("uid", user.id)
37
+ .single();
38
+
39
+ if (!queryUserData) {
40
+ return NextResponse.json({ error: "Can't find user" });
41
+ }
42
+
43
+ let { data: queryCollectionData, error: collectionError } = await supabase
44
+ .from("beatmapCollections")
45
+ .select("*")
46
+ .eq("id", data.collection)
47
+ .single();
48
+
49
+ if (!queryCollectionData) {
50
+ return NextResponse.json({ error: "Can't find collection" });
51
+ }
52
+
53
+ if (queryCollectionData.owner !== queryUserData.id) {
54
+ return NextResponse.json({ error: "You can't update foreign collections" });
55
+ }
56
+
57
+ if (data.title.length < 3) {
58
+ return NextResponse.json({
59
+ error: "Collection title should be longer than 3",
60
+ });
61
+ }
62
+
63
+ if (data.description.length > 128) {
64
+ return NextResponse.json({
65
+ error: "Description too long",
66
+ });
67
+ }
68
+
69
+ await supabase.from("beatmapCollections").upsert({
70
+ id: data.collection,
71
+ title: data.title,
72
+ description: data.description,
73
+ is_list: data.isList,
74
+ owner: queryUserData.id,
75
+ });
76
+ return NextResponse.json({});
77
+ }