rhythia-api 104.0.0 → 106.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/editAboutMe.ts +89 -0
- package/api/editProfile.ts +15 -1
- package/api/getAvatarUploadUrl.ts +9 -3
- package/api/getMapUploadUrl.ts +76 -0
- package/api/getProfile.ts +4 -2
- package/index.ts +10 -0
- package/package.json +2 -2
- package/types/database.ts +13 -1
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
export const Schema = {
|
|
7
|
+
input: z.strictObject({
|
|
8
|
+
session: z.string(),
|
|
9
|
+
data: z.object({
|
|
10
|
+
about_me: z.string().optional(),
|
|
11
|
+
}),
|
|
12
|
+
}),
|
|
13
|
+
output: z.object({
|
|
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
|
+
data: (typeof Schema)["input"]["_type"]
|
|
29
|
+
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
30
|
+
if (!data.data.about_me) {
|
|
31
|
+
return NextResponse.json(
|
|
32
|
+
{
|
|
33
|
+
error: "Missing body.",
|
|
34
|
+
},
|
|
35
|
+
{ status: 404 }
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (data.data.about_me.length > 500) {
|
|
40
|
+
return NextResponse.json(
|
|
41
|
+
{
|
|
42
|
+
error: "Too long.",
|
|
43
|
+
},
|
|
44
|
+
{ status: 404 }
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const user = (await supabase.auth.getUser(data.session)).data.user!;
|
|
49
|
+
let userData: Database["public"]["Tables"]["profiles"]["Update"];
|
|
50
|
+
|
|
51
|
+
// Find user's entry
|
|
52
|
+
{
|
|
53
|
+
let { data: queryUserData, error } = await supabase
|
|
54
|
+
.from("profiles")
|
|
55
|
+
.select("*")
|
|
56
|
+
.eq("uid", user.id);
|
|
57
|
+
|
|
58
|
+
if (!queryUserData?.length) {
|
|
59
|
+
return NextResponse.json(
|
|
60
|
+
{
|
|
61
|
+
error: "User cannot be retrieved from session",
|
|
62
|
+
},
|
|
63
|
+
{ status: 404 }
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
userData = queryUserData[0];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const upsertPayload: Database["public"]["Tables"]["profiles"]["Update"] = {
|
|
70
|
+
id: userData.id,
|
|
71
|
+
about_me: data.data.about_me,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const upsertResult = await supabase
|
|
75
|
+
.from("profiles")
|
|
76
|
+
.upsert(upsertPayload)
|
|
77
|
+
.select();
|
|
78
|
+
|
|
79
|
+
if (upsertResult.error) {
|
|
80
|
+
return NextResponse.json(
|
|
81
|
+
{
|
|
82
|
+
error: "Can't update..",
|
|
83
|
+
},
|
|
84
|
+
{ status: 404 }
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return NextResponse.json({});
|
|
89
|
+
}
|
package/api/editProfile.ts
CHANGED
|
@@ -8,7 +8,6 @@ export const Schema = {
|
|
|
8
8
|
session: z.string(),
|
|
9
9
|
data: z.object({
|
|
10
10
|
avatar_url: z.string().optional(),
|
|
11
|
-
about_me: z.string().optional(),
|
|
12
11
|
username: z.string().optional(),
|
|
13
12
|
}),
|
|
14
13
|
}),
|
|
@@ -48,6 +47,7 @@ export async function handler(
|
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
const user = (await supabase.auth.getUser(data.session)).data.user!;
|
|
50
|
+
|
|
51
51
|
let userData: Database["public"]["Tables"]["profiles"]["Update"];
|
|
52
52
|
|
|
53
53
|
// Find user's entry
|
|
@@ -68,6 +68,20 @@ export async function handler(
|
|
|
68
68
|
userData = queryUserData[0];
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
if (
|
|
72
|
+
userData.ban == "excluded" ||
|
|
73
|
+
userData.ban == "restricted" ||
|
|
74
|
+
userData.ban == "silenced"
|
|
75
|
+
) {
|
|
76
|
+
return NextResponse.json(
|
|
77
|
+
{
|
|
78
|
+
error:
|
|
79
|
+
"Silenced, restricted or excluded players can't update their profile.",
|
|
80
|
+
},
|
|
81
|
+
{ status: 404 }
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
71
85
|
const upsertPayload: Database["public"]["Tables"]["profiles"]["Update"] = {
|
|
72
86
|
id: userData.id,
|
|
73
87
|
computedUsername: data.data.username?.toLowerCase(),
|
|
@@ -3,10 +3,15 @@ import z from "zod";
|
|
|
3
3
|
import { protectedApi, validUser } from "../utils/requestUtils";
|
|
4
4
|
import { supabase } from "../utils/supabase";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
PutBucketCorsCommand,
|
|
8
|
+
PutObjectCommand,
|
|
9
|
+
S3Client,
|
|
10
|
+
} from "@aws-sdk/client-s3";
|
|
7
11
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
8
12
|
|
|
9
13
|
const s3Client = new S3Client({
|
|
14
|
+
region: "auto",
|
|
10
15
|
endpoint: "https://s3.eu-central-003.backblazeb2.com",
|
|
11
16
|
credentials: {
|
|
12
17
|
secretAccessKey: "K0039mm4iKsteQOXpZSzf0+VDzuH89U",
|
|
@@ -51,9 +56,10 @@ export async function handler({
|
|
|
51
56
|
});
|
|
52
57
|
}
|
|
53
58
|
|
|
59
|
+
const key = `user-avatar-${Date.now()}-${user.id}`;
|
|
54
60
|
const command = new PutObjectCommand({
|
|
55
61
|
Bucket: "rhthia-avatars",
|
|
56
|
-
Key:
|
|
62
|
+
Key: key,
|
|
57
63
|
ContentLength: contentLength,
|
|
58
64
|
ContentType: contentType,
|
|
59
65
|
});
|
|
@@ -63,6 +69,6 @@ export async function handler({
|
|
|
63
69
|
});
|
|
64
70
|
return NextResponse.json({
|
|
65
71
|
url: presigned,
|
|
66
|
-
objectKey:
|
|
72
|
+
objectKey: key,
|
|
67
73
|
});
|
|
68
74
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
|
|
13
|
+
const s3Client = new S3Client({
|
|
14
|
+
region: "auto",
|
|
15
|
+
endpoint: "https://s3.eu-central-003.backblazeb2.com",
|
|
16
|
+
credentials: {
|
|
17
|
+
secretAccessKey: "K0039mm4iKsteQOXpZSzf0+VDzuH89U",
|
|
18
|
+
accessKeyId: "003c245e893e8060000000001",
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const Schema = {
|
|
23
|
+
input: z.strictObject({
|
|
24
|
+
session: z.string(),
|
|
25
|
+
beatmapHash: z.string(),
|
|
26
|
+
contentLength: z.number(),
|
|
27
|
+
contentType: z.string(),
|
|
28
|
+
}),
|
|
29
|
+
output: z.strictObject({
|
|
30
|
+
error: z.string().optional(),
|
|
31
|
+
url: z.string().optional(),
|
|
32
|
+
objectKey: z.string().optional(),
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
37
|
+
return protectedApi({
|
|
38
|
+
request,
|
|
39
|
+
schema: Schema,
|
|
40
|
+
authorization: validUser,
|
|
41
|
+
activity: handler,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function handler({
|
|
46
|
+
session,
|
|
47
|
+
beatmapHash,
|
|
48
|
+
contentLength,
|
|
49
|
+
contentType,
|
|
50
|
+
}: (typeof Schema)["input"]["_type"]): Promise<
|
|
51
|
+
NextResponse<(typeof Schema)["output"]["_type"]>
|
|
52
|
+
> {
|
|
53
|
+
const user = (await supabase.auth.getUser(session)).data.user!;
|
|
54
|
+
|
|
55
|
+
if (contentLength > 50000000) {
|
|
56
|
+
return NextResponse.json({
|
|
57
|
+
error: "Max content length exceeded.",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const key = `beatmap-${beatmapHash}-${user.id}`;
|
|
62
|
+
const command = new PutObjectCommand({
|
|
63
|
+
Bucket: "rhthia-avatars",
|
|
64
|
+
Key: key,
|
|
65
|
+
ContentLength: contentLength,
|
|
66
|
+
ContentType: contentType,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const presigned = await getSignedUrl(s3Client, command, {
|
|
70
|
+
expiresIn: 3600,
|
|
71
|
+
});
|
|
72
|
+
return NextResponse.json({
|
|
73
|
+
url: presigned,
|
|
74
|
+
objectKey: key,
|
|
75
|
+
});
|
|
76
|
+
}
|
package/api/getProfile.ts
CHANGED
|
@@ -21,6 +21,7 @@ export const Schema = {
|
|
|
21
21
|
flag: z.string().nullable(),
|
|
22
22
|
id: z.number(),
|
|
23
23
|
uid: z.string().nullable(),
|
|
24
|
+
ban: z.string().nullable(),
|
|
24
25
|
username: z.string().nullable(),
|
|
25
26
|
verified: z.boolean().nullable(),
|
|
26
27
|
play_count: z.number().nullable(),
|
|
@@ -84,8 +85,9 @@ export async function handler(
|
|
|
84
85
|
.upsert({
|
|
85
86
|
uid: user.id,
|
|
86
87
|
about_me: "",
|
|
87
|
-
avatar_url:
|
|
88
|
-
|
|
88
|
+
avatar_url:
|
|
89
|
+
"https://rhthia-avatars.s3.eu-central-003.backblazeb2.com/user-avatar-1725309193296-72002e6b-321c-4f60-a692-568e0e75147d",
|
|
90
|
+
badges: [],
|
|
89
91
|
username: `${user.user_metadata.full_name.slice(0, 20)}${Math.round(
|
|
90
92
|
Math.random() * 900000 + 100000
|
|
91
93
|
)}`,
|
package/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { handleApi } from "./handleApi"
|
|
2
2
|
|
|
3
|
+
// ./api/editAboutMe.ts API
|
|
4
|
+
import { Schema as EditAboutMe } from "./api/editAboutMe"
|
|
5
|
+
export { Schema as SchemaEditAboutMe } from "./api/editAboutMe"
|
|
6
|
+
export const editAboutMe = handleApi({url:"/api/editAboutMe",...EditAboutMe})
|
|
7
|
+
|
|
3
8
|
// ./api/editProfile.ts API
|
|
4
9
|
import { Schema as EditProfile } from "./api/editProfile"
|
|
5
10
|
export { Schema as SchemaEditProfile } from "./api/editProfile"
|
|
@@ -15,6 +20,11 @@ import { Schema as GetLeaderboard } from "./api/getLeaderboard"
|
|
|
15
20
|
export { Schema as SchemaGetLeaderboard } from "./api/getLeaderboard"
|
|
16
21
|
export const getLeaderboard = handleApi({url:"/api/getLeaderboard",...GetLeaderboard})
|
|
17
22
|
|
|
23
|
+
// ./api/getMapUploadUrl.ts API
|
|
24
|
+
import { Schema as GetMapUploadUrl } from "./api/getMapUploadUrl"
|
|
25
|
+
export { Schema as SchemaGetMapUploadUrl } from "./api/getMapUploadUrl"
|
|
26
|
+
export const getMapUploadUrl = handleApi({url:"/api/getMapUploadUrl",...GetMapUploadUrl})
|
|
27
|
+
|
|
18
28
|
// ./api/getProfile.ts API
|
|
19
29
|
import { Schema as GetProfile } from "./api/getProfile"
|
|
20
30
|
export { Schema as SchemaGetProfile } from "./api/getProfile"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rhythia-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "106.0.0",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"update": "bun ./scripts/update.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"lodash": "^4.17.21",
|
|
32
32
|
"next": "^14.2.5",
|
|
33
33
|
"simple-git": "^3.25.0",
|
|
34
|
-
"supabase": "^1.
|
|
34
|
+
"supabase": "^1.192.5",
|
|
35
35
|
"tsx": "^4.17.0",
|
|
36
36
|
"utf-8-validate": "^6.0.4",
|
|
37
37
|
"zod": "^3.23.8"
|
package/types/database.ts
CHANGED
|
@@ -11,9 +11,11 @@ export type Database = {
|
|
|
11
11
|
Tables: {
|
|
12
12
|
beatmaps: {
|
|
13
13
|
Row: {
|
|
14
|
+
beatmapFile: string | null
|
|
14
15
|
beatmapHash: string
|
|
15
16
|
created_at: string
|
|
16
17
|
difficulty: number | null
|
|
18
|
+
image: string | null
|
|
17
19
|
length: number | null
|
|
18
20
|
noteCount: number | null
|
|
19
21
|
playcount: number | null
|
|
@@ -21,9 +23,11 @@ export type Database = {
|
|
|
21
23
|
title: string | null
|
|
22
24
|
}
|
|
23
25
|
Insert: {
|
|
26
|
+
beatmapFile?: string | null
|
|
24
27
|
beatmapHash: string
|
|
25
28
|
created_at?: string
|
|
26
29
|
difficulty?: number | null
|
|
30
|
+
image?: string | null
|
|
27
31
|
length?: number | null
|
|
28
32
|
noteCount?: number | null
|
|
29
33
|
playcount?: number | null
|
|
@@ -31,9 +35,11 @@ export type Database = {
|
|
|
31
35
|
title?: string | null
|
|
32
36
|
}
|
|
33
37
|
Update: {
|
|
38
|
+
beatmapFile?: string | null
|
|
34
39
|
beatmapHash?: string
|
|
35
40
|
created_at?: string
|
|
36
41
|
difficulty?: number | null
|
|
42
|
+
image?: string | null
|
|
37
43
|
length?: number | null
|
|
38
44
|
noteCount?: number | null
|
|
39
45
|
playcount?: number | null
|
|
@@ -47,6 +53,8 @@ export type Database = {
|
|
|
47
53
|
about_me: string | null
|
|
48
54
|
avatar_url: string | null
|
|
49
55
|
badges: Json | null
|
|
56
|
+
ban: Database["public"]["Enums"]["banTypes"] | null
|
|
57
|
+
bannedAt: number | null
|
|
50
58
|
computedUsername: string | null
|
|
51
59
|
created_at: number | null
|
|
52
60
|
flag: string | null
|
|
@@ -63,6 +71,8 @@ export type Database = {
|
|
|
63
71
|
about_me?: string | null
|
|
64
72
|
avatar_url?: string | null
|
|
65
73
|
badges?: Json | null
|
|
74
|
+
ban?: Database["public"]["Enums"]["banTypes"] | null
|
|
75
|
+
bannedAt?: number | null
|
|
66
76
|
computedUsername?: string | null
|
|
67
77
|
created_at?: number | null
|
|
68
78
|
flag?: string | null
|
|
@@ -79,6 +89,8 @@ export type Database = {
|
|
|
79
89
|
about_me?: string | null
|
|
80
90
|
avatar_url?: string | null
|
|
81
91
|
badges?: Json | null
|
|
92
|
+
ban?: Database["public"]["Enums"]["banTypes"] | null
|
|
93
|
+
bannedAt?: number | null
|
|
82
94
|
computedUsername?: string | null
|
|
83
95
|
created_at?: number | null
|
|
84
96
|
flag?: string | null
|
|
@@ -160,7 +172,7 @@ export type Database = {
|
|
|
160
172
|
[_ in never]: never
|
|
161
173
|
}
|
|
162
174
|
Enums: {
|
|
163
|
-
|
|
175
|
+
banTypes: "cool" | "silenced" | "restricted" | "excluded"
|
|
164
176
|
}
|
|
165
177
|
CompositeTypes: {
|
|
166
178
|
[_ in never]: never
|