rhythia-api 186.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 -132
- 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 -867
- package/package.json +1 -1
- package/types/database.ts +800 -800
- 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/createCollection.ts
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
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
|
-
|
|
8
|
-
export const Schema = {
|
|
9
|
-
input: z.strictObject({
|
|
10
|
-
session: z.string(),
|
|
11
|
-
title: z.string(),
|
|
12
|
-
}),
|
|
13
|
-
output: z.object({
|
|
14
|
-
id: z.number(),
|
|
15
|
-
error: z.string().optional(),
|
|
16
|
-
}),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export async function POST(request: Request) {
|
|
20
|
-
return protectedApi({
|
|
21
|
-
request,
|
|
22
|
-
schema: Schema,
|
|
23
|
-
authorization: validUser,
|
|
24
|
-
activity: handler,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
29
|
-
const user = (await getUserBySession(data.session)) as User;
|
|
30
|
-
let { data: queryUserData, error: userError } = await supabase
|
|
31
|
-
.from("profiles")
|
|
32
|
-
.select("*")
|
|
33
|
-
.eq("uid", user.id)
|
|
34
|
-
.single();
|
|
35
|
-
|
|
36
|
-
if (!queryUserData) {
|
|
37
|
-
return NextResponse.json({ error: "Can't find user" });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (data.title.length < 3) {
|
|
41
|
-
return NextResponse.json({
|
|
42
|
-
error: "Collection title should be longer than 3",
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
const inserted = await supabase
|
|
46
|
-
.from("beatmapCollections")
|
|
47
|
-
.insert({
|
|
48
|
-
title: data.title,
|
|
49
|
-
description: "",
|
|
50
|
-
owner: queryUserData.id,
|
|
51
|
-
})
|
|
52
|
-
.select("*")
|
|
53
|
-
.single();
|
|
54
|
-
|
|
55
|
-
return NextResponse.json({
|
|
56
|
-
id: inserted.data!.id,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
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
|
+
|
|
8
|
+
export const Schema = {
|
|
9
|
+
input: z.strictObject({
|
|
10
|
+
session: z.string(),
|
|
11
|
+
title: z.string(),
|
|
12
|
+
}),
|
|
13
|
+
output: z.object({
|
|
14
|
+
id: z.number(),
|
|
15
|
+
error: z.string().optional(),
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export async function POST(request: Request) {
|
|
20
|
+
return protectedApi({
|
|
21
|
+
request,
|
|
22
|
+
schema: Schema,
|
|
23
|
+
authorization: validUser,
|
|
24
|
+
activity: handler,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
29
|
+
const user = (await getUserBySession(data.session)) as User;
|
|
30
|
+
let { data: queryUserData, error: userError } = await supabase
|
|
31
|
+
.from("profiles")
|
|
32
|
+
.select("*")
|
|
33
|
+
.eq("uid", user.id)
|
|
34
|
+
.single();
|
|
35
|
+
|
|
36
|
+
if (!queryUserData) {
|
|
37
|
+
return NextResponse.json({ error: "Can't find user" });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (data.title.length < 3) {
|
|
41
|
+
return NextResponse.json({
|
|
42
|
+
error: "Collection title should be longer than 3",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const inserted = await supabase
|
|
46
|
+
.from("beatmapCollections")
|
|
47
|
+
.insert({
|
|
48
|
+
title: data.title,
|
|
49
|
+
description: "",
|
|
50
|
+
owner: queryUserData.id,
|
|
51
|
+
})
|
|
52
|
+
.select("*")
|
|
53
|
+
.single();
|
|
54
|
+
|
|
55
|
+
return NextResponse.json({
|
|
56
|
+
id: inserted.data!.id,
|
|
57
|
+
});
|
|
58
|
+
}
|
package/api/deleteBeatmapPage.ts
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
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
|
-
|
|
8
|
-
export const Schema = {
|
|
9
|
-
input: z.strictObject({
|
|
10
|
-
session: z.string(),
|
|
11
|
-
id: z.number(),
|
|
12
|
-
}),
|
|
13
|
-
output: z.strictObject({
|
|
14
|
-
error: z.string().optional(),
|
|
15
|
-
}),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export async function POST(request: Request): Promise<NextResponse> {
|
|
19
|
-
return protectedApi({
|
|
20
|
-
request,
|
|
21
|
-
schema: Schema,
|
|
22
|
-
authorization: validUser,
|
|
23
|
-
activity: handler,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function handler({
|
|
28
|
-
session,
|
|
29
|
-
id,
|
|
30
|
-
}: (typeof Schema)["input"]["_type"]): Promise<
|
|
31
|
-
NextResponse<(typeof Schema)["output"]["_type"]>
|
|
32
|
-
> {
|
|
33
|
-
const user = (await getUserBySession(session)) as User;
|
|
34
|
-
let { data: userData, error: userError } = await supabase
|
|
35
|
-
.from("profiles")
|
|
36
|
-
.select("*")
|
|
37
|
-
.eq("uid", user.id)
|
|
38
|
-
.single();
|
|
39
|
-
|
|
40
|
-
let { data: pageData, error: pageError } = await supabase
|
|
41
|
-
.from("beatmapPages")
|
|
42
|
-
.select("*")
|
|
43
|
-
.eq("id", id)
|
|
44
|
-
.single();
|
|
45
|
-
|
|
46
|
-
if (!pageData) return NextResponse.json({ error: "No beatmap." });
|
|
47
|
-
|
|
48
|
-
let { data: beatmapData, error: bmPageError } = await supabase
|
|
49
|
-
.from("beatmaps")
|
|
50
|
-
.select("*")
|
|
51
|
-
.eq("beatmapHash", pageData.latestBeatmapHash || "-1-1-1-1")
|
|
52
|
-
.single();
|
|
53
|
-
|
|
54
|
-
if (!userData) return NextResponse.json({ error: "No user." });
|
|
55
|
-
if (!beatmapData) return NextResponse.json({ error: "No beatmap." });
|
|
56
|
-
|
|
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
|
-
}
|
|
64
|
-
|
|
65
|
-
if (pageData.status !== "UNRANKED")
|
|
66
|
-
return NextResponse.json({ error: "Only unranked maps can be updated" });
|
|
67
|
-
|
|
68
|
-
await supabase.from("beatmapPageComments").delete().eq("beatmapPage", id);
|
|
69
|
-
await supabase.from("collectionRelations").delete().eq("beatmapPage", id);
|
|
70
|
-
await supabase.from("beatmapPages").delete().eq("id", id);
|
|
71
|
-
await supabase
|
|
72
|
-
.from("beatmaps")
|
|
73
|
-
.delete()
|
|
74
|
-
.eq("beatmapHash", beatmapData.beatmapHash);
|
|
75
|
-
|
|
76
|
-
return NextResponse.json({});
|
|
77
|
-
}
|
|
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
|
+
|
|
8
|
+
export const Schema = {
|
|
9
|
+
input: z.strictObject({
|
|
10
|
+
session: z.string(),
|
|
11
|
+
id: z.number(),
|
|
12
|
+
}),
|
|
13
|
+
output: z.strictObject({
|
|
14
|
+
error: z.string().optional(),
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
19
|
+
return protectedApi({
|
|
20
|
+
request,
|
|
21
|
+
schema: Schema,
|
|
22
|
+
authorization: validUser,
|
|
23
|
+
activity: handler,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function handler({
|
|
28
|
+
session,
|
|
29
|
+
id,
|
|
30
|
+
}: (typeof Schema)["input"]["_type"]): Promise<
|
|
31
|
+
NextResponse<(typeof Schema)["output"]["_type"]>
|
|
32
|
+
> {
|
|
33
|
+
const user = (await getUserBySession(session)) as User;
|
|
34
|
+
let { data: userData, error: userError } = await supabase
|
|
35
|
+
.from("profiles")
|
|
36
|
+
.select("*")
|
|
37
|
+
.eq("uid", user.id)
|
|
38
|
+
.single();
|
|
39
|
+
|
|
40
|
+
let { data: pageData, error: pageError } = await supabase
|
|
41
|
+
.from("beatmapPages")
|
|
42
|
+
.select("*")
|
|
43
|
+
.eq("id", id)
|
|
44
|
+
.single();
|
|
45
|
+
|
|
46
|
+
if (!pageData) return NextResponse.json({ error: "No beatmap." });
|
|
47
|
+
|
|
48
|
+
let { data: beatmapData, error: bmPageError } = await supabase
|
|
49
|
+
.from("beatmaps")
|
|
50
|
+
.select("*")
|
|
51
|
+
.eq("beatmapHash", pageData.latestBeatmapHash || "-1-1-1-1")
|
|
52
|
+
.single();
|
|
53
|
+
|
|
54
|
+
if (!userData) return NextResponse.json({ error: "No user." });
|
|
55
|
+
if (!beatmapData) return NextResponse.json({ error: "No beatmap." });
|
|
56
|
+
|
|
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
|
+
}
|
|
64
|
+
|
|
65
|
+
if (pageData.status !== "UNRANKED")
|
|
66
|
+
return NextResponse.json({ error: "Only unranked maps can be updated" });
|
|
67
|
+
|
|
68
|
+
await supabase.from("beatmapPageComments").delete().eq("beatmapPage", id);
|
|
69
|
+
await supabase.from("collectionRelations").delete().eq("beatmapPage", id);
|
|
70
|
+
await supabase.from("beatmapPages").delete().eq("id", id);
|
|
71
|
+
await supabase
|
|
72
|
+
.from("beatmaps")
|
|
73
|
+
.delete()
|
|
74
|
+
.eq("beatmapHash", beatmapData.beatmapHash);
|
|
75
|
+
|
|
76
|
+
return NextResponse.json({});
|
|
77
|
+
}
|
package/api/deleteCollection.ts
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
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
|
-
|
|
8
|
-
export const Schema = {
|
|
9
|
-
input: z.strictObject({
|
|
10
|
-
session: z.string(),
|
|
11
|
-
collection: z.number(),
|
|
12
|
-
}),
|
|
13
|
-
output: z.object({
|
|
14
|
-
error: z.string().optional(),
|
|
15
|
-
}),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export async function POST(request: Request) {
|
|
19
|
-
return protectedApi({
|
|
20
|
-
request,
|
|
21
|
-
schema: Schema,
|
|
22
|
-
authorization: validUser,
|
|
23
|
-
activity: handler,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
28
|
-
const user = (await getUserBySession(data.session)) as User;
|
|
29
|
-
let { data: queryUserData, error: userError } = await supabase
|
|
30
|
-
.from("profiles")
|
|
31
|
-
.select("*")
|
|
32
|
-
.eq("uid", user.id)
|
|
33
|
-
.single();
|
|
34
|
-
|
|
35
|
-
if (!queryUserData) {
|
|
36
|
-
return NextResponse.json({ error: "Can't find user" });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let { data: queryCollectionData, error: collectionError } = await supabase
|
|
40
|
-
.from("beatmapCollections")
|
|
41
|
-
.select("*")
|
|
42
|
-
.eq("id", data.collection)
|
|
43
|
-
.single();
|
|
44
|
-
|
|
45
|
-
if (!queryCollectionData) {
|
|
46
|
-
return NextResponse.json({ error: "Can't find collection" });
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (queryCollectionData.owner !== queryUserData.id) {
|
|
50
|
-
return NextResponse.json({ error: "You can't update foreign collections" });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
await supabase.from("beatmapCollections").delete().eq("id", data.collection);
|
|
54
|
-
await supabase
|
|
55
|
-
.from("collectionRelations")
|
|
56
|
-
.delete()
|
|
57
|
-
.eq("collection", data.collection);
|
|
58
|
-
return NextResponse.json({});
|
|
59
|
-
}
|
|
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
|
+
|
|
8
|
+
export const Schema = {
|
|
9
|
+
input: z.strictObject({
|
|
10
|
+
session: z.string(),
|
|
11
|
+
collection: z.number(),
|
|
12
|
+
}),
|
|
13
|
+
output: z.object({
|
|
14
|
+
error: z.string().optional(),
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export async function POST(request: Request) {
|
|
19
|
+
return protectedApi({
|
|
20
|
+
request,
|
|
21
|
+
schema: Schema,
|
|
22
|
+
authorization: validUser,
|
|
23
|
+
activity: handler,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
28
|
+
const user = (await getUserBySession(data.session)) as User;
|
|
29
|
+
let { data: queryUserData, error: userError } = await supabase
|
|
30
|
+
.from("profiles")
|
|
31
|
+
.select("*")
|
|
32
|
+
.eq("uid", user.id)
|
|
33
|
+
.single();
|
|
34
|
+
|
|
35
|
+
if (!queryUserData) {
|
|
36
|
+
return NextResponse.json({ error: "Can't find user" });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let { data: queryCollectionData, error: collectionError } = await supabase
|
|
40
|
+
.from("beatmapCollections")
|
|
41
|
+
.select("*")
|
|
42
|
+
.eq("id", data.collection)
|
|
43
|
+
.single();
|
|
44
|
+
|
|
45
|
+
if (!queryCollectionData) {
|
|
46
|
+
return NextResponse.json({ error: "Can't find collection" });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (queryCollectionData.owner !== queryUserData.id) {
|
|
50
|
+
return NextResponse.json({ error: "You can't update foreign collections" });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await supabase.from("beatmapCollections").delete().eq("id", data.collection);
|
|
54
|
+
await supabase
|
|
55
|
+
.from("collectionRelations")
|
|
56
|
+
.delete()
|
|
57
|
+
.eq("collection", data.collection);
|
|
58
|
+
return NextResponse.json({});
|
|
59
|
+
}
|
|
@@ -1,71 +1,71 @@
|
|
|
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
|
-
|
|
8
|
-
export const Schema = {
|
|
9
|
-
input: z.strictObject({
|
|
10
|
-
session: z.string(),
|
|
11
|
-
collection: z.number(),
|
|
12
|
-
beatmapPage: z.number(),
|
|
13
|
-
}),
|
|
14
|
-
output: z.object({
|
|
15
|
-
error: z.string().optional(),
|
|
16
|
-
}),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export async function POST(request: Request) {
|
|
20
|
-
return protectedApi({
|
|
21
|
-
request,
|
|
22
|
-
schema: Schema,
|
|
23
|
-
authorization: validUser,
|
|
24
|
-
activity: handler,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
29
|
-
const user = (await getUserBySession(data.session)) as User;
|
|
30
|
-
let { data: queryUserData, error: userError } = await supabase
|
|
31
|
-
.from("profiles")
|
|
32
|
-
.select("*")
|
|
33
|
-
.eq("uid", user.id)
|
|
34
|
-
.single();
|
|
35
|
-
|
|
36
|
-
if (!queryUserData) {
|
|
37
|
-
return NextResponse.json({ error: "Can't find user" });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
let { data: queryCollectionData, error: collectionError } = await supabase
|
|
41
|
-
.from("beatmapCollections")
|
|
42
|
-
.select("*")
|
|
43
|
-
.eq("id", data.collection)
|
|
44
|
-
.single();
|
|
45
|
-
|
|
46
|
-
let { data: queryBeatmapData, error: beatmapData } = await supabase
|
|
47
|
-
.from("beatmapPages")
|
|
48
|
-
.select("*")
|
|
49
|
-
.eq("id", data.beatmapPage)
|
|
50
|
-
.single();
|
|
51
|
-
|
|
52
|
-
if (!queryCollectionData) {
|
|
53
|
-
return NextResponse.json({ error: "Can't find collection" });
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (!queryBeatmapData) {
|
|
57
|
-
return NextResponse.json({ error: "Can't find beatmap page" });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (queryCollectionData.owner !== queryUserData.id) {
|
|
61
|
-
return NextResponse.json({ error: "You can't update foreign collections" });
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
await supabase
|
|
65
|
-
.from("collectionRelations")
|
|
66
|
-
.delete()
|
|
67
|
-
.eq("beatmapPage", data.beatmapPage)
|
|
68
|
-
.eq("collection", data.collection);
|
|
69
|
-
|
|
70
|
-
return NextResponse.json({});
|
|
71
|
-
}
|
|
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
|
+
|
|
8
|
+
export const Schema = {
|
|
9
|
+
input: z.strictObject({
|
|
10
|
+
session: z.string(),
|
|
11
|
+
collection: z.number(),
|
|
12
|
+
beatmapPage: z.number(),
|
|
13
|
+
}),
|
|
14
|
+
output: z.object({
|
|
15
|
+
error: z.string().optional(),
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export async function POST(request: Request) {
|
|
20
|
+
return protectedApi({
|
|
21
|
+
request,
|
|
22
|
+
schema: Schema,
|
|
23
|
+
authorization: validUser,
|
|
24
|
+
activity: handler,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
29
|
+
const user = (await getUserBySession(data.session)) as User;
|
|
30
|
+
let { data: queryUserData, error: userError } = await supabase
|
|
31
|
+
.from("profiles")
|
|
32
|
+
.select("*")
|
|
33
|
+
.eq("uid", user.id)
|
|
34
|
+
.single();
|
|
35
|
+
|
|
36
|
+
if (!queryUserData) {
|
|
37
|
+
return NextResponse.json({ error: "Can't find user" });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let { data: queryCollectionData, error: collectionError } = await supabase
|
|
41
|
+
.from("beatmapCollections")
|
|
42
|
+
.select("*")
|
|
43
|
+
.eq("id", data.collection)
|
|
44
|
+
.single();
|
|
45
|
+
|
|
46
|
+
let { data: queryBeatmapData, error: beatmapData } = await supabase
|
|
47
|
+
.from("beatmapPages")
|
|
48
|
+
.select("*")
|
|
49
|
+
.eq("id", data.beatmapPage)
|
|
50
|
+
.single();
|
|
51
|
+
|
|
52
|
+
if (!queryCollectionData) {
|
|
53
|
+
return NextResponse.json({ error: "Can't find collection" });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!queryBeatmapData) {
|
|
57
|
+
return NextResponse.json({ error: "Can't find beatmap page" });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (queryCollectionData.owner !== queryUserData.id) {
|
|
61
|
+
return NextResponse.json({ error: "You can't update foreign collections" });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await supabase
|
|
65
|
+
.from("collectionRelations")
|
|
66
|
+
.delete()
|
|
67
|
+
.eq("beatmapPage", data.beatmapPage)
|
|
68
|
+
.eq("collection", data.collection);
|
|
69
|
+
|
|
70
|
+
return NextResponse.json({});
|
|
71
|
+
}
|