rhythia-api 182.0.0 → 183.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 -156
- package/api/createBeatmapPage.ts +64 -64
- package/api/createClan.ts +81 -81
- package/api/createCollection.ts +58 -58
- package/api/deleteBeatmapPage.ts +77 -72
- 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 +128 -126
- 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 -69
- 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 +20 -20
- package/index.html +2 -2
- package/index.ts +865 -864
- package/package.json +2 -2
- package/types/database.ts +39 -0
- 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/package-lock.json +0 -8913
package/api/getLeaderboard.ts
CHANGED
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
import { NextResponse } from "next/server";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import { protectedApi } 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
|
-
page: z.number().default(1),
|
|
12
|
-
flag: z.string().optional(),
|
|
13
|
-
spin: z.boolean().default(false),
|
|
14
|
-
}),
|
|
15
|
-
output: z.object({
|
|
16
|
-
error: z.string().optional(),
|
|
17
|
-
total: z.number(),
|
|
18
|
-
viewPerPage: z.number(),
|
|
19
|
-
currentPage: z.number(),
|
|
20
|
-
userPosition: z.number(),
|
|
21
|
-
leaderboard: z
|
|
22
|
-
.array(
|
|
23
|
-
z.object({
|
|
24
|
-
flag: z.string().nullable(),
|
|
25
|
-
id: z.number(),
|
|
26
|
-
username: z.string().nullable(),
|
|
27
|
-
play_count: z.number().nullable(),
|
|
28
|
-
skill_points: z.number().nullable(),
|
|
29
|
-
spin_skill_points: z.number().nullable(),
|
|
30
|
-
total_score: z.number().nullable(),
|
|
31
|
-
clans: z
|
|
32
|
-
.object({
|
|
33
|
-
id: z.number(),
|
|
34
|
-
acronym: z.string(),
|
|
35
|
-
})
|
|
36
|
-
.optional()
|
|
37
|
-
.nullable(),
|
|
38
|
-
})
|
|
39
|
-
)
|
|
40
|
-
.optional(),
|
|
41
|
-
}),
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export async function POST(request: Request): Promise<NextResponse> {
|
|
45
|
-
return protectedApi({
|
|
46
|
-
request,
|
|
47
|
-
schema: Schema,
|
|
48
|
-
authorization: () => {},
|
|
49
|
-
activity: handler,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function handler(
|
|
54
|
-
data: (typeof Schema)["input"]["_type"]
|
|
55
|
-
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
56
|
-
const result = await getLeaderboard(
|
|
57
|
-
data.page,
|
|
58
|
-
data.session,
|
|
59
|
-
data.spin,
|
|
60
|
-
data.flag
|
|
61
|
-
);
|
|
62
|
-
return NextResponse.json(result);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const VIEW_PER_PAGE = 50;
|
|
66
|
-
|
|
67
|
-
export async function getLeaderboard(
|
|
68
|
-
page = 1,
|
|
69
|
-
session: string,
|
|
70
|
-
spin: boolean,
|
|
71
|
-
flag?: string
|
|
72
|
-
) {
|
|
73
|
-
const getUserData = (await getUserBySession(session)) as User;
|
|
74
|
-
|
|
75
|
-
let leaderPosition = 0;
|
|
76
|
-
|
|
77
|
-
if (getUserData) {
|
|
78
|
-
let { data: queryData, error } = await supabase
|
|
79
|
-
.from("profiles")
|
|
80
|
-
.select("*")
|
|
81
|
-
.eq("uid", getUserData.id)
|
|
82
|
-
.single();
|
|
83
|
-
|
|
84
|
-
if (queryData) {
|
|
85
|
-
const { count: playersWithMorePoints, error: rankError } = await supabase
|
|
86
|
-
.from("profiles")
|
|
87
|
-
.select("*", { count: "exact", head: true })
|
|
88
|
-
.neq("ban", "excluded")
|
|
89
|
-
.gt("skill_points", queryData.skill_points);
|
|
90
|
-
|
|
91
|
-
leaderPosition = (playersWithMorePoints || 0) + 1;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const startPage = (page - 1) * VIEW_PER_PAGE;
|
|
96
|
-
const endPage = startPage + VIEW_PER_PAGE - 1;
|
|
97
|
-
const countQuery = await supabase
|
|
98
|
-
.from("profiles")
|
|
99
|
-
.select("ban", { count: "exact", head: true })
|
|
100
|
-
.neq("ban", "excluded");
|
|
101
|
-
|
|
102
|
-
let query = supabase
|
|
103
|
-
.from("profiles")
|
|
104
|
-
.select("*,clans:clan(id, acronym)")
|
|
105
|
-
.neq("ban", "excluded");
|
|
106
|
-
|
|
107
|
-
if (flag) {
|
|
108
|
-
query.eq("flag", flag);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (spin) {
|
|
112
|
-
query.order("spin_skill_points", { ascending: false });
|
|
113
|
-
} else {
|
|
114
|
-
query.order("skill_points", { ascending: false });
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
query.range(startPage, endPage);
|
|
118
|
-
|
|
119
|
-
let { data: queryData, error } = await query;
|
|
120
|
-
return {
|
|
121
|
-
total: countQuery.count || 0,
|
|
122
|
-
viewPerPage: VIEW_PER_PAGE,
|
|
123
|
-
currentPage: page,
|
|
124
|
-
userPosition: leaderPosition,
|
|
125
|
-
leaderboard: queryData?.map((user) => ({
|
|
126
|
-
flag: user.flag,
|
|
127
|
-
id: user.id,
|
|
128
|
-
play_count: user.play_count,
|
|
129
|
-
skill_points: user.skill_points,
|
|
130
|
-
spin_skill_points: user.spin_skill_points,
|
|
131
|
-
total_score: user.total_score,
|
|
132
|
-
username: user.username,
|
|
133
|
-
clans: user.clans as any,
|
|
134
|
-
})),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { protectedApi } 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
|
+
page: z.number().default(1),
|
|
12
|
+
flag: z.string().optional(),
|
|
13
|
+
spin: z.boolean().default(false),
|
|
14
|
+
}),
|
|
15
|
+
output: z.object({
|
|
16
|
+
error: z.string().optional(),
|
|
17
|
+
total: z.number(),
|
|
18
|
+
viewPerPage: z.number(),
|
|
19
|
+
currentPage: z.number(),
|
|
20
|
+
userPosition: z.number(),
|
|
21
|
+
leaderboard: z
|
|
22
|
+
.array(
|
|
23
|
+
z.object({
|
|
24
|
+
flag: z.string().nullable(),
|
|
25
|
+
id: z.number(),
|
|
26
|
+
username: z.string().nullable(),
|
|
27
|
+
play_count: z.number().nullable(),
|
|
28
|
+
skill_points: z.number().nullable(),
|
|
29
|
+
spin_skill_points: z.number().nullable(),
|
|
30
|
+
total_score: z.number().nullable(),
|
|
31
|
+
clans: z
|
|
32
|
+
.object({
|
|
33
|
+
id: z.number(),
|
|
34
|
+
acronym: z.string(),
|
|
35
|
+
})
|
|
36
|
+
.optional()
|
|
37
|
+
.nullable(),
|
|
38
|
+
})
|
|
39
|
+
)
|
|
40
|
+
.optional(),
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
45
|
+
return protectedApi({
|
|
46
|
+
request,
|
|
47
|
+
schema: Schema,
|
|
48
|
+
authorization: () => {},
|
|
49
|
+
activity: handler,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function handler(
|
|
54
|
+
data: (typeof Schema)["input"]["_type"]
|
|
55
|
+
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
56
|
+
const result = await getLeaderboard(
|
|
57
|
+
data.page,
|
|
58
|
+
data.session,
|
|
59
|
+
data.spin,
|
|
60
|
+
data.flag
|
|
61
|
+
);
|
|
62
|
+
return NextResponse.json(result);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const VIEW_PER_PAGE = 50;
|
|
66
|
+
|
|
67
|
+
export async function getLeaderboard(
|
|
68
|
+
page = 1,
|
|
69
|
+
session: string,
|
|
70
|
+
spin: boolean,
|
|
71
|
+
flag?: string
|
|
72
|
+
) {
|
|
73
|
+
const getUserData = (await getUserBySession(session)) as User;
|
|
74
|
+
|
|
75
|
+
let leaderPosition = 0;
|
|
76
|
+
|
|
77
|
+
if (getUserData) {
|
|
78
|
+
let { data: queryData, error } = await supabase
|
|
79
|
+
.from("profiles")
|
|
80
|
+
.select("*")
|
|
81
|
+
.eq("uid", getUserData.id)
|
|
82
|
+
.single();
|
|
83
|
+
|
|
84
|
+
if (queryData) {
|
|
85
|
+
const { count: playersWithMorePoints, error: rankError } = await supabase
|
|
86
|
+
.from("profiles")
|
|
87
|
+
.select("*", { count: "exact", head: true })
|
|
88
|
+
.neq("ban", "excluded")
|
|
89
|
+
.gt("skill_points", queryData.skill_points);
|
|
90
|
+
|
|
91
|
+
leaderPosition = (playersWithMorePoints || 0) + 1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const startPage = (page - 1) * VIEW_PER_PAGE;
|
|
96
|
+
const endPage = startPage + VIEW_PER_PAGE - 1;
|
|
97
|
+
const countQuery = await supabase
|
|
98
|
+
.from("profiles")
|
|
99
|
+
.select("ban", { count: "exact", head: true })
|
|
100
|
+
.neq("ban", "excluded");
|
|
101
|
+
|
|
102
|
+
let query = supabase
|
|
103
|
+
.from("profiles")
|
|
104
|
+
.select("*,clans:clan(id, acronym)")
|
|
105
|
+
.neq("ban", "excluded");
|
|
106
|
+
|
|
107
|
+
if (flag) {
|
|
108
|
+
query.eq("flag", flag);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (spin) {
|
|
112
|
+
query.order("spin_skill_points", { ascending: false });
|
|
113
|
+
} else {
|
|
114
|
+
query.order("skill_points", { ascending: false });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
query.range(startPage, endPage);
|
|
118
|
+
|
|
119
|
+
let { data: queryData, error } = await query;
|
|
120
|
+
return {
|
|
121
|
+
total: countQuery.count || 0,
|
|
122
|
+
viewPerPage: VIEW_PER_PAGE,
|
|
123
|
+
currentPage: page,
|
|
124
|
+
userPosition: leaderPosition,
|
|
125
|
+
leaderboard: queryData?.map((user) => ({
|
|
126
|
+
flag: user.flag,
|
|
127
|
+
id: user.id,
|
|
128
|
+
play_count: user.play_count,
|
|
129
|
+
skill_points: user.skill_points,
|
|
130
|
+
spin_skill_points: user.spin_skill_points,
|
|
131
|
+
total_score: user.total_score,
|
|
132
|
+
username: user.username,
|
|
133
|
+
clans: user.clans as any,
|
|
134
|
+
})),
|
|
135
|
+
};
|
|
136
|
+
}
|
package/api/getMapUploadUrl.ts
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
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
|
-
import {
|
|
7
|
-
PutBucketCorsCommand,
|
|
8
|
-
PutObjectCommand,
|
|
9
|
-
S3Client,
|
|
10
|
-
} from "@aws-sdk/client-s3";
|
|
11
|
-
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
12
|
-
import { validateIntrinsicToken } from "../utils/validateToken";
|
|
13
|
-
import { getUserBySession } from "../utils/getUserBySession";
|
|
14
|
-
import { User } from "@supabase/supabase-js";
|
|
15
|
-
|
|
16
|
-
const s3Client = new S3Client({
|
|
17
|
-
region: "auto",
|
|
18
|
-
endpoint: "https://s3.eu-central-003.backblazeb2.com",
|
|
19
|
-
credentials: {
|
|
20
|
-
secretAccessKey: process.env.SECRET_BUCKET || "",
|
|
21
|
-
accessKeyId: process.env.ACCESS_BUCKET || "",
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export const Schema = {
|
|
26
|
-
input: z.strictObject({
|
|
27
|
-
mapName: z.string().optional(),
|
|
28
|
-
session: z.string(),
|
|
29
|
-
contentLength: z.number(),
|
|
30
|
-
contentType: z.string(),
|
|
31
|
-
intrinsicToken: z.string(),
|
|
32
|
-
}),
|
|
33
|
-
output: z.strictObject({
|
|
34
|
-
error: z.string().optional(),
|
|
35
|
-
url: z.string().optional(),
|
|
36
|
-
objectKey: z.string().optional(),
|
|
37
|
-
}),
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export async function POST(request: Request): Promise<NextResponse> {
|
|
41
|
-
return protectedApi({
|
|
42
|
-
request,
|
|
43
|
-
schema: Schema,
|
|
44
|
-
authorization: validUser,
|
|
45
|
-
activity: handler,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export async function handler({
|
|
50
|
-
mapName,
|
|
51
|
-
session,
|
|
52
|
-
contentLength,
|
|
53
|
-
contentType,
|
|
54
|
-
intrinsicToken,
|
|
55
|
-
}: (typeof Schema)["input"]["_type"]): Promise<
|
|
56
|
-
NextResponse<(typeof Schema)["output"]["_type"]>
|
|
57
|
-
> {
|
|
58
|
-
const user = (await getUserBySession(session)) as User;
|
|
59
|
-
|
|
60
|
-
if (!validateIntrinsicToken(intrinsicToken)) {
|
|
61
|
-
return NextResponse.json({
|
|
62
|
-
error: "Invalid intrinsic token",
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (contentLength > 50000000) {
|
|
67
|
-
return NextResponse.json({
|
|
68
|
-
error: "Max content length exceeded.",
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (contentType !== "application/octet-stream") {
|
|
73
|
-
return NextResponse.json({
|
|
74
|
-
error: "Unnacceptable format",
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const key = `rhythia-${mapName ? mapName : user.id}-${Date.now()}.sspm`;
|
|
79
|
-
const command = new PutObjectCommand({
|
|
80
|
-
Bucket: "rhthia-avatars",
|
|
81
|
-
Key: key,
|
|
82
|
-
ContentLength: contentLength,
|
|
83
|
-
ContentType: contentType,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const presigned = await getSignedUrl(s3Client, command, {
|
|
87
|
-
expiresIn: 3600,
|
|
88
|
-
});
|
|
89
|
-
return NextResponse.json({
|
|
90
|
-
url: presigned,
|
|
91
|
-
objectKey: key,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
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
|
+
import {
|
|
7
|
+
PutBucketCorsCommand,
|
|
8
|
+
PutObjectCommand,
|
|
9
|
+
S3Client,
|
|
10
|
+
} from "@aws-sdk/client-s3";
|
|
11
|
+
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
12
|
+
import { validateIntrinsicToken } from "../utils/validateToken";
|
|
13
|
+
import { getUserBySession } from "../utils/getUserBySession";
|
|
14
|
+
import { User } from "@supabase/supabase-js";
|
|
15
|
+
|
|
16
|
+
const s3Client = new S3Client({
|
|
17
|
+
region: "auto",
|
|
18
|
+
endpoint: "https://s3.eu-central-003.backblazeb2.com",
|
|
19
|
+
credentials: {
|
|
20
|
+
secretAccessKey: process.env.SECRET_BUCKET || "",
|
|
21
|
+
accessKeyId: process.env.ACCESS_BUCKET || "",
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const Schema = {
|
|
26
|
+
input: z.strictObject({
|
|
27
|
+
mapName: z.string().optional(),
|
|
28
|
+
session: z.string(),
|
|
29
|
+
contentLength: z.number(),
|
|
30
|
+
contentType: z.string(),
|
|
31
|
+
intrinsicToken: z.string(),
|
|
32
|
+
}),
|
|
33
|
+
output: z.strictObject({
|
|
34
|
+
error: z.string().optional(),
|
|
35
|
+
url: z.string().optional(),
|
|
36
|
+
objectKey: z.string().optional(),
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
41
|
+
return protectedApi({
|
|
42
|
+
request,
|
|
43
|
+
schema: Schema,
|
|
44
|
+
authorization: validUser,
|
|
45
|
+
activity: handler,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function handler({
|
|
50
|
+
mapName,
|
|
51
|
+
session,
|
|
52
|
+
contentLength,
|
|
53
|
+
contentType,
|
|
54
|
+
intrinsicToken,
|
|
55
|
+
}: (typeof Schema)["input"]["_type"]): Promise<
|
|
56
|
+
NextResponse<(typeof Schema)["output"]["_type"]>
|
|
57
|
+
> {
|
|
58
|
+
const user = (await getUserBySession(session)) as User;
|
|
59
|
+
|
|
60
|
+
if (!validateIntrinsicToken(intrinsicToken)) {
|
|
61
|
+
return NextResponse.json({
|
|
62
|
+
error: "Invalid intrinsic token",
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (contentLength > 50000000) {
|
|
67
|
+
return NextResponse.json({
|
|
68
|
+
error: "Max content length exceeded.",
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (contentType !== "application/octet-stream") {
|
|
73
|
+
return NextResponse.json({
|
|
74
|
+
error: "Unnacceptable format",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const key = `rhythia-${mapName ? mapName : user.id}-${Date.now()}.sspm`;
|
|
79
|
+
const command = new PutObjectCommand({
|
|
80
|
+
Bucket: "rhthia-avatars",
|
|
81
|
+
Key: key,
|
|
82
|
+
ContentLength: contentLength,
|
|
83
|
+
ContentType: contentType,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const presigned = await getSignedUrl(s3Client, command, {
|
|
87
|
+
expiresIn: 3600,
|
|
88
|
+
});
|
|
89
|
+
return NextResponse.json({
|
|
90
|
+
url: presigned,
|
|
91
|
+
objectKey: key,
|
|
92
|
+
});
|
|
93
|
+
}
|
package/api/getPassToken.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
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 { encryptString } from "../utils/security";
|
|
7
|
-
export const Schema = {
|
|
8
|
-
input: z.strictObject({
|
|
9
|
-
data: z.object({
|
|
10
|
-
email: z.string(),
|
|
11
|
-
passkey: z.string(),
|
|
12
|
-
computerName: z.string(),
|
|
13
|
-
}),
|
|
14
|
-
}),
|
|
15
|
-
output: z.object({
|
|
16
|
-
token: z.string().optional(),
|
|
17
|
-
error: z.string().optional(),
|
|
18
|
-
}),
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export async function POST(request: Request): Promise<NextResponse> {
|
|
22
|
-
return protectedApi({
|
|
23
|
-
request,
|
|
24
|
-
schema: Schema,
|
|
25
|
-
authorization: () => {},
|
|
26
|
-
activity: handler,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function handler(
|
|
31
|
-
data: (typeof Schema)["input"]["_type"]
|
|
32
|
-
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
33
|
-
let { data: queryPasskey, error } = await supabase
|
|
34
|
-
.from("passkeys")
|
|
35
|
-
.select("*")
|
|
36
|
-
.eq("email", data.data.email)
|
|
37
|
-
.eq("passkey", data.data.passkey)
|
|
38
|
-
.single();
|
|
39
|
-
|
|
40
|
-
if (!queryPasskey) {
|
|
41
|
-
return NextResponse.json({
|
|
42
|
-
error: "Wrong combination",
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return NextResponse.json({
|
|
46
|
-
token: encryptString(
|
|
47
|
-
JSON.stringify({
|
|
48
|
-
userId: queryPasskey.id,
|
|
49
|
-
email: queryPasskey.email,
|
|
50
|
-
passKey: queryPasskey.passkey,
|
|
51
|
-
computerName: data.data.computerName,
|
|
52
|
-
})
|
|
53
|
-
),
|
|
54
|
-
});
|
|
55
|
-
}
|
|
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 { encryptString } from "../utils/security";
|
|
7
|
+
export const Schema = {
|
|
8
|
+
input: z.strictObject({
|
|
9
|
+
data: z.object({
|
|
10
|
+
email: z.string(),
|
|
11
|
+
passkey: z.string(),
|
|
12
|
+
computerName: z.string(),
|
|
13
|
+
}),
|
|
14
|
+
}),
|
|
15
|
+
output: z.object({
|
|
16
|
+
token: z.string().optional(),
|
|
17
|
+
error: z.string().optional(),
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
22
|
+
return protectedApi({
|
|
23
|
+
request,
|
|
24
|
+
schema: Schema,
|
|
25
|
+
authorization: () => {},
|
|
26
|
+
activity: handler,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function handler(
|
|
31
|
+
data: (typeof Schema)["input"]["_type"]
|
|
32
|
+
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
33
|
+
let { data: queryPasskey, error } = await supabase
|
|
34
|
+
.from("passkeys")
|
|
35
|
+
.select("*")
|
|
36
|
+
.eq("email", data.data.email)
|
|
37
|
+
.eq("passkey", data.data.passkey)
|
|
38
|
+
.single();
|
|
39
|
+
|
|
40
|
+
if (!queryPasskey) {
|
|
41
|
+
return NextResponse.json({
|
|
42
|
+
error: "Wrong combination",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return NextResponse.json({
|
|
46
|
+
token: encryptString(
|
|
47
|
+
JSON.stringify({
|
|
48
|
+
userId: queryPasskey.id,
|
|
49
|
+
email: queryPasskey.email,
|
|
50
|
+
passKey: queryPasskey.passkey,
|
|
51
|
+
computerName: data.data.computerName,
|
|
52
|
+
})
|
|
53
|
+
),
|
|
54
|
+
});
|
|
55
|
+
}
|