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/nominateMap.ts
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
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
|
-
mapId: 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
|
-
const tags = (queryUserData?.badges || []) as string[];
|
|
40
|
-
|
|
41
|
-
if (!tags.includes("RCT")) {
|
|
42
|
-
return NextResponse.json({ error: "Only RCTs can nominate maps!" });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const { data: mapData, error } = await supabase
|
|
46
|
-
.from("beatmapPages")
|
|
47
|
-
.select("id,nominations,owner")
|
|
48
|
-
.eq("id", data.mapId)
|
|
49
|
-
.single();
|
|
50
|
-
|
|
51
|
-
if (!mapData) {
|
|
52
|
-
return NextResponse.json({ error: "Bad map" });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (mapData.owner == queryUserData.id) {
|
|
56
|
-
return NextResponse.json({ error: "Can't nominate own map" });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if ((mapData.nominations as number[]).includes(queryUserData.id)) {
|
|
60
|
-
return NextResponse.json({ error: "Already nominated" });
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const newNominations = [
|
|
64
|
-
...(mapData.nominations! as number[]),
|
|
65
|
-
queryUserData.id,
|
|
66
|
-
];
|
|
67
|
-
if (newNominations.length == 2) {
|
|
68
|
-
await supabase.from("beatmapPages").upsert({
|
|
69
|
-
id: data.mapId,
|
|
70
|
-
nominations: newNominations,
|
|
71
|
-
status: "RANKED",
|
|
72
|
-
ranked_at: Date.now(),
|
|
73
|
-
});
|
|
74
|
-
} else {
|
|
75
|
-
await supabase.from("beatmapPages").upsert({
|
|
76
|
-
id: data.mapId,
|
|
77
|
-
nominations: newNominations,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return NextResponse.json({});
|
|
82
|
-
}
|
|
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
|
+
mapId: 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
|
+
const tags = (queryUserData?.badges || []) as string[];
|
|
40
|
+
|
|
41
|
+
if (!tags.includes("RCT")) {
|
|
42
|
+
return NextResponse.json({ error: "Only RCTs can nominate maps!" });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { data: mapData, error } = await supabase
|
|
46
|
+
.from("beatmapPages")
|
|
47
|
+
.select("id,nominations,owner")
|
|
48
|
+
.eq("id", data.mapId)
|
|
49
|
+
.single();
|
|
50
|
+
|
|
51
|
+
if (!mapData) {
|
|
52
|
+
return NextResponse.json({ error: "Bad map" });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (mapData.owner == queryUserData.id) {
|
|
56
|
+
return NextResponse.json({ error: "Can't nominate own map" });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if ((mapData.nominations as number[]).includes(queryUserData.id)) {
|
|
60
|
+
return NextResponse.json({ error: "Already nominated" });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const newNominations = [
|
|
64
|
+
...(mapData.nominations! as number[]),
|
|
65
|
+
queryUserData.id,
|
|
66
|
+
];
|
|
67
|
+
if (newNominations.length == 2) {
|
|
68
|
+
await supabase.from("beatmapPages").upsert({
|
|
69
|
+
id: data.mapId,
|
|
70
|
+
nominations: newNominations,
|
|
71
|
+
status: "RANKED",
|
|
72
|
+
ranked_at: Date.now(),
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
await supabase.from("beatmapPages").upsert({
|
|
76
|
+
id: data.mapId,
|
|
77
|
+
nominations: newNominations,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return NextResponse.json({});
|
|
82
|
+
}
|
|
@@ -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 { User } from "@supabase/supabase-js";
|
|
6
|
-
import { getUserBySession } from "../utils/getUserBySession";
|
|
7
|
-
|
|
8
|
-
export const Schema = {
|
|
9
|
-
input: z.strictObject({
|
|
10
|
-
session: z.string(),
|
|
11
|
-
page: z.number(),
|
|
12
|
-
content: z.string(),
|
|
13
|
-
}),
|
|
14
|
-
output: z.strictObject({
|
|
15
|
-
error: z.string().optional(),
|
|
16
|
-
}),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export async function POST(request: Request): Promise<NextResponse> {
|
|
20
|
-
return protectedApi({
|
|
21
|
-
request,
|
|
22
|
-
schema: Schema,
|
|
23
|
-
authorization: validUser,
|
|
24
|
-
activity: handler,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function handler({
|
|
29
|
-
session,
|
|
30
|
-
page,
|
|
31
|
-
content,
|
|
32
|
-
}: (typeof Schema)["input"]["_type"]): Promise<
|
|
33
|
-
NextResponse<(typeof Schema)["output"]["_type"]>
|
|
34
|
-
> {
|
|
35
|
-
const user = (await getUserBySession(session)) as User;
|
|
36
|
-
let { data: userData, error: userError } = await supabase
|
|
37
|
-
.from("profiles")
|
|
38
|
-
.select("*")
|
|
39
|
-
.eq("uid", user.id)
|
|
40
|
-
.single();
|
|
41
|
-
|
|
42
|
-
if (!userData) return NextResponse.json({ error: "No user." });
|
|
43
|
-
if (userData.ban !== "cool") return NextResponse.json({ error: "Error" });
|
|
44
|
-
|
|
45
|
-
const upserted = await supabase
|
|
46
|
-
.from("beatmapPageComments")
|
|
47
|
-
.upsert({
|
|
48
|
-
beatmapPage: page,
|
|
49
|
-
owner: userData.id,
|
|
50
|
-
content,
|
|
51
|
-
})
|
|
52
|
-
.select("*")
|
|
53
|
-
.single();
|
|
54
|
-
|
|
55
|
-
if (upserted.error?.message.length) {
|
|
56
|
-
return NextResponse.json({ error: upserted.error.message });
|
|
57
|
-
}
|
|
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 { User } from "@supabase/supabase-js";
|
|
6
|
+
import { getUserBySession } from "../utils/getUserBySession";
|
|
7
|
+
|
|
8
|
+
export const Schema = {
|
|
9
|
+
input: z.strictObject({
|
|
10
|
+
session: z.string(),
|
|
11
|
+
page: z.number(),
|
|
12
|
+
content: z.string(),
|
|
13
|
+
}),
|
|
14
|
+
output: z.strictObject({
|
|
15
|
+
error: z.string().optional(),
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
20
|
+
return protectedApi({
|
|
21
|
+
request,
|
|
22
|
+
schema: Schema,
|
|
23
|
+
authorization: validUser,
|
|
24
|
+
activity: handler,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function handler({
|
|
29
|
+
session,
|
|
30
|
+
page,
|
|
31
|
+
content,
|
|
32
|
+
}: (typeof Schema)["input"]["_type"]): Promise<
|
|
33
|
+
NextResponse<(typeof Schema)["output"]["_type"]>
|
|
34
|
+
> {
|
|
35
|
+
const user = (await getUserBySession(session)) as User;
|
|
36
|
+
let { data: userData, error: userError } = await supabase
|
|
37
|
+
.from("profiles")
|
|
38
|
+
.select("*")
|
|
39
|
+
.eq("uid", user.id)
|
|
40
|
+
.single();
|
|
41
|
+
|
|
42
|
+
if (!userData) return NextResponse.json({ error: "No user." });
|
|
43
|
+
if (userData.ban !== "cool") return NextResponse.json({ error: "Error" });
|
|
44
|
+
|
|
45
|
+
const upserted = await supabase
|
|
46
|
+
.from("beatmapPageComments")
|
|
47
|
+
.upsert({
|
|
48
|
+
beatmapPage: page,
|
|
49
|
+
owner: userData.id,
|
|
50
|
+
content,
|
|
51
|
+
})
|
|
52
|
+
.select("*")
|
|
53
|
+
.single();
|
|
54
|
+
|
|
55
|
+
if (upserted.error?.message.length) {
|
|
56
|
+
return NextResponse.json({ error: upserted.error.message });
|
|
57
|
+
}
|
|
58
|
+
return NextResponse.json({});
|
|
59
|
+
}
|
package/api/rankMapsArchive.ts
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
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
|
-
mapId: 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
|
-
const tags = (queryUserData?.badges || []) as string[];
|
|
40
|
-
|
|
41
|
-
if (!tags.includes("Bot")) {
|
|
42
|
-
return NextResponse.json({ error: "Only Bots can force-rank maps!" });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const { data: mapData, error } = await supabase
|
|
46
|
-
.from("beatmapPages")
|
|
47
|
-
.select("id,nominations,owner,status")
|
|
48
|
-
.eq("owner", user.id)
|
|
49
|
-
.eq("status", "UNRANKED");
|
|
50
|
-
|
|
51
|
-
if (!mapData) {
|
|
52
|
-
return NextResponse.json({ error: "Bad map" });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
for (const element of mapData) {
|
|
56
|
-
await supabase.from("beatmapPages").upsert({
|
|
57
|
-
id: element.id,
|
|
58
|
-
nominations: [queryUserData.id, queryUserData.id],
|
|
59
|
-
status: "RANKED",
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return NextResponse.json({});
|
|
64
|
-
}
|
|
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
|
+
mapId: 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
|
+
const tags = (queryUserData?.badges || []) as string[];
|
|
40
|
+
|
|
41
|
+
if (!tags.includes("Bot")) {
|
|
42
|
+
return NextResponse.json({ error: "Only Bots can force-rank maps!" });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { data: mapData, error } = await supabase
|
|
46
|
+
.from("beatmapPages")
|
|
47
|
+
.select("id,nominations,owner,status")
|
|
48
|
+
.eq("owner", user.id)
|
|
49
|
+
.eq("status", "UNRANKED");
|
|
50
|
+
|
|
51
|
+
if (!mapData) {
|
|
52
|
+
return NextResponse.json({ error: "Bad map" });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (const element of mapData) {
|
|
56
|
+
await supabase.from("beatmapPages").upsert({
|
|
57
|
+
id: element.id,
|
|
58
|
+
nominations: [queryUserData.id, queryUserData.id],
|
|
59
|
+
status: "RANKED",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return NextResponse.json({});
|
|
64
|
+
}
|
package/api/searchUsers.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
-
import { supabase } from "../utils/supabase";
|
|
5
|
-
|
|
6
|
-
export const Schema = {
|
|
7
|
-
input: z.strictObject({
|
|
8
|
-
text: z.string(),
|
|
9
|
-
}),
|
|
10
|
-
output: z.object({
|
|
11
|
-
error: z.string().optional(),
|
|
12
|
-
results: z
|
|
13
|
-
.array(
|
|
14
|
-
z.object({
|
|
15
|
-
id: z.number(),
|
|
16
|
-
username: z.string().nullable(),
|
|
17
|
-
})
|
|
18
|
-
)
|
|
19
|
-
.optional(),
|
|
20
|
-
}),
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export async function POST(request: Request) {
|
|
24
|
-
return protectedApi({
|
|
25
|
-
request,
|
|
26
|
-
schema: Schema,
|
|
27
|
-
authorization: () => {},
|
|
28
|
-
activity: handler,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
33
|
-
const { data: exactUser } = await supabase
|
|
34
|
-
.from("profiles")
|
|
35
|
-
.select("id,username")
|
|
36
|
-
.neq("ban", "excluded")
|
|
37
|
-
.eq("computedUsername", data.text.toLocaleLowerCase())
|
|
38
|
-
.single();
|
|
39
|
-
|
|
40
|
-
const { data: searchData, error } = await supabase
|
|
41
|
-
.from("profiles")
|
|
42
|
-
.select("id,username")
|
|
43
|
-
.neq("ban", "excluded")
|
|
44
|
-
.ilike("username", `%${data.text}%`)
|
|
45
|
-
.limit(10);
|
|
46
|
-
|
|
47
|
-
const conjoined = searchData || [];
|
|
48
|
-
|
|
49
|
-
if (exactUser && !conjoined.some((user) => user.id === exactUser?.id)) {
|
|
50
|
-
conjoined.unshift(exactUser);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return NextResponse.json({
|
|
54
|
-
results: conjoined || [],
|
|
55
|
-
});
|
|
56
|
-
}
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { protectedApi } from "../utils/requestUtils";
|
|
4
|
+
import { supabase } from "../utils/supabase";
|
|
5
|
+
|
|
6
|
+
export const Schema = {
|
|
7
|
+
input: z.strictObject({
|
|
8
|
+
text: z.string(),
|
|
9
|
+
}),
|
|
10
|
+
output: z.object({
|
|
11
|
+
error: z.string().optional(),
|
|
12
|
+
results: z
|
|
13
|
+
.array(
|
|
14
|
+
z.object({
|
|
15
|
+
id: z.number(),
|
|
16
|
+
username: z.string().nullable(),
|
|
17
|
+
})
|
|
18
|
+
)
|
|
19
|
+
.optional(),
|
|
20
|
+
}),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export async function POST(request: Request) {
|
|
24
|
+
return protectedApi({
|
|
25
|
+
request,
|
|
26
|
+
schema: Schema,
|
|
27
|
+
authorization: () => {},
|
|
28
|
+
activity: handler,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function handler(data: (typeof Schema)["input"]["_type"]) {
|
|
33
|
+
const { data: exactUser } = await supabase
|
|
34
|
+
.from("profiles")
|
|
35
|
+
.select("id,username")
|
|
36
|
+
.neq("ban", "excluded")
|
|
37
|
+
.eq("computedUsername", data.text.toLocaleLowerCase())
|
|
38
|
+
.single();
|
|
39
|
+
|
|
40
|
+
const { data: searchData, error } = await supabase
|
|
41
|
+
.from("profiles")
|
|
42
|
+
.select("id,username")
|
|
43
|
+
.neq("ban", "excluded")
|
|
44
|
+
.ilike("username", `%${data.text}%`)
|
|
45
|
+
.limit(10);
|
|
46
|
+
|
|
47
|
+
const conjoined = searchData || [];
|
|
48
|
+
|
|
49
|
+
if (exactUser && !conjoined.some((user) => user.id === exactUser?.id)) {
|
|
50
|
+
conjoined.unshift(exactUser);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return NextResponse.json({
|
|
54
|
+
results: conjoined || [],
|
|
55
|
+
});
|
|
56
|
+
}
|
package/api/setPasskey.ts
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import { Database } from "../types/database";
|
|
4
|
-
import { protectedApi, validUser } from "../utils/requestUtils";
|
|
5
|
-
import { supabase } from "../utils/supabase";
|
|
6
|
-
import { getUserBySession } from "../utils/getUserBySession";
|
|
7
|
-
import { User } from "@supabase/supabase-js";
|
|
8
|
-
export const Schema = {
|
|
9
|
-
input: z.strictObject({
|
|
10
|
-
session: z.string(),
|
|
11
|
-
data: z.object({
|
|
12
|
-
passkey: z.string(),
|
|
13
|
-
}),
|
|
14
|
-
}),
|
|
15
|
-
output: z.object({
|
|
16
|
-
error: z.string().optional(),
|
|
17
|
-
}),
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export async function POST(request: Request): Promise<NextResponse> {
|
|
21
|
-
return protectedApi({
|
|
22
|
-
request,
|
|
23
|
-
schema: Schema,
|
|
24
|
-
authorization: () => {},
|
|
25
|
-
activity: handler,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export async function handler(
|
|
30
|
-
data: (typeof Schema)["input"]["_type"]
|
|
31
|
-
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
32
|
-
const user = (await getUserBySession(data.session)) as User;
|
|
33
|
-
let userData: Database["public"]["Tables"]["profiles"]["Update"];
|
|
34
|
-
// Find user's entry
|
|
35
|
-
{
|
|
36
|
-
let { data: queryUserData, error } = await supabase
|
|
37
|
-
.from("profiles")
|
|
38
|
-
.select("*")
|
|
39
|
-
.eq("uid", user.id);
|
|
40
|
-
|
|
41
|
-
if (!queryUserData?.length) {
|
|
42
|
-
return NextResponse.json(
|
|
43
|
-
{
|
|
44
|
-
error: "User cannot be retrieved from session",
|
|
45
|
-
},
|
|
46
|
-
{ status: 404 }
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
userData = queryUserData[0];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
await supabase.from("passkeys").upsert({
|
|
53
|
-
id: userData.id!,
|
|
54
|
-
email: user.email!,
|
|
55
|
-
passkey: data.data.passkey,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return NextResponse.json({});
|
|
59
|
-
}
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { Database } from "../types/database";
|
|
4
|
+
import { protectedApi, validUser } from "../utils/requestUtils";
|
|
5
|
+
import { supabase } from "../utils/supabase";
|
|
6
|
+
import { getUserBySession } from "../utils/getUserBySession";
|
|
7
|
+
import { User } from "@supabase/supabase-js";
|
|
8
|
+
export const Schema = {
|
|
9
|
+
input: z.strictObject({
|
|
10
|
+
session: z.string(),
|
|
11
|
+
data: z.object({
|
|
12
|
+
passkey: z.string(),
|
|
13
|
+
}),
|
|
14
|
+
}),
|
|
15
|
+
output: z.object({
|
|
16
|
+
error: z.string().optional(),
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
21
|
+
return protectedApi({
|
|
22
|
+
request,
|
|
23
|
+
schema: Schema,
|
|
24
|
+
authorization: () => {},
|
|
25
|
+
activity: handler,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function handler(
|
|
30
|
+
data: (typeof Schema)["input"]["_type"]
|
|
31
|
+
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
32
|
+
const user = (await getUserBySession(data.session)) as User;
|
|
33
|
+
let userData: Database["public"]["Tables"]["profiles"]["Update"];
|
|
34
|
+
// Find user's entry
|
|
35
|
+
{
|
|
36
|
+
let { data: queryUserData, error } = await supabase
|
|
37
|
+
.from("profiles")
|
|
38
|
+
.select("*")
|
|
39
|
+
.eq("uid", user.id);
|
|
40
|
+
|
|
41
|
+
if (!queryUserData?.length) {
|
|
42
|
+
return NextResponse.json(
|
|
43
|
+
{
|
|
44
|
+
error: "User cannot be retrieved from session",
|
|
45
|
+
},
|
|
46
|
+
{ status: 404 }
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
userData = queryUserData[0];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
await supabase.from("passkeys").upsert({
|
|
53
|
+
id: userData.id!,
|
|
54
|
+
email: user.email!,
|
|
55
|
+
passkey: data.data.passkey,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return NextResponse.json({});
|
|
59
|
+
}
|