rhythia-api 128.0.0 → 130.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.
package/api/approveMap.ts CHANGED
@@ -60,6 +60,12 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
60
60
  });
61
61
  }
62
62
 
63
+ if ((mapData.nominations as number[]).includes(queryUserData.id)) {
64
+ return NextResponse.json({
65
+ error: "Can't nominate and approve",
66
+ });
67
+ }
68
+
63
69
  await supabase.from("beatmapPages").upsert({
64
70
  id: data.mapId,
65
71
  status: "RANKED",
@@ -50,6 +50,17 @@ export async function handler({
50
50
  let sum = require("crypto").createHash("sha1");
51
51
  sum.update(Buffer.from(bytes));
52
52
  const digested = sum.digest("hex");
53
+
54
+ let { data: beatmapPage, error: errorlast } = await supabase
55
+ .from("beatmapPages")
56
+ .select(`*`)
57
+ .eq("latestBeatmapHash", digested)
58
+ .single();
59
+
60
+ if (beatmapPage) {
61
+ return NextResponse.json({ error: "Already Exists" });
62
+ }
63
+
53
64
  const imgkey = `beatmap-img-${Date.now()}-${digested}`;
54
65
 
55
66
  let buffer = Buffer.from([]);
@@ -36,7 +36,7 @@ export async function handler(
36
36
  );
37
37
  }
38
38
 
39
- if (data.data.about_me.length > 500) {
39
+ if (data.data.about_me.length > 10000) {
40
40
  return NextResponse.json(
41
41
  {
42
42
  error: "Too long.",
@@ -9,16 +9,12 @@ export const Schema = {
9
9
  }),
10
10
  output: z.object({
11
11
  error: z.string().optional(),
12
- total: z.number(),
13
12
  leaderboard: z
14
13
  .array(
15
14
  z.object({
16
15
  flag: z.string().nullable(),
17
16
  id: z.number(),
18
17
  username: z.string().nullable(),
19
- play_count: z.number().nullable(),
20
- skill_points: z.number().nullable(),
21
- total_score: z.number().nullable(),
22
18
  })
23
19
  )
24
20
  .optional(),
@@ -42,28 +38,19 @@ export async function handler(
42
38
  }
43
39
 
44
40
  export async function getLeaderboard(badge: string) {
45
- const countQuery = await supabase
46
- .from("profiles")
47
- .select("ban", { count: "exact", head: true })
48
- .neq("ban", "excluded")
49
- .ilike("badges", `%${badge}%`);
50
-
51
41
  let { data: queryData, error } = await supabase
52
42
  .from("profiles")
53
- .select("*")
54
- .neq("ban", "excluded")
55
- .ilike("badges", `%${badge}%`)
56
- .order("skill_points", { ascending: false })
57
- .range(0, 200);
43
+ .select("flag,id,username,badges")
44
+ .neq("ban", "excluded");
45
+
46
+ const users = queryData?.filter((e) =>
47
+ ((e.badges || []) as string[]).includes(badge)
48
+ );
58
49
 
59
50
  return {
60
- total: countQuery.count || 0,
61
- leaderboard: queryData?.map((user) => ({
51
+ leaderboard: users?.map((user) => ({
62
52
  flag: user.flag,
63
53
  id: user.id,
64
- play_count: user.play_count,
65
- skill_points: user.skill_points,
66
- total_score: user.total_score,
67
54
  username: user.username,
68
55
  })),
69
56
  };
package/handleApi.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  let env = "development";
3
+ import { profanity, CensorType } from "@2toad/profanity";
3
4
  export function setEnvironment(
4
5
  stage: "development" | "testing" | "production"
5
6
  ) {
@@ -13,7 +14,7 @@ export function handleApi<
13
14
  method: "POST",
14
15
  body: JSON.stringify(input),
15
16
  });
16
- const output = await response.json();
17
- return output;
17
+ const output = await response.text();
18
+ return JSON.parse(profanity.censor(output));
18
19
  };
19
20
  }