rhythia-api 129.0.0 → 131.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 +6 -0
- package/api/createBeatmap.ts +12 -3
- package/api/editAboutMe.ts +1 -1
- package/api/getBadgedUsers.ts +1 -7
- package/api/getMapUploadUrl.ts +3 -1
- package/api/rankMapsArchive.ts +62 -0
- package/api/submitScore.ts +1 -1
- package/handleApi.ts +3 -2
- package/index.ts +5 -0
- package/package-lock.json +8814 -4404
- package/package.json +3 -1
- package/scripts/test.ts +16 -11
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",
|
package/api/createBeatmap.ts
CHANGED
|
@@ -47,9 +47,18 @@ export async function handler({
|
|
|
47
47
|
const parser = new SSPMParser(Buffer.from(bytes));
|
|
48
48
|
|
|
49
49
|
const parsedData = parser.parse();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const digested = parsedData.strings.mapID;
|
|
51
|
+
|
|
52
|
+
let { data: beatmapPage, error: errorlast } = await supabase
|
|
53
|
+
.from("beatmapPages")
|
|
54
|
+
.select(`*`)
|
|
55
|
+
.eq("latestBeatmapHash", digested)
|
|
56
|
+
.single();
|
|
57
|
+
|
|
58
|
+
if (beatmapPage) {
|
|
59
|
+
return NextResponse.json({ error: "Already Exists" });
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
const imgkey = `beatmap-img-${Date.now()}-${digested}`;
|
|
54
63
|
|
|
55
64
|
let buffer = Buffer.from([]);
|
package/api/editAboutMe.ts
CHANGED
package/api/getBadgedUsers.ts
CHANGED
|
@@ -15,9 +15,6 @@ export const Schema = {
|
|
|
15
15
|
flag: z.string().nullable(),
|
|
16
16
|
id: z.number(),
|
|
17
17
|
username: z.string().nullable(),
|
|
18
|
-
play_count: z.number().nullable(),
|
|
19
|
-
skill_points: z.number().nullable(),
|
|
20
|
-
total_score: z.number().nullable(),
|
|
21
18
|
})
|
|
22
19
|
)
|
|
23
20
|
.optional(),
|
|
@@ -43,7 +40,7 @@ export async function handler(
|
|
|
43
40
|
export async function getLeaderboard(badge: string) {
|
|
44
41
|
let { data: queryData, error } = await supabase
|
|
45
42
|
.from("profiles")
|
|
46
|
-
.select("
|
|
43
|
+
.select("flag,id,username,badges")
|
|
47
44
|
.neq("ban", "excluded");
|
|
48
45
|
|
|
49
46
|
const users = queryData?.filter((e) =>
|
|
@@ -54,9 +51,6 @@ export async function getLeaderboard(badge: string) {
|
|
|
54
51
|
leaderboard: users?.map((user) => ({
|
|
55
52
|
flag: user.flag,
|
|
56
53
|
id: user.id,
|
|
57
|
-
play_count: user.play_count,
|
|
58
|
-
skill_points: user.skill_points,
|
|
59
|
-
total_score: user.total_score,
|
|
60
54
|
username: user.username,
|
|
61
55
|
})),
|
|
62
56
|
};
|
package/api/getMapUploadUrl.ts
CHANGED
|
@@ -21,6 +21,7 @@ const s3Client = new S3Client({
|
|
|
21
21
|
|
|
22
22
|
export const Schema = {
|
|
23
23
|
input: z.strictObject({
|
|
24
|
+
mapName: z.string().optional(),
|
|
24
25
|
session: z.string(),
|
|
25
26
|
contentLength: z.number(),
|
|
26
27
|
contentType: z.string(),
|
|
@@ -42,6 +43,7 @@ export async function POST(request: Request): Promise<NextResponse> {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
export async function handler({
|
|
46
|
+
mapName,
|
|
45
47
|
session,
|
|
46
48
|
contentLength,
|
|
47
49
|
contentType,
|
|
@@ -56,7 +58,7 @@ export async function handler({
|
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
const key = `
|
|
61
|
+
const key = `rhythia-${mapName ? mapName : user.id}-${Date.now()}.sspm`;
|
|
60
62
|
const command = new PutObjectCommand({
|
|
61
63
|
Bucket: "rhthia-avatars",
|
|
62
64
|
Key: key,
|
|
@@ -0,0 +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
|
+
|
|
6
|
+
export const Schema = {
|
|
7
|
+
input: z.strictObject({
|
|
8
|
+
session: z.string(),
|
|
9
|
+
mapId: z.number(),
|
|
10
|
+
}),
|
|
11
|
+
output: z.object({
|
|
12
|
+
error: z.string().optional(),
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export async function POST(request: Request) {
|
|
17
|
+
return protectedApi({
|
|
18
|
+
request,
|
|
19
|
+
schema: Schema,
|
|
20
|
+
authorization: validUser,
|
|
21
|
+
activity: handler,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
26
|
+
const user = (await supabase.auth.getUser(data.session)).data.user!;
|
|
27
|
+
let { data: queryUserData, error: userError } = await supabase
|
|
28
|
+
.from("profiles")
|
|
29
|
+
.select("*")
|
|
30
|
+
.eq("uid", user.id)
|
|
31
|
+
.single();
|
|
32
|
+
|
|
33
|
+
if (!queryUserData) {
|
|
34
|
+
return NextResponse.json({ error: "Can't find user" });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const tags = (queryUserData?.badges || []) as string[];
|
|
38
|
+
|
|
39
|
+
if (!tags.includes("Bot")) {
|
|
40
|
+
return NextResponse.json({ error: "Only Bots can force-rank maps!" });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const { data: mapData, error } = await supabase
|
|
44
|
+
.from("beatmapPages")
|
|
45
|
+
.select("id,nominations,owner,status")
|
|
46
|
+
.eq("owner", user.id)
|
|
47
|
+
.eq("status", "UNRANKED");
|
|
48
|
+
|
|
49
|
+
if (!mapData) {
|
|
50
|
+
return NextResponse.json({ error: "Bad map" });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const element of mapData) {
|
|
54
|
+
await supabase.from("beatmapPages").upsert({
|
|
55
|
+
id: element.id,
|
|
56
|
+
nominations: [queryUserData.id, queryUserData.id],
|
|
57
|
+
status: "RANKED",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return NextResponse.json({});
|
|
62
|
+
}
|
package/api/submitScore.ts
CHANGED
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.
|
|
17
|
-
return output;
|
|
17
|
+
const output = await response.text();
|
|
18
|
+
return JSON.parse(profanity.censor(output));
|
|
18
19
|
};
|
|
19
20
|
}
|
package/index.ts
CHANGED
|
@@ -80,6 +80,11 @@ import { Schema as NominateMap } from "./api/nominateMap"
|
|
|
80
80
|
export { Schema as SchemaNominateMap } from "./api/nominateMap"
|
|
81
81
|
export const nominateMap = handleApi({url:"/api/nominateMap",...NominateMap})
|
|
82
82
|
|
|
83
|
+
// ./api/rankMapsArchive.ts API
|
|
84
|
+
import { Schema as RankMapsArchive } from "./api/rankMapsArchive"
|
|
85
|
+
export { Schema as SchemaRankMapsArchive } from "./api/rankMapsArchive"
|
|
86
|
+
export const rankMapsArchive = handleApi({url:"/api/rankMapsArchive",...RankMapsArchive})
|
|
87
|
+
|
|
83
88
|
// ./api/searchUsers.ts API
|
|
84
89
|
import { Schema as SearchUsers } from "./api/searchUsers"
|
|
85
90
|
export { Schema as SchemaSearchUsers } from "./api/searchUsers"
|