rhythia-api 138.0.0 → 139.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/createBeatmap.ts +3 -2
- package/api/deleteBeatmapPage.ts +69 -0
- package/api/submitScore.ts +26 -3
- package/api/updateBeatmapPage.ts +3 -0
- package/index.ts +5 -0
- package/package.json +1 -1
package/api/createBeatmap.ts
CHANGED
|
@@ -77,14 +77,15 @@ export async function handler({
|
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
await s3Client.send(command);
|
|
80
|
-
parsedData.markers.sort((a, b) => a.position - b.position);
|
|
80
|
+
const markers = parsedData.markers.sort((a, b) => a.position - b.position);
|
|
81
|
+
|
|
81
82
|
const upserted = await supabase.from("beatmaps").upsert({
|
|
82
83
|
beatmapHash: digested,
|
|
83
84
|
title: parsedData.strings.mapName,
|
|
84
85
|
playcount: 0,
|
|
85
86
|
difficulty: parsedData.metadata.difficulty,
|
|
86
87
|
noteCount: parsedData.metadata.noteCount,
|
|
87
|
-
length:
|
|
88
|
+
length: markers[markers.length - 1].position,
|
|
88
89
|
beatmapFile: url,
|
|
89
90
|
image: `https://static.rhythia.com/${imgkey}`,
|
|
90
91
|
starRating: rateMap(parsedData),
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
id: z.number(),
|
|
10
|
+
}),
|
|
11
|
+
output: z.strictObject({
|
|
12
|
+
error: z.string().optional(),
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
17
|
+
return protectedApi({
|
|
18
|
+
request,
|
|
19
|
+
schema: Schema,
|
|
20
|
+
authorization: validUser,
|
|
21
|
+
activity: handler,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function handler({
|
|
26
|
+
session,
|
|
27
|
+
id,
|
|
28
|
+
}: (typeof Schema)["input"]["_type"]): Promise<
|
|
29
|
+
NextResponse<(typeof Schema)["output"]["_type"]>
|
|
30
|
+
> {
|
|
31
|
+
const user = (await supabase.auth.getUser(session)).data.user!;
|
|
32
|
+
let { data: userData, error: userError } = await supabase
|
|
33
|
+
.from("profiles")
|
|
34
|
+
.select("*")
|
|
35
|
+
.eq("uid", user.id)
|
|
36
|
+
.single();
|
|
37
|
+
|
|
38
|
+
let { data: pageData, error: pageError } = await supabase
|
|
39
|
+
.from("beatmapPages")
|
|
40
|
+
.select("*")
|
|
41
|
+
.eq("id", id)
|
|
42
|
+
.single();
|
|
43
|
+
|
|
44
|
+
if (!pageData) return NextResponse.json({ error: "No beatmap." });
|
|
45
|
+
|
|
46
|
+
let { data: beatmapData, error: bmPageError } = await supabase
|
|
47
|
+
.from("beatmaps")
|
|
48
|
+
.select("*")
|
|
49
|
+
.eq("beatmapHash", pageData.id)
|
|
50
|
+
.single();
|
|
51
|
+
|
|
52
|
+
if (!userData) return NextResponse.json({ error: "No user." });
|
|
53
|
+
if (!beatmapData) return NextResponse.json({ error: "No beatmap." });
|
|
54
|
+
|
|
55
|
+
if (userData.id !== pageData.owner)
|
|
56
|
+
return NextResponse.json({ error: "Non-authz user." });
|
|
57
|
+
|
|
58
|
+
if (pageData.status !== "UNRANKED")
|
|
59
|
+
return NextResponse.json({ error: "Only unranked maps can be updated" });
|
|
60
|
+
|
|
61
|
+
await supabase.from("beatmapPageComments").delete().eq("beatmapPage", id);
|
|
62
|
+
await supabase.from("beatmapPages").delete().eq("id", id);
|
|
63
|
+
await supabase
|
|
64
|
+
.from("beatmaps")
|
|
65
|
+
.delete()
|
|
66
|
+
.eq("beatmapHash", beatmapData.beatmapHash);
|
|
67
|
+
|
|
68
|
+
return NextResponse.json({});
|
|
69
|
+
}
|
package/api/submitScore.ts
CHANGED
|
@@ -60,7 +60,7 @@ export async function handler({
|
|
|
60
60
|
console.log(userData);
|
|
61
61
|
let { data: beatmaps, error } = await supabase
|
|
62
62
|
.from("beatmaps")
|
|
63
|
-
.select("
|
|
63
|
+
.select("*")
|
|
64
64
|
.eq("beatmapHash", data.mapHash)
|
|
65
65
|
.single();
|
|
66
66
|
|
|
@@ -81,10 +81,33 @@ export async function handler({
|
|
|
81
81
|
|
|
82
82
|
let newPlaycount = 1;
|
|
83
83
|
|
|
84
|
-
if (beatmaps) {
|
|
85
|
-
|
|
84
|
+
if (!beatmaps) {
|
|
85
|
+
return NextResponse.json(
|
|
86
|
+
{
|
|
87
|
+
error: "Map not submitted",
|
|
88
|
+
},
|
|
89
|
+
{ status: 500 }
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (beatmaps.noteCount !== data.mapNoteCount) {
|
|
94
|
+
return NextResponse.json(
|
|
95
|
+
{
|
|
96
|
+
error: "Wrong map",
|
|
97
|
+
},
|
|
98
|
+
{ status: 500 }
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
if (beatmaps.noteCount !== data.mapNoteCount) {
|
|
102
|
+
return NextResponse.json(
|
|
103
|
+
{
|
|
104
|
+
error: "Wrong map",
|
|
105
|
+
},
|
|
106
|
+
{ status: 500 }
|
|
107
|
+
);
|
|
86
108
|
}
|
|
87
109
|
|
|
110
|
+
newPlaycount = (beatmaps.playcount || 1) + 1;
|
|
88
111
|
await supabase.from("beatmaps").upsert({
|
|
89
112
|
beatmapHash: data.mapHash,
|
|
90
113
|
title: data.mapTitle,
|
package/api/updateBeatmapPage.ts
CHANGED
|
@@ -59,6 +59,9 @@ export async function handler({
|
|
|
59
59
|
if (userData.id !== pageData?.owner)
|
|
60
60
|
return NextResponse.json({ error: "Non-authz user." });
|
|
61
61
|
|
|
62
|
+
if (pageData?.status !== "UNRANKED")
|
|
63
|
+
return NextResponse.json({ error: "Only unranked maps can be updated" });
|
|
64
|
+
|
|
62
65
|
const upserted = await supabase
|
|
63
66
|
.from("beatmapPages")
|
|
64
67
|
.upsert({
|
package/index.ts
CHANGED
|
@@ -15,6 +15,11 @@ import { Schema as CreateBeatmapPage } from "./api/createBeatmapPage"
|
|
|
15
15
|
export { Schema as SchemaCreateBeatmapPage } from "./api/createBeatmapPage"
|
|
16
16
|
export const createBeatmapPage = handleApi({url:"/api/createBeatmapPage",...CreateBeatmapPage})
|
|
17
17
|
|
|
18
|
+
// ./api/deleteBeatmapPage.ts API
|
|
19
|
+
import { Schema as DeleteBeatmapPage } from "./api/deleteBeatmapPage"
|
|
20
|
+
export { Schema as SchemaDeleteBeatmapPage } from "./api/deleteBeatmapPage"
|
|
21
|
+
export const deleteBeatmapPage = handleApi({url:"/api/deleteBeatmapPage",...DeleteBeatmapPage})
|
|
22
|
+
|
|
18
23
|
// ./api/editAboutMe.ts API
|
|
19
24
|
import { Schema as EditAboutMe } from "./api/editAboutMe"
|
|
20
25
|
export { Schema as SchemaEditAboutMe } from "./api/editAboutMe"
|