rhythia-api 185.0.0 → 187.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/.prettierrc.json +6 -6
- package/api/addCollectionMap.ts +82 -82
- package/api/approveMap.ts +78 -78
- package/api/chartPublicStats.ts +32 -32
- package/api/createBeatmap.ts +168 -168
- package/api/createBeatmapPage.ts +64 -64
- package/api/createClan.ts +81 -81
- package/api/createCollection.ts +58 -58
- package/api/deleteBeatmapPage.ts +77 -77
- package/api/deleteCollection.ts +59 -59
- package/api/deleteCollectionMap.ts +71 -71
- package/api/editAboutMe.ts +91 -91
- package/api/editClan.ts +90 -90
- package/api/editCollection.ts +77 -77
- package/api/editProfile.ts +123 -123
- package/api/getAvatarUploadUrl.ts +85 -85
- package/api/getBadgedUsers.ts +56 -56
- package/api/getBeatmapComments.ts +57 -57
- package/api/getBeatmapPage.ts +106 -106
- package/api/getBeatmapPageById.ts +99 -99
- package/api/getBeatmapStarRating.ts +53 -53
- package/api/getBeatmaps.ts +159 -159
- package/api/getClan.ts +77 -77
- package/api/getCollection.ts +130 -130
- package/api/getCollections.ts +132 -130
- package/api/getLeaderboard.ts +136 -136
- package/api/getMapUploadUrl.ts +93 -93
- package/api/getPassToken.ts +55 -55
- package/api/getProfile.ts +146 -146
- package/api/getPublicStats.ts +180 -180
- package/api/getRawStarRating.ts +57 -57
- package/api/getScore.ts +85 -85
- package/api/getTimestamp.ts +23 -23
- package/api/getUserScores.ts +175 -175
- package/api/nominateMap.ts +82 -82
- package/api/postBeatmapComment.ts +59 -59
- package/api/rankMapsArchive.ts +64 -64
- package/api/searchUsers.ts +56 -56
- package/api/setPasskey.ts +59 -59
- package/api/submitScore.ts +433 -433
- package/api/updateBeatmapPage.ts +229 -229
- package/handleApi.ts +21 -20
- package/index.html +2 -2
- package/index.ts +867 -866
- package/package.json +1 -1
- package/types/database.ts +800 -798
- package/utils/getUserBySession.ts +48 -48
- package/utils/requestUtils.ts +87 -87
- package/utils/security.ts +20 -20
- package/utils/star-calc/index.ts +72 -72
- package/utils/star-calc/osuUtils.ts +53 -53
- package/utils/star-calc/sspmParser.ts +398 -398
- package/utils/star-calc/sspmv1Parser.ts +165 -165
- package/utils/supabase.ts +13 -13
- package/utils/test +4 -4
- package/utils/validateToken.ts +7 -7
- package/vercel.json +12 -12
package/api/updateBeatmapPage.ts
CHANGED
|
@@ -1,229 +1,229 @@
|
|
|
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
|
-
import { calculatePerformancePoints } from "./submitScore";
|
|
8
|
-
|
|
9
|
-
export const Schema = {
|
|
10
|
-
input: z.strictObject({
|
|
11
|
-
session: z.string(),
|
|
12
|
-
id: z.number(),
|
|
13
|
-
beatmapHash: z.string().optional(),
|
|
14
|
-
tags: z.string().optional(),
|
|
15
|
-
description: z.string().optional(),
|
|
16
|
-
}),
|
|
17
|
-
output: z.strictObject({
|
|
18
|
-
error: z.string().optional(),
|
|
19
|
-
}),
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export async function POST(request: Request): Promise<NextResponse> {
|
|
23
|
-
return protectedApi({
|
|
24
|
-
request,
|
|
25
|
-
schema: Schema,
|
|
26
|
-
authorization: validUser,
|
|
27
|
-
activity: handler,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
export function formatTime(milliseconds: number): string {
|
|
31
|
-
const totalSeconds = Math.floor(milliseconds / 1000);
|
|
32
|
-
const minutes = Math.floor(totalSeconds / 60);
|
|
33
|
-
const seconds = totalSeconds % 60;
|
|
34
|
-
return `${minutes.toString().padStart(2, "0")}:${seconds
|
|
35
|
-
.toString()
|
|
36
|
-
.padStart(2, "0")}`;
|
|
37
|
-
}
|
|
38
|
-
export async function handler({
|
|
39
|
-
session,
|
|
40
|
-
beatmapHash,
|
|
41
|
-
id,
|
|
42
|
-
description,
|
|
43
|
-
tags,
|
|
44
|
-
}: (typeof Schema)["input"]["_type"]): Promise<
|
|
45
|
-
NextResponse<(typeof Schema)["output"]["_type"]>
|
|
46
|
-
> {
|
|
47
|
-
const user = (await getUserBySession(session)) as User;
|
|
48
|
-
let { data: userData, error: userError } = await supabase
|
|
49
|
-
.from("profiles")
|
|
50
|
-
.select("*")
|
|
51
|
-
.eq("uid", user.id)
|
|
52
|
-
.single();
|
|
53
|
-
|
|
54
|
-
let { data: pageData, error: pageError } = await supabase
|
|
55
|
-
.from("beatmapPages")
|
|
56
|
-
.select("*")
|
|
57
|
-
.eq("id", id)
|
|
58
|
-
.single();
|
|
59
|
-
|
|
60
|
-
if (!userData) return NextResponse.json({ error: "No user." });
|
|
61
|
-
|
|
62
|
-
let { data: beatmapData, error: bmPageError } = await supabase
|
|
63
|
-
.from("beatmaps")
|
|
64
|
-
.select("*")
|
|
65
|
-
.eq("beatmapHash", beatmapHash || "")
|
|
66
|
-
.single();
|
|
67
|
-
|
|
68
|
-
if (!beatmapData && beatmapHash) {
|
|
69
|
-
return NextResponse.json({ error: "No beatmap." });
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (userData.id !== pageData?.owner)
|
|
73
|
-
return NextResponse.json({ error: "Non-authz user." });
|
|
74
|
-
|
|
75
|
-
if (pageData?.status !== "UNRANKED")
|
|
76
|
-
return NextResponse.json({ error: "Only unranked maps can be updated" });
|
|
77
|
-
|
|
78
|
-
const upsertPayload = {
|
|
79
|
-
id,
|
|
80
|
-
genre: "",
|
|
81
|
-
status: "UNRANKED",
|
|
82
|
-
owner: userData.id,
|
|
83
|
-
description: description ? description : pageData.description,
|
|
84
|
-
tags: tags ? tags : pageData.tags,
|
|
85
|
-
updated_at: Date.now(),
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
if (beatmapHash && beatmapData) {
|
|
89
|
-
upsertPayload["title"] = beatmapData.title;
|
|
90
|
-
upsertPayload["latestBeatmapHash"] = beatmapHash;
|
|
91
|
-
upsertPayload["nominations"] = [];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const upserted = await supabase
|
|
95
|
-
.from("beatmapPages")
|
|
96
|
-
.upsert(upsertPayload)
|
|
97
|
-
.select("*")
|
|
98
|
-
.single();
|
|
99
|
-
|
|
100
|
-
if (upserted.error?.message.length) {
|
|
101
|
-
return NextResponse.json({ error: upserted.error.message });
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (beatmapData?.starRating) {
|
|
105
|
-
postBeatmapToWebhooks({
|
|
106
|
-
username: userData.username || "",
|
|
107
|
-
userid: userData.id,
|
|
108
|
-
avatar: userData.avatar_url || "",
|
|
109
|
-
mapimage: beatmapData?.image || "",
|
|
110
|
-
mapname: beatmapData?.title || "",
|
|
111
|
-
mapid: upserted.data?.id || 0,
|
|
112
|
-
mapDownload: beatmapData?.beatmapFile || "",
|
|
113
|
-
starRating: beatmapData?.starRating || 0,
|
|
114
|
-
length: beatmapData?.length || 0,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return NextResponse.json({});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const beatmapWebhookTemplate: any = {
|
|
122
|
-
content: null,
|
|
123
|
-
embeds: [
|
|
124
|
-
{
|
|
125
|
-
title: "Captain Lou Albano - Do the Mario",
|
|
126
|
-
description: "Beatmap Created",
|
|
127
|
-
url: "https://www.rhythia.com/maps/4469",
|
|
128
|
-
color: 16775930,
|
|
129
|
-
fields: [
|
|
130
|
-
{
|
|
131
|
-
name: "Star Rating",
|
|
132
|
-
value: "12.4*",
|
|
133
|
-
inline: true,
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
name: "Length",
|
|
137
|
-
value: "4:24 minutes",
|
|
138
|
-
inline: true,
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
name: "Max RP",
|
|
142
|
-
value: "100 RP",
|
|
143
|
-
inline: true,
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
author: {
|
|
147
|
-
name: "cunev",
|
|
148
|
-
url: "https://www.rhythia.com/player/0",
|
|
149
|
-
icon_url:
|
|
150
|
-
"https://static.rhythia.com/user-avatar-1735149648551-a2a8cfbe-af5d-46e8-a19a-be2339c1679a",
|
|
151
|
-
},
|
|
152
|
-
footer: {
|
|
153
|
-
text: "Sun, 22 Dec 2024 22:40:17 GMT",
|
|
154
|
-
},
|
|
155
|
-
thumbnail: {
|
|
156
|
-
url: "https://static.rhythia.com/beatmap-img-1735995790136-gen_-_frozy_tomo_-_islands_(kompa_pasi%C3%B3n)large",
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
title: "Direct download",
|
|
161
|
-
url: "https://www.rhythia.com/maps/4469",
|
|
162
|
-
color: null,
|
|
163
|
-
},
|
|
164
|
-
],
|
|
165
|
-
attachments: [],
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export async function postBeatmapToWebhooks({
|
|
169
|
-
username,
|
|
170
|
-
userid,
|
|
171
|
-
avatar,
|
|
172
|
-
mapimage,
|
|
173
|
-
mapname,
|
|
174
|
-
mapid,
|
|
175
|
-
starRating,
|
|
176
|
-
length,
|
|
177
|
-
mapDownload,
|
|
178
|
-
}: {
|
|
179
|
-
username: string;
|
|
180
|
-
userid: number;
|
|
181
|
-
avatar: string;
|
|
182
|
-
mapimage: string;
|
|
183
|
-
mapname: string;
|
|
184
|
-
mapid: number;
|
|
185
|
-
starRating: number;
|
|
186
|
-
length: number;
|
|
187
|
-
mapDownload: string;
|
|
188
|
-
}) {
|
|
189
|
-
// format length in MM:SS with padding 0
|
|
190
|
-
|
|
191
|
-
const webHooks = await supabase
|
|
192
|
-
.from("discordWebhooks")
|
|
193
|
-
.select("*")
|
|
194
|
-
.eq("type", "maps");
|
|
195
|
-
|
|
196
|
-
if (!webHooks.data) return;
|
|
197
|
-
|
|
198
|
-
for (const webhook of webHooks.data) {
|
|
199
|
-
const webhookUrl = webhook.webhook_link;
|
|
200
|
-
|
|
201
|
-
const mainEmbed = beatmapWebhookTemplate.embeds[0];
|
|
202
|
-
const downloadEmbed = beatmapWebhookTemplate.embeds[1];
|
|
203
|
-
|
|
204
|
-
mainEmbed.title = mapname;
|
|
205
|
-
mainEmbed.url = `https://www.rhythia.com/maps/${mapid}`;
|
|
206
|
-
mainEmbed.fields[0].value = `${Math.round(starRating * 100) / 100}*`;
|
|
207
|
-
mainEmbed.fields[1].value = `${formatTime(length)} minutes`;
|
|
208
|
-
mainEmbed.fields[2].value =
|
|
209
|
-
calculatePerformancePoints(starRating, 1) + " RP";
|
|
210
|
-
mainEmbed.author.name = username;
|
|
211
|
-
mainEmbed.author.url = `https://www.rhythia.com/player/${userid}`;
|
|
212
|
-
mainEmbed.author.icon_url = avatar;
|
|
213
|
-
mainEmbed.thumbnail.url = mapimage;
|
|
214
|
-
if (mapimage.includes("backfill")) {
|
|
215
|
-
mainEmbed.thumbnail.url = "https://www.rhythia.com/unkimg.png";
|
|
216
|
-
}
|
|
217
|
-
mainEmbed.footer.text = new Date().toUTCString();
|
|
218
|
-
|
|
219
|
-
downloadEmbed.url = mapDownload;
|
|
220
|
-
|
|
221
|
-
await fetch(webhookUrl, {
|
|
222
|
-
method: "POST",
|
|
223
|
-
headers: {
|
|
224
|
-
"Content-Type": "application/json",
|
|
225
|
-
},
|
|
226
|
-
body: JSON.stringify(beatmapWebhookTemplate),
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}
|
|
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
|
+
import { calculatePerformancePoints } from "./submitScore";
|
|
8
|
+
|
|
9
|
+
export const Schema = {
|
|
10
|
+
input: z.strictObject({
|
|
11
|
+
session: z.string(),
|
|
12
|
+
id: z.number(),
|
|
13
|
+
beatmapHash: z.string().optional(),
|
|
14
|
+
tags: z.string().optional(),
|
|
15
|
+
description: z.string().optional(),
|
|
16
|
+
}),
|
|
17
|
+
output: z.strictObject({
|
|
18
|
+
error: z.string().optional(),
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
23
|
+
return protectedApi({
|
|
24
|
+
request,
|
|
25
|
+
schema: Schema,
|
|
26
|
+
authorization: validUser,
|
|
27
|
+
activity: handler,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export function formatTime(milliseconds: number): string {
|
|
31
|
+
const totalSeconds = Math.floor(milliseconds / 1000);
|
|
32
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
33
|
+
const seconds = totalSeconds % 60;
|
|
34
|
+
return `${minutes.toString().padStart(2, "0")}:${seconds
|
|
35
|
+
.toString()
|
|
36
|
+
.padStart(2, "0")}`;
|
|
37
|
+
}
|
|
38
|
+
export async function handler({
|
|
39
|
+
session,
|
|
40
|
+
beatmapHash,
|
|
41
|
+
id,
|
|
42
|
+
description,
|
|
43
|
+
tags,
|
|
44
|
+
}: (typeof Schema)["input"]["_type"]): Promise<
|
|
45
|
+
NextResponse<(typeof Schema)["output"]["_type"]>
|
|
46
|
+
> {
|
|
47
|
+
const user = (await getUserBySession(session)) as User;
|
|
48
|
+
let { data: userData, error: userError } = await supabase
|
|
49
|
+
.from("profiles")
|
|
50
|
+
.select("*")
|
|
51
|
+
.eq("uid", user.id)
|
|
52
|
+
.single();
|
|
53
|
+
|
|
54
|
+
let { data: pageData, error: pageError } = await supabase
|
|
55
|
+
.from("beatmapPages")
|
|
56
|
+
.select("*")
|
|
57
|
+
.eq("id", id)
|
|
58
|
+
.single();
|
|
59
|
+
|
|
60
|
+
if (!userData) return NextResponse.json({ error: "No user." });
|
|
61
|
+
|
|
62
|
+
let { data: beatmapData, error: bmPageError } = await supabase
|
|
63
|
+
.from("beatmaps")
|
|
64
|
+
.select("*")
|
|
65
|
+
.eq("beatmapHash", beatmapHash || "")
|
|
66
|
+
.single();
|
|
67
|
+
|
|
68
|
+
if (!beatmapData && beatmapHash) {
|
|
69
|
+
return NextResponse.json({ error: "No beatmap." });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (userData.id !== pageData?.owner)
|
|
73
|
+
return NextResponse.json({ error: "Non-authz user." });
|
|
74
|
+
|
|
75
|
+
if (pageData?.status !== "UNRANKED")
|
|
76
|
+
return NextResponse.json({ error: "Only unranked maps can be updated" });
|
|
77
|
+
|
|
78
|
+
const upsertPayload = {
|
|
79
|
+
id,
|
|
80
|
+
genre: "",
|
|
81
|
+
status: "UNRANKED",
|
|
82
|
+
owner: userData.id,
|
|
83
|
+
description: description ? description : pageData.description,
|
|
84
|
+
tags: tags ? tags : pageData.tags,
|
|
85
|
+
updated_at: Date.now(),
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
if (beatmapHash && beatmapData) {
|
|
89
|
+
upsertPayload["title"] = beatmapData.title;
|
|
90
|
+
upsertPayload["latestBeatmapHash"] = beatmapHash;
|
|
91
|
+
upsertPayload["nominations"] = [];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const upserted = await supabase
|
|
95
|
+
.from("beatmapPages")
|
|
96
|
+
.upsert(upsertPayload)
|
|
97
|
+
.select("*")
|
|
98
|
+
.single();
|
|
99
|
+
|
|
100
|
+
if (upserted.error?.message.length) {
|
|
101
|
+
return NextResponse.json({ error: upserted.error.message });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (beatmapData?.starRating) {
|
|
105
|
+
postBeatmapToWebhooks({
|
|
106
|
+
username: userData.username || "",
|
|
107
|
+
userid: userData.id,
|
|
108
|
+
avatar: userData.avatar_url || "",
|
|
109
|
+
mapimage: beatmapData?.image || "",
|
|
110
|
+
mapname: beatmapData?.title || "",
|
|
111
|
+
mapid: upserted.data?.id || 0,
|
|
112
|
+
mapDownload: beatmapData?.beatmapFile || "",
|
|
113
|
+
starRating: beatmapData?.starRating || 0,
|
|
114
|
+
length: beatmapData?.length || 0,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return NextResponse.json({});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const beatmapWebhookTemplate: any = {
|
|
122
|
+
content: null,
|
|
123
|
+
embeds: [
|
|
124
|
+
{
|
|
125
|
+
title: "Captain Lou Albano - Do the Mario",
|
|
126
|
+
description: "Beatmap Created",
|
|
127
|
+
url: "https://www.rhythia.com/maps/4469",
|
|
128
|
+
color: 16775930,
|
|
129
|
+
fields: [
|
|
130
|
+
{
|
|
131
|
+
name: "Star Rating",
|
|
132
|
+
value: "12.4*",
|
|
133
|
+
inline: true,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: "Length",
|
|
137
|
+
value: "4:24 minutes",
|
|
138
|
+
inline: true,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: "Max RP",
|
|
142
|
+
value: "100 RP",
|
|
143
|
+
inline: true,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
author: {
|
|
147
|
+
name: "cunev",
|
|
148
|
+
url: "https://www.rhythia.com/player/0",
|
|
149
|
+
icon_url:
|
|
150
|
+
"https://static.rhythia.com/user-avatar-1735149648551-a2a8cfbe-af5d-46e8-a19a-be2339c1679a",
|
|
151
|
+
},
|
|
152
|
+
footer: {
|
|
153
|
+
text: "Sun, 22 Dec 2024 22:40:17 GMT",
|
|
154
|
+
},
|
|
155
|
+
thumbnail: {
|
|
156
|
+
url: "https://static.rhythia.com/beatmap-img-1735995790136-gen_-_frozy_tomo_-_islands_(kompa_pasi%C3%B3n)large",
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
title: "Direct download",
|
|
161
|
+
url: "https://www.rhythia.com/maps/4469",
|
|
162
|
+
color: null,
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
attachments: [],
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export async function postBeatmapToWebhooks({
|
|
169
|
+
username,
|
|
170
|
+
userid,
|
|
171
|
+
avatar,
|
|
172
|
+
mapimage,
|
|
173
|
+
mapname,
|
|
174
|
+
mapid,
|
|
175
|
+
starRating,
|
|
176
|
+
length,
|
|
177
|
+
mapDownload,
|
|
178
|
+
}: {
|
|
179
|
+
username: string;
|
|
180
|
+
userid: number;
|
|
181
|
+
avatar: string;
|
|
182
|
+
mapimage: string;
|
|
183
|
+
mapname: string;
|
|
184
|
+
mapid: number;
|
|
185
|
+
starRating: number;
|
|
186
|
+
length: number;
|
|
187
|
+
mapDownload: string;
|
|
188
|
+
}) {
|
|
189
|
+
// format length in MM:SS with padding 0
|
|
190
|
+
|
|
191
|
+
const webHooks = await supabase
|
|
192
|
+
.from("discordWebhooks")
|
|
193
|
+
.select("*")
|
|
194
|
+
.eq("type", "maps");
|
|
195
|
+
|
|
196
|
+
if (!webHooks.data) return;
|
|
197
|
+
|
|
198
|
+
for (const webhook of webHooks.data) {
|
|
199
|
+
const webhookUrl = webhook.webhook_link;
|
|
200
|
+
|
|
201
|
+
const mainEmbed = beatmapWebhookTemplate.embeds[0];
|
|
202
|
+
const downloadEmbed = beatmapWebhookTemplate.embeds[1];
|
|
203
|
+
|
|
204
|
+
mainEmbed.title = mapname;
|
|
205
|
+
mainEmbed.url = `https://www.rhythia.com/maps/${mapid}`;
|
|
206
|
+
mainEmbed.fields[0].value = `${Math.round(starRating * 100) / 100}*`;
|
|
207
|
+
mainEmbed.fields[1].value = `${formatTime(length)} minutes`;
|
|
208
|
+
mainEmbed.fields[2].value =
|
|
209
|
+
calculatePerformancePoints(starRating, 1) + " RP";
|
|
210
|
+
mainEmbed.author.name = username;
|
|
211
|
+
mainEmbed.author.url = `https://www.rhythia.com/player/${userid}`;
|
|
212
|
+
mainEmbed.author.icon_url = avatar;
|
|
213
|
+
mainEmbed.thumbnail.url = mapimage;
|
|
214
|
+
if (mapimage.includes("backfill")) {
|
|
215
|
+
mainEmbed.thumbnail.url = "https://www.rhythia.com/unkimg.png";
|
|
216
|
+
}
|
|
217
|
+
mainEmbed.footer.text = new Date().toUTCString();
|
|
218
|
+
|
|
219
|
+
downloadEmbed.url = mapDownload;
|
|
220
|
+
|
|
221
|
+
await fetch(webhookUrl, {
|
|
222
|
+
method: "POST",
|
|
223
|
+
headers: {
|
|
224
|
+
"Content-Type": "application/json",
|
|
225
|
+
},
|
|
226
|
+
body: JSON.stringify(beatmapWebhookTemplate),
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
package/handleApi.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
let env = "development";
|
|
3
|
-
import { profanity, CensorType } from "@2toad/profanity";
|
|
4
|
-
export function setEnvironment(
|
|
5
|
-
stage: "development" | "testing" | "production"
|
|
6
|
-
) {
|
|
7
|
-
env = stage;
|
|
8
|
-
}
|
|
9
|
-
export function handleApi<
|
|
10
|
-
T extends { url: string; input: z.ZodObject<any>; output: z.ZodObject<any> }
|
|
11
|
-
>(apiSchema: T) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
let env = "development";
|
|
3
|
+
import { profanity, CensorType } from "@2toad/profanity";
|
|
4
|
+
export function setEnvironment(
|
|
5
|
+
stage: "development" | "testing" | "production"
|
|
6
|
+
) {
|
|
7
|
+
env = stage;
|
|
8
|
+
}
|
|
9
|
+
export function handleApi<
|
|
10
|
+
T extends { url: string; input: z.ZodObject<any>; output: z.ZodObject<any> }
|
|
11
|
+
>(apiSchema: T) {
|
|
12
|
+
profanity.whitelist.addWords(["willy"]);
|
|
13
|
+
return async (input: T["input"]["_type"]): Promise<T["output"]["_type"]> => {
|
|
14
|
+
const response = await fetch(`https://${env}.rhythia.com${apiSchema.url}`, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
body: JSON.stringify(input),
|
|
17
|
+
});
|
|
18
|
+
const output = await response.text();
|
|
19
|
+
return JSON.parse(profanity.censor(output));
|
|
20
|
+
};
|
|
21
|
+
}
|
package/index.html
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
<div>Rhythia API</div>
|
|
1
|
+
<html>
|
|
2
|
+
<div>Rhythia API</div>
|
|
3
3
|
</html>
|