rhythia-api 233.0.0 → 234.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/.codex +0 -0
- package/.env +1 -12
- package/README.md +4 -4
- package/api/acceptInvite.ts +1 -1
- package/api/addCollectionMap.ts +1 -1
- package/api/chartPublicStats.ts +1 -1
- package/api/checkQualified.ts +93 -93
- package/api/createBeatmap.ts +53 -62
- package/api/createBeatmapPage.ts +1 -1
- package/api/createClan.ts +1 -1
- package/api/createCollection.ts +1 -1
- package/api/createInvite.ts +1 -1
- package/api/createSupporter.ts +1 -1
- package/api/deleteBeatmapPage.ts +2 -5
- package/api/deleteCollection.ts +1 -1
- package/api/deleteCollectionMap.ts +1 -1
- package/api/editAboutMe.ts +1 -1
- package/api/editClan.ts +1 -1
- package/api/editCollection.ts +1 -2
- package/api/editProfile.ts +1 -1
- package/api/enhancedSearch.ts +113 -113
- package/api/executeAdminOperation.ts +1 -22
- package/api/getAvatarUploadUrl.ts +1 -1
- package/api/getBadgeLeaders.ts +1 -1
- package/api/getBadgedUsers.ts +1 -1
- package/api/getBeatmapComments.ts +1 -1
- package/api/getBeatmapPage.ts +74 -106
- package/api/getBeatmapPageById.ts +70 -109
- package/api/getBeatmapStarRating.ts +1 -1
- package/api/getBeatmaps.ts +1 -1
- package/api/getClan.ts +1 -1
- package/api/getClans.ts +1 -1
- package/api/getCollection.ts +1 -1
- package/api/getCollections.ts +1 -1
- package/api/getInventory.ts +1 -1
- package/api/getLeaderboard.ts +1 -1
- package/api/getMapUploadUrl.ts +2 -2
- package/api/getOnlinePlayers.ts +1 -1
- package/api/getPassToken.ts +1 -1
- package/api/getProfile.ts +51 -31
- package/api/getPublicStats.ts +5 -5
- package/api/getRawStarRating.ts +1 -1
- package/api/getScore.ts +1 -1
- package/api/getStoryBeatmaps.ts +1 -1
- package/api/getTimestamp.ts +1 -1
- package/api/getUserScores.ts +19 -19
- package/api/getVerified.ts +1 -1
- package/api/getVideoUploadUrl.ts +1 -1
- package/api/postBeatmapComment.ts +1 -1
- package/api/qualifyMap.ts +97 -92
- package/api/rankMapsArchive.ts +20 -20
- package/api/searchUsers.ts +1 -1
- package/api/setPasskey.ts +1 -1
- package/api/submitScore.ts +1 -6
- package/api/submitScoreInternal.ts +461 -449
- package/api/updateBeatmapPage.ts +1 -1
- package/api/vetoMap.ts +101 -101
- package/index.ts +165 -153
- package/package.json +7 -12
- package/queries/admin_delete_user.sql +39 -39
- package/queries/admin_exclude_user.sql +21 -21
- package/queries/admin_invalidate_ranked_scores.sql +18 -18
- package/queries/admin_log_action.sql +10 -10
- package/queries/admin_profanity_clear.sql +29 -29
- package/queries/admin_remove_all_scores.sql +29 -29
- package/queries/admin_restrict_user.sql +21 -21
- package/queries/admin_search_users.sql +24 -24
- package/queries/admin_silence_user.sql +21 -21
- package/queries/admin_unban_user.sql +21 -21
- package/queries/enhanced_search.sql +217 -217
- package/queries/get_badge_leaderboard.sql +50 -50
- package/queries/get_clan_leaderboard.sql +68 -68
- package/queries/get_collections_v4.sql +109 -109
- package/queries/get_top_scores_for_beatmap.sql +44 -44
- package/queries/get_top_scores_for_beatmap3.sql +38 -0
- package/queries/get_user_by_email.sql +32 -32
- package/queries/get_user_scores_lastday.sql +47 -47
- package/queries/get_user_scores_reign.sql +31 -31
- package/queries/get_user_scores_top_and_stats.sql +84 -84
- package/queries/grant_special_badges.sql +69 -69
- package/types/database.ts +1288 -1248
- package/utils/beatmapTopScores.ts +84 -0
- package/utils/mapLifecycleWebhook.ts +287 -277
- package/utils/requestGeo.ts +13 -0
- package/utils/requestUtils.ts +127 -127
- package/utils/response.ts +11 -0
- package/worker.ts +189 -0
- package/wrangler.jsonc +10 -0
- package/index.html +0 -3
- package/vercel.json +0 -13
package/api/qualifyMap.ts
CHANGED
|
@@ -1,92 +1,97 @@
|
|
|
1
|
-
import { NextResponse } from "
|
|
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 { postMapLifecycleWebhook } from "../utils/mapLifecycleWebhook";
|
|
8
|
-
|
|
9
|
-
const QUALIFY_BADGES = ["Team Ranked"];
|
|
10
|
-
|
|
11
|
-
export const Schema = {
|
|
12
|
-
input: z.strictObject({
|
|
13
|
-
session: z.string(),
|
|
14
|
-
mapId: z.number(),
|
|
15
|
-
}),
|
|
16
|
-
output: z.object({
|
|
17
|
-
error: z.string().optional(),
|
|
18
|
-
qualifiedAt: 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
|
-
const { data: queryUserData } = 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
|
-
const tags = (queryUserData?.badges || []) as string[];
|
|
44
|
-
const hasQualifyAccess = QUALIFY_BADGES.some((badge) => tags.includes(badge));
|
|
45
|
-
|
|
46
|
-
if (!hasQualifyAccess) {
|
|
47
|
-
return NextResponse.json({ error: "Only management can qualify maps!" });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const { data: mapData } = await supabase
|
|
51
|
-
.from("beatmapPages")
|
|
52
|
-
.select("id,owner,status,qualified,qualifiedAt")
|
|
53
|
-
.eq("id", data.mapId)
|
|
54
|
-
.single();
|
|
55
|
-
|
|
56
|
-
if (!mapData) {
|
|
57
|
-
return NextResponse.json({ error: "Bad map" });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (mapData.owner === queryUserData.id) {
|
|
61
|
-
return NextResponse.json({ error: "Can't qualify own map" });
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (mapData.status === "RANKED") {
|
|
65
|
-
return NextResponse.json({ error: "Map is already ranked" });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (mapData.qualified) {
|
|
69
|
-
return NextResponse.json({
|
|
70
|
-
error: "Map is already qualified",
|
|
71
|
-
qualifiedAt: mapData.qualifiedAt || undefined,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const qualifiedAt = new Date().toISOString();
|
|
76
|
-
const { error: updateError } = await supabase.from("beatmapPages").upsert({
|
|
77
|
-
id: data.mapId,
|
|
78
|
-
qualified: true,
|
|
79
|
-
qualifiedAt,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (updateError) {
|
|
83
|
-
return NextResponse.json({ error: updateError.message });
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
await postMapLifecycleWebhook({
|
|
87
|
-
mapId: data.mapId,
|
|
88
|
-
event: "qualified",
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
1
|
+
import { NextResponse } from "../utils/response";
|
|
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 { postMapLifecycleWebhook } from "../utils/mapLifecycleWebhook";
|
|
8
|
+
|
|
9
|
+
const QUALIFY_BADGES = ["Team Ranked"];
|
|
10
|
+
|
|
11
|
+
export const Schema = {
|
|
12
|
+
input: z.strictObject({
|
|
13
|
+
session: z.string(),
|
|
14
|
+
mapId: z.number(),
|
|
15
|
+
}),
|
|
16
|
+
output: z.object({
|
|
17
|
+
error: z.string().optional(),
|
|
18
|
+
qualifiedAt: 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
|
+
const { data: queryUserData } = 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
|
+
const tags = (queryUserData?.badges || []) as string[];
|
|
44
|
+
const hasQualifyAccess = QUALIFY_BADGES.some((badge) => tags.includes(badge));
|
|
45
|
+
|
|
46
|
+
if (!hasQualifyAccess) {
|
|
47
|
+
return NextResponse.json({ error: "Only management can qualify maps!" });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const { data: mapData } = await supabase
|
|
51
|
+
.from("beatmapPages")
|
|
52
|
+
.select("id,owner,status,qualified,qualifiedAt")
|
|
53
|
+
.eq("id", data.mapId)
|
|
54
|
+
.single();
|
|
55
|
+
|
|
56
|
+
if (!mapData) {
|
|
57
|
+
return NextResponse.json({ error: "Bad map" });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (mapData.owner === queryUserData.id) {
|
|
61
|
+
return NextResponse.json({ error: "Can't qualify own map" });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (mapData.status === "RANKED") {
|
|
65
|
+
return NextResponse.json({ error: "Map is already ranked" });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (mapData.qualified) {
|
|
69
|
+
return NextResponse.json({
|
|
70
|
+
error: "Map is already qualified",
|
|
71
|
+
qualifiedAt: mapData.qualifiedAt || undefined,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const qualifiedAt = new Date().toISOString();
|
|
76
|
+
const { error: updateError } = await supabase.from("beatmapPages").upsert({
|
|
77
|
+
id: data.mapId,
|
|
78
|
+
qualified: true,
|
|
79
|
+
qualifiedAt,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (updateError) {
|
|
83
|
+
return NextResponse.json({ error: updateError.message });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
await postMapLifecycleWebhook({
|
|
87
|
+
mapId: data.mapId,
|
|
88
|
+
event: "qualified",
|
|
89
|
+
candidateQualifierUsername: tags.includes("Candidate")
|
|
90
|
+
? queryUserData.username ||
|
|
91
|
+
queryUserData.computedUsername ||
|
|
92
|
+
`User #${queryUserData.id}`
|
|
93
|
+
: undefined,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return NextResponse.json({ qualifiedAt });
|
|
97
|
+
}
|
package/api/rankMapsArchive.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { NextResponse } from "
|
|
1
|
+
import { NextResponse } from "../utils/response";
|
|
2
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 { postMapLifecycleWebhook } from "../utils/mapLifecycleWebhook";
|
|
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 { postMapLifecycleWebhook } from "../utils/mapLifecycleWebhook";
|
|
8
8
|
|
|
9
9
|
export const Schema = {
|
|
10
10
|
input: z.strictObject({
|
|
@@ -59,20 +59,20 @@ export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
|
59
59
|
return NextResponse.json({ error: "Bad map" });
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
for (const element of mapData) {
|
|
63
|
-
await supabase.from("beatmapPages").upsert({
|
|
64
|
-
id: element.id,
|
|
65
|
-
nominations: [queryUserData.id, queryUserData.id],
|
|
66
|
-
status: "RANKED",
|
|
67
|
-
ranked_at: Date.now(),
|
|
68
|
-
qualified: false,
|
|
69
|
-
qualifiedAt: null,
|
|
70
|
-
});
|
|
71
|
-
await postMapLifecycleWebhook({
|
|
72
|
-
mapId: element.id,
|
|
73
|
-
event: "ranked",
|
|
74
|
-
});
|
|
75
|
-
}
|
|
62
|
+
for (const element of mapData) {
|
|
63
|
+
await supabase.from("beatmapPages").upsert({
|
|
64
|
+
id: element.id,
|
|
65
|
+
nominations: [queryUserData.id, queryUserData.id],
|
|
66
|
+
status: "RANKED",
|
|
67
|
+
ranked_at: Date.now(),
|
|
68
|
+
qualified: false,
|
|
69
|
+
qualifiedAt: null,
|
|
70
|
+
});
|
|
71
|
+
await postMapLifecycleWebhook({
|
|
72
|
+
mapId: element.id,
|
|
73
|
+
event: "ranked",
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
76
|
|
|
77
77
|
return NextResponse.json({});
|
|
78
78
|
}
|
package/api/searchUsers.ts
CHANGED
package/api/setPasskey.ts
CHANGED
package/api/submitScore.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NextResponse } from "
|
|
1
|
+
import { NextResponse } from "../utils/response";
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import { protectedApi, validUser } from "../utils/requestUtils";
|
|
4
4
|
import { supabase } from "../utils/supabase";
|
|
@@ -303,11 +303,6 @@ export async function handler({
|
|
|
303
303
|
console.log("p3");
|
|
304
304
|
|
|
305
305
|
await invalidateCachePrefix(`userscore:${userData.id}`);
|
|
306
|
-
const beatmapIsRanked =
|
|
307
|
-
beatmapPages?.status === "RANKED" || beatmapPages?.status === "APPROVED";
|
|
308
|
-
if (beatmapIsRanked) {
|
|
309
|
-
await invalidateCachePrefix(`beatmap-scores:${data.mapHash}`);
|
|
310
|
-
}
|
|
311
306
|
|
|
312
307
|
// Grant special badges if applicable
|
|
313
308
|
if (passed && beatmapPages && !data.mods.includes("mod_nofail")) {
|