rhythia-api 102.0.0 → 103.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/editProfile.ts +1 -1
- package/api/getAvatarUploadUrl.ts +55 -0
- package/api/getLeaderboard.ts +1 -1
- package/api/getScore.ts +0 -2
- package/api/getUserScores.ts +0 -2
- package/api/submitScore.ts +0 -2
- package/index.ts +5 -0
- package/package.json +3 -1
- package/types/database.ts +0 -9
package/api/editProfile.ts
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
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 { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
7
|
+
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
8
|
+
|
|
9
|
+
const s3Client = new S3Client({
|
|
10
|
+
region: "us-east-1",
|
|
11
|
+
credentials: {
|
|
12
|
+
secretAccessKey: "0036dd2cb06d730015861d27ce0796cccb5031123e",
|
|
13
|
+
accessKeyId: "c245e893e806",
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const Schema = {
|
|
18
|
+
input: z.strictObject({
|
|
19
|
+
session: z.string(),
|
|
20
|
+
}),
|
|
21
|
+
output: z.strictObject({
|
|
22
|
+
url: z.string(),
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
27
|
+
return protectedApi({
|
|
28
|
+
request,
|
|
29
|
+
schema: Schema,
|
|
30
|
+
authorization: validUser,
|
|
31
|
+
activity: handler,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function handler({
|
|
36
|
+
session,
|
|
37
|
+
}: (typeof Schema)["input"]["_type"]): Promise<
|
|
38
|
+
NextResponse<(typeof Schema)["output"]["_type"]>
|
|
39
|
+
> {
|
|
40
|
+
const user = (await supabase.auth.getUser(session)).data.user!;
|
|
41
|
+
|
|
42
|
+
const command = new PutObjectCommand({
|
|
43
|
+
Bucket: "rhythia-avatars",
|
|
44
|
+
Key: `user-avatar-${Date.now()}-${user.id}`,
|
|
45
|
+
ContentLength: 5000000,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const presigned = await getSignedUrl(s3Client, command, {
|
|
49
|
+
expiresIn: 3600,
|
|
50
|
+
});
|
|
51
|
+
return NextResponse.json({
|
|
52
|
+
url: presigned,
|
|
53
|
+
objectKey: `user-avatar-${Date.now()}-${user.id}`,
|
|
54
|
+
});
|
|
55
|
+
}
|
package/api/getLeaderboard.ts
CHANGED
package/api/getScore.ts
CHANGED
|
@@ -18,7 +18,6 @@ export const Schema = {
|
|
|
18
18
|
id: z.number(),
|
|
19
19
|
misses: z.number().nullable(),
|
|
20
20
|
passed: z.boolean().nullable(),
|
|
21
|
-
rank: z.string().nullable(),
|
|
22
21
|
songId: z.string().nullable(),
|
|
23
22
|
userId: z.number().nullable(),
|
|
24
23
|
beatmapDifficulty: z.number().optional().nullable(),
|
|
@@ -72,7 +71,6 @@ export async function handler(
|
|
|
72
71
|
awarded_sp: score.awarded_sp,
|
|
73
72
|
beatmapHash: score.beatmapHash,
|
|
74
73
|
misses: score.misses,
|
|
75
|
-
rank: score.rank,
|
|
76
74
|
songId: score.songId,
|
|
77
75
|
beatmapDifficulty: score.beatmaps?.difficulty,
|
|
78
76
|
beatmapNotes: score.beatmaps?.noteCount,
|
package/api/getUserScores.ts
CHANGED
|
@@ -19,7 +19,6 @@ export const Schema = {
|
|
|
19
19
|
id: z.number(),
|
|
20
20
|
misses: z.number().nullable(),
|
|
21
21
|
passed: z.boolean().nullable(),
|
|
22
|
-
rank: z.string().nullable(),
|
|
23
22
|
songId: z.string().nullable(),
|
|
24
23
|
userId: z.number().nullable(),
|
|
25
24
|
beatmapDifficulty: z.number().optional().nullable(),
|
|
@@ -125,7 +124,6 @@ export async function handler(
|
|
|
125
124
|
awarded_sp: s.awarded_sp,
|
|
126
125
|
beatmapHash: s.beatmapHash,
|
|
127
126
|
misses: s.misses,
|
|
128
|
-
rank: s.rank,
|
|
129
127
|
songId: s.songId,
|
|
130
128
|
beatmapDifficulty: s.beatmaps?.difficulty,
|
|
131
129
|
beatmapNotes: s.beatmaps?.noteCount,
|
package/api/submitScore.ts
CHANGED
|
@@ -82,14 +82,12 @@ export async function handler({
|
|
|
82
82
|
console.log("p1");
|
|
83
83
|
await supabase.from("scores").upsert({
|
|
84
84
|
beatmapHash: data.mapHash,
|
|
85
|
-
noteResults: [],
|
|
86
85
|
replayHwid: data.relayHwid,
|
|
87
86
|
songId: data.songId,
|
|
88
87
|
userId: userData.id,
|
|
89
88
|
passed: data.passed,
|
|
90
89
|
misses: data.misses,
|
|
91
90
|
awarded_sp: Math.round(data.sspp * 100) / 100,
|
|
92
|
-
rank: "A",
|
|
93
91
|
});
|
|
94
92
|
console.log("p2");
|
|
95
93
|
|
package/index.ts
CHANGED
|
@@ -5,6 +5,11 @@ import { Schema as EditProfile } from "./api/editProfile"
|
|
|
5
5
|
export { Schema as SchemaEditProfile } from "./api/editProfile"
|
|
6
6
|
export const editProfile = handleApi({url:"/api/editProfile",...EditProfile})
|
|
7
7
|
|
|
8
|
+
// ./api/getAvatarUploadUrl.ts API
|
|
9
|
+
import { Schema as GetAvatarUploadUrl } from "./api/getAvatarUploadUrl"
|
|
10
|
+
export { Schema as SchemaGetAvatarUploadUrl } from "./api/getAvatarUploadUrl"
|
|
11
|
+
export const getAvatarUploadUrl = handleApi({url:"/api/getAvatarUploadUrl",...GetAvatarUploadUrl})
|
|
12
|
+
|
|
8
13
|
// ./api/getLeaderboard.ts API
|
|
9
14
|
import { Schema as GetLeaderboard } from "./api/getLeaderboard"
|
|
10
15
|
export { Schema as SchemaGetLeaderboard } from "./api/getLeaderboard"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rhythia-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "103.0.0",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"update": "bun ./scripts/update.ts",
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"@aws-sdk/client-s3": "^3.637.0",
|
|
16
|
+
"@aws-sdk/s3-request-presigner": "^3.637.0",
|
|
15
17
|
"@netlify/zip-it-and-ship-it": "^9.37.9",
|
|
16
18
|
"@supabase/supabase-js": "^2.45.1",
|
|
17
19
|
"@types/aws-lambda": "^8.10.143",
|
package/types/database.ts
CHANGED
|
@@ -108,12 +108,9 @@ export type Database = {
|
|
|
108
108
|
created_at: string
|
|
109
109
|
id: number
|
|
110
110
|
misses: number | null
|
|
111
|
-
noteResults: Json | null
|
|
112
111
|
passed: boolean | null
|
|
113
|
-
rank: string | null
|
|
114
112
|
replayHwid: string | null
|
|
115
113
|
songId: string | null
|
|
116
|
-
triggers: Json | null
|
|
117
114
|
userId: number | null
|
|
118
115
|
}
|
|
119
116
|
Insert: {
|
|
@@ -122,12 +119,9 @@ export type Database = {
|
|
|
122
119
|
created_at?: string
|
|
123
120
|
id?: number
|
|
124
121
|
misses?: number | null
|
|
125
|
-
noteResults?: Json | null
|
|
126
122
|
passed?: boolean | null
|
|
127
|
-
rank?: string | null
|
|
128
123
|
replayHwid?: string | null
|
|
129
124
|
songId?: string | null
|
|
130
|
-
triggers?: Json | null
|
|
131
125
|
userId?: number | null
|
|
132
126
|
}
|
|
133
127
|
Update: {
|
|
@@ -136,12 +130,9 @@ export type Database = {
|
|
|
136
130
|
created_at?: string
|
|
137
131
|
id?: number
|
|
138
132
|
misses?: number | null
|
|
139
|
-
noteResults?: Json | null
|
|
140
133
|
passed?: boolean | null
|
|
141
|
-
rank?: string | null
|
|
142
134
|
replayHwid?: string | null
|
|
143
135
|
songId?: string | null
|
|
144
|
-
triggers?: Json | null
|
|
145
136
|
userId?: number | null
|
|
146
137
|
}
|
|
147
138
|
Relationships: [
|