rhythia-api 182.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.
@@ -65,6 +65,18 @@ export async function handler({
65
65
  return NextResponse.json({ error: "Bad user" });
66
66
  }
67
67
 
68
+ if (
69
+ !parsedData.strings.mappers
70
+ .map((mapper) => mapper.toLowerCase().trim())
71
+ .includes((userData.username?.trim() || "").toLowerCase())
72
+ ) {
73
+ return NextResponse.json({
74
+ error: `You are not among the authors of the map. If you made the map, please add yourself as an author in the editor. Mappers: ${JSON.stringify(
75
+ parsedData.strings.mappers
76
+ )}, Your name: ${userData.username}`,
77
+ });
78
+ }
79
+
68
80
  if (
69
81
  userData.ban == "excluded" ||
70
82
  userData.ban == "restricted" ||
@@ -54,8 +54,13 @@ export async function handler({
54
54
  if (!userData) return NextResponse.json({ error: "No user." });
55
55
  if (!beatmapData) return NextResponse.json({ error: "No beatmap." });
56
56
 
57
- if (userData.id !== pageData.owner)
58
- return NextResponse.json({ error: "Non-authz user." });
57
+ if (userData.id !== pageData.owner) {
58
+ const isDev =
59
+ (userData.badges as string[]).includes("Developer") ||
60
+ (userData.badges as string[]).includes("Global Moderator");
61
+
62
+ if (!isDev) return NextResponse.json({ error: "Non-authz user." });
63
+ }
59
64
 
60
65
  if (pageData.status !== "UNRANKED")
61
66
  return NextResponse.json({ error: "Only unranked maps can be updated" });
@@ -60,10 +60,23 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
60
60
  return NextResponse.json({ error: "Already nominated" });
61
61
  }
62
62
 
63
- await supabase.from("beatmapPages").upsert({
64
- id: data.mapId,
65
- nominations: [...(mapData.nominations! as number[]), queryUserData.id],
66
- });
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
+ }
67
80
 
68
81
  return NextResponse.json({});
69
82
  }
package/handleApi.ts CHANGED
@@ -9,6 +9,8 @@ export function setEnvironment(
9
9
  export function handleApi<
10
10
  T extends { url: string; input: z.ZodObject<any>; output: z.ZodObject<any> }
11
11
  >(apiSchema: T) {
12
+ profanity.whitelist.addWords(["willy"]);
13
+
12
14
  return async (input: T["input"]["_type"]): Promise<T["output"]["_type"]> => {
13
15
  const response = await fetch(`https://${env}.rhythia.com${apiSchema.url}`, {
14
16
  method: "POST",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhythia-api",
3
- "version": "182.0.0",
3
+ "version": "184.0.0",
4
4
  "main": "index.ts",
5
5
  "author": "online-contributors",
6
6
  "scripts": {
@@ -136,6 +136,7 @@ export class SSPMParser {
136
136
  }
137
137
 
138
138
  private readStringList(count: number): string[] {
139
+ console.log("[DANGER] Reading String List");
139
140
  const list: string[] = [];
140
141
  for (let i = 0; i < count; i++) {
141
142
  list.push(this.readString());
@@ -281,8 +282,7 @@ export class SSPMParser {
281
282
  mapID: this.readString(),
282
283
  mapName: this.readString(),
283
284
  songName: this.readString(),
284
- mappers: [],
285
- // mappers: this.readStringList(this.readUInt16()),
285
+ mappers: this.readStringList(this.readUInt16()),
286
286
  };
287
287
 
288
288
  let customData: CustomData = { fields: [] };