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,82 +1,82 @@
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
- mapId: z.number(),
12
- }),
13
- output: z.object({
14
- error: z.string().optional(),
15
- }),
16
- };
17
-
18
- export async function POST(request: Request) {
19
- return protectedApi({
20
- request,
21
- schema: Schema,
22
- authorization: validUser,
23
- activity: handler,
24
- });
25
- }
26
-
27
- export async function handler(data: (typeof Schema)["input"]["_type"]) {
28
- const user = (await getUserBySession(data.session)) as User;
29
- let { data: queryUserData, error: userError } = await supabase
30
- .from("profiles")
31
- .select("*")
32
- .eq("uid", user.id)
33
- .single();
34
-
35
- if (!queryUserData) {
36
- return NextResponse.json({ error: "Can't find user" });
37
- }
38
-
39
- const tags = (queryUserData?.badges || []) as string[];
40
-
41
- if (!tags.includes("RCT")) {
42
- return NextResponse.json({ error: "Only RCTs can nominate maps!" });
43
- }
44
-
45
- const { data: mapData, error } = await supabase
46
- .from("beatmapPages")
47
- .select("id,nominations,owner")
48
- .eq("id", data.mapId)
49
- .single();
50
-
51
- if (!mapData) {
52
- return NextResponse.json({ error: "Bad map" });
53
- }
54
-
55
- if (mapData.owner == queryUserData.id) {
56
- return NextResponse.json({ error: "Can't nominate own map" });
57
- }
58
-
59
- if ((mapData.nominations as number[]).includes(queryUserData.id)) {
60
- return NextResponse.json({ error: "Already nominated" });
61
- }
62
-
63
- const newNominations = [
64
- ...(mapData.nominations! as number[]),
65
- queryUserData.id,
66
- ];
67
- if (newNominations.length == 2) {
68
- await supabase.from("beatmapPages").upsert({
69
- id: data.mapId,
70
- nominations: newNominations,
71
- status: "RANKED",
72
- ranked_at: Date.now(),
73
- });
74
- } else {
75
- await supabase.from("beatmapPages").upsert({
76
- id: data.mapId,
77
- nominations: newNominations,
78
- });
79
- }
80
-
81
- return NextResponse.json({});
82
- }
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
+ mapId: z.number(),
12
+ }),
13
+ output: z.object({
14
+ error: z.string().optional(),
15
+ }),
16
+ };
17
+
18
+ export async function POST(request: Request) {
19
+ return protectedApi({
20
+ request,
21
+ schema: Schema,
22
+ authorization: validUser,
23
+ activity: handler,
24
+ });
25
+ }
26
+
27
+ export async function handler(data: (typeof Schema)["input"]["_type"]) {
28
+ const user = (await getUserBySession(data.session)) as User;
29
+ let { data: queryUserData, error: userError } = await supabase
30
+ .from("profiles")
31
+ .select("*")
32
+ .eq("uid", user.id)
33
+ .single();
34
+
35
+ if (!queryUserData) {
36
+ return NextResponse.json({ error: "Can't find user" });
37
+ }
38
+
39
+ const tags = (queryUserData?.badges || []) as string[];
40
+
41
+ if (!tags.includes("RCT")) {
42
+ return NextResponse.json({ error: "Only RCTs can nominate maps!" });
43
+ }
44
+
45
+ const { data: mapData, error } = await supabase
46
+ .from("beatmapPages")
47
+ .select("id,nominations,owner")
48
+ .eq("id", data.mapId)
49
+ .single();
50
+
51
+ if (!mapData) {
52
+ return NextResponse.json({ error: "Bad map" });
53
+ }
54
+
55
+ if (mapData.owner == queryUserData.id) {
56
+ return NextResponse.json({ error: "Can't nominate own map" });
57
+ }
58
+
59
+ if ((mapData.nominations as number[]).includes(queryUserData.id)) {
60
+ return NextResponse.json({ error: "Already nominated" });
61
+ }
62
+
63
+ const newNominations = [
64
+ ...(mapData.nominations! as number[]),
65
+ queryUserData.id,
66
+ ];
67
+ if (newNominations.length == 2) {
68
+ await supabase.from("beatmapPages").upsert({
69
+ id: data.mapId,
70
+ nominations: newNominations,
71
+ status: "RANKED",
72
+ ranked_at: Date.now(),
73
+ });
74
+ } else {
75
+ await supabase.from("beatmapPages").upsert({
76
+ id: data.mapId,
77
+ nominations: newNominations,
78
+ });
79
+ }
80
+
81
+ return NextResponse.json({});
82
+ }
@@ -1,59 +1,62 @@
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 { User } from "@supabase/supabase-js";
6
- import { getUserBySession } from "../utils/getUserBySession";
7
-
8
- export const Schema = {
9
- input: z.strictObject({
10
- session: z.string(),
11
- page: z.number(),
12
- content: z.string(),
13
- }),
14
- output: z.strictObject({
15
- error: z.string().optional(),
16
- }),
17
- };
18
-
19
- export async function POST(request: Request): Promise<NextResponse> {
20
- return protectedApi({
21
- request,
22
- schema: Schema,
23
- authorization: validUser,
24
- activity: handler,
25
- });
26
- }
27
-
28
- export async function handler({
29
- session,
30
- page,
31
- content,
32
- }: (typeof Schema)["input"]["_type"]): Promise<
33
- NextResponse<(typeof Schema)["output"]["_type"]>
34
- > {
35
- const user = (await getUserBySession(session)) as User;
36
- let { data: userData, error: userError } = await supabase
37
- .from("profiles")
38
- .select("*")
39
- .eq("uid", user.id)
40
- .single();
41
-
42
- if (!userData) return NextResponse.json({ error: "No user." });
43
- if (userData.ban !== "cool") return NextResponse.json({ error: "Error" });
44
-
45
- const upserted = await supabase
46
- .from("beatmapPageComments")
47
- .upsert({
48
- beatmapPage: page,
49
- owner: userData.id,
50
- content,
51
- })
52
- .select("*")
53
- .single();
54
-
55
- if (upserted.error?.message.length) {
56
- return NextResponse.json({ error: upserted.error.message });
57
- }
58
- return NextResponse.json({});
59
- }
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 { User } from "@supabase/supabase-js";
6
+ import { getUserBySession } from "../utils/getUserBySession";
7
+
8
+ export const Schema = {
9
+ input: z.strictObject({
10
+ session: z.string(),
11
+ page: z.number(),
12
+ content: z.string(),
13
+ }),
14
+ output: z.strictObject({
15
+ error: z.string().optional(),
16
+ }),
17
+ };
18
+
19
+ export async function POST(request: Request): Promise<NextResponse> {
20
+ return protectedApi({
21
+ request,
22
+ schema: Schema,
23
+ authorization: validUser,
24
+ activity: handler,
25
+ });
26
+ }
27
+
28
+ export async function handler({
29
+ session,
30
+ page,
31
+ content,
32
+ }: (typeof Schema)["input"]["_type"]): Promise<
33
+ NextResponse<(typeof Schema)["output"]["_type"]>
34
+ > {
35
+ const user = (await getUserBySession(session)) as User;
36
+ let { data: userData, error: userError } = await supabase
37
+ .from("profiles")
38
+ .select("*")
39
+ .eq("uid", user.id)
40
+ .single();
41
+
42
+ if (!userData) return NextResponse.json({ error: "No user." });
43
+ if (userData.ban !== "cool") return NextResponse.json({ error: "Error" });
44
+
45
+ if (content.length > 256)
46
+ return NextResponse.json({ error: "Comment exceeds length." });
47
+
48
+ const upserted = await supabase
49
+ .from("beatmapPageComments")
50
+ .upsert({
51
+ beatmapPage: page,
52
+ owner: userData.id,
53
+ content,
54
+ })
55
+ .select("*")
56
+ .single();
57
+
58
+ if (upserted.error?.message.length) {
59
+ return NextResponse.json({ error: upserted.error.message });
60
+ }
61
+ return NextResponse.json({});
62
+ }
@@ -1,64 +1,64 @@
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
- mapId: z.number(),
12
- }),
13
- output: z.object({
14
- error: z.string().optional(),
15
- }),
16
- };
17
-
18
- export async function POST(request: Request) {
19
- return protectedApi({
20
- request,
21
- schema: Schema,
22
- authorization: validUser,
23
- activity: handler,
24
- });
25
- }
26
-
27
- export async function handler(data: (typeof Schema)["input"]["_type"]) {
28
- const user = (await getUserBySession(data.session)) as User;
29
- let { data: queryUserData, error: userError } = await supabase
30
- .from("profiles")
31
- .select("*")
32
- .eq("uid", user.id)
33
- .single();
34
-
35
- if (!queryUserData) {
36
- return NextResponse.json({ error: "Can't find user" });
37
- }
38
-
39
- const tags = (queryUserData?.badges || []) as string[];
40
-
41
- if (!tags.includes("Bot")) {
42
- return NextResponse.json({ error: "Only Bots can force-rank maps!" });
43
- }
44
-
45
- const { data: mapData, error } = await supabase
46
- .from("beatmapPages")
47
- .select("id,nominations,owner,status")
48
- .eq("owner", user.id)
49
- .eq("status", "UNRANKED");
50
-
51
- if (!mapData) {
52
- return NextResponse.json({ error: "Bad map" });
53
- }
54
-
55
- for (const element of mapData) {
56
- await supabase.from("beatmapPages").upsert({
57
- id: element.id,
58
- nominations: [queryUserData.id, queryUserData.id],
59
- status: "RANKED",
60
- });
61
- }
62
-
63
- return NextResponse.json({});
64
- }
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
+ mapId: z.number(),
12
+ }),
13
+ output: z.object({
14
+ error: z.string().optional(),
15
+ }),
16
+ };
17
+
18
+ export async function POST(request: Request) {
19
+ return protectedApi({
20
+ request,
21
+ schema: Schema,
22
+ authorization: validUser,
23
+ activity: handler,
24
+ });
25
+ }
26
+
27
+ export async function handler(data: (typeof Schema)["input"]["_type"]) {
28
+ const user = (await getUserBySession(data.session)) as User;
29
+ let { data: queryUserData, error: userError } = await supabase
30
+ .from("profiles")
31
+ .select("*")
32
+ .eq("uid", user.id)
33
+ .single();
34
+
35
+ if (!queryUserData) {
36
+ return NextResponse.json({ error: "Can't find user" });
37
+ }
38
+
39
+ const tags = (queryUserData?.badges || []) as string[];
40
+
41
+ if (!tags.includes("Bot")) {
42
+ return NextResponse.json({ error: "Only Bots can force-rank maps!" });
43
+ }
44
+
45
+ const { data: mapData, error } = await supabase
46
+ .from("beatmapPages")
47
+ .select("id,nominations,owner,status")
48
+ .eq("owner", user.id)
49
+ .eq("status", "UNRANKED");
50
+
51
+ if (!mapData) {
52
+ return NextResponse.json({ error: "Bad map" });
53
+ }
54
+
55
+ for (const element of mapData) {
56
+ await supabase.from("beatmapPages").upsert({
57
+ id: element.id,
58
+ nominations: [queryUserData.id, queryUserData.id],
59
+ status: "RANKED",
60
+ });
61
+ }
62
+
63
+ return NextResponse.json({});
64
+ }
@@ -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
- text: z.string(),
9
- }),
10
- output: z.object({
11
- error: z.string().optional(),
12
- results: z
13
- .array(
14
- z.object({
15
- id: z.number(),
16
- username: z.string().nullable(),
17
- })
18
- )
19
- .optional(),
20
- }),
21
- };
22
-
23
- export async function POST(request: Request) {
24
- return protectedApi({
25
- request,
26
- schema: Schema,
27
- authorization: () => {},
28
- activity: handler,
29
- });
30
- }
31
-
32
- export async function handler(data: (typeof Schema)["input"]["_type"]) {
33
- const { data: exactUser } = await supabase
34
- .from("profiles")
35
- .select("id,username")
36
- .neq("ban", "excluded")
37
- .eq("computedUsername", data.text.toLocaleLowerCase())
38
- .single();
39
-
40
- const { data: searchData, error } = await supabase
41
- .from("profiles")
42
- .select("id,username")
43
- .neq("ban", "excluded")
44
- .ilike("username", `%${data.text}%`)
45
- .limit(10);
46
-
47
- const conjoined = searchData || [];
48
-
49
- if (exactUser && !conjoined.some((user) => user.id === exactUser?.id)) {
50
- conjoined.unshift(exactUser);
51
- }
52
-
53
- return NextResponse.json({
54
- results: conjoined || [],
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
+ text: z.string(),
9
+ }),
10
+ output: z.object({
11
+ error: z.string().optional(),
12
+ results: z
13
+ .array(
14
+ z.object({
15
+ id: z.number(),
16
+ username: z.string().nullable(),
17
+ })
18
+ )
19
+ .optional(),
20
+ }),
21
+ };
22
+
23
+ export async function POST(request: Request) {
24
+ return protectedApi({
25
+ request,
26
+ schema: Schema,
27
+ authorization: () => {},
28
+ activity: handler,
29
+ });
30
+ }
31
+
32
+ export async function handler(data: (typeof Schema)["input"]["_type"]) {
33
+ const { data: exactUser } = await supabase
34
+ .from("profiles")
35
+ .select("id,username")
36
+ .neq("ban", "excluded")
37
+ .eq("computedUsername", data.text.toLocaleLowerCase())
38
+ .single();
39
+
40
+ const { data: searchData, error } = await supabase
41
+ .from("profiles")
42
+ .select("id,username")
43
+ .neq("ban", "excluded")
44
+ .ilike("username", `%${data.text}%`)
45
+ .limit(10);
46
+
47
+ const conjoined = searchData || [];
48
+
49
+ if (exactUser && !conjoined.some((user) => user.id === exactUser?.id)) {
50
+ conjoined.unshift(exactUser);
51
+ }
52
+
53
+ return NextResponse.json({
54
+ results: conjoined || [],
55
+ });
56
+ }
package/api/setPasskey.ts CHANGED
@@ -1,59 +1,59 @@
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
- passkey: z.string(),
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: () => {},
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
- const user = (await getUserBySession(data.session)) as User;
33
- let userData: Database["public"]["Tables"]["profiles"]["Update"];
34
- // Find user's entry
35
- {
36
- let { data: queryUserData, error } = await supabase
37
- .from("profiles")
38
- .select("*")
39
- .eq("uid", user.id);
40
-
41
- if (!queryUserData?.length) {
42
- return NextResponse.json(
43
- {
44
- error: "User cannot be retrieved from session",
45
- },
46
- { status: 404 }
47
- );
48
- }
49
- userData = queryUserData[0];
50
- }
51
-
52
- await supabase.from("passkeys").upsert({
53
- id: userData.id!,
54
- email: user.email!,
55
- passkey: data.data.passkey,
56
- });
57
-
58
- return NextResponse.json({});
59
- }
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
+ passkey: z.string(),
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: () => {},
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
+ const user = (await getUserBySession(data.session)) as User;
33
+ let userData: Database["public"]["Tables"]["profiles"]["Update"];
34
+ // Find user's entry
35
+ {
36
+ let { data: queryUserData, error } = await supabase
37
+ .from("profiles")
38
+ .select("*")
39
+ .eq("uid", user.id);
40
+
41
+ if (!queryUserData?.length) {
42
+ return NextResponse.json(
43
+ {
44
+ error: "User cannot be retrieved from session",
45
+ },
46
+ { status: 404 }
47
+ );
48
+ }
49
+ userData = queryUserData[0];
50
+ }
51
+
52
+ await supabase.from("passkeys").upsert({
53
+ id: userData.id!,
54
+ email: user.email!,
55
+ passkey: data.data.passkey,
56
+ });
57
+
58
+ return NextResponse.json({});
59
+ }