rhythia-api 240.0.0 → 241.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 +85 -85
- package/package.json +1 -1
- package/utils/countryList.ts +141 -0
package/api/editProfile.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NextResponse } from "../utils/response";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import { Database } from "../types/database";
|
|
1
|
+
import { NextResponse } from "../utils/response";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { Database } from "../types/database";
|
|
4
4
|
import { protectedApi, validUser } from "../utils/requestUtils";
|
|
5
5
|
import { supabase } from "../utils/supabase";
|
|
6
6
|
import { getUserBySession } from "../utils/getUserBySession";
|
|
@@ -58,55 +58,55 @@ export const Schema = {
|
|
|
58
58
|
next_username_change_at: z.string().nullable().optional(),
|
|
59
59
|
}),
|
|
60
60
|
};
|
|
61
|
-
|
|
62
|
-
export async function POST(request: Request): Promise<NextResponse> {
|
|
63
|
-
return protectedApi({
|
|
64
|
-
request,
|
|
65
|
-
schema: Schema,
|
|
66
|
-
authorization: validUser,
|
|
67
|
-
activity: handler,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function handler(
|
|
72
|
-
data: (typeof Schema)["input"]["_type"]
|
|
73
|
-
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
74
|
-
if (data.data.username !== undefined) {
|
|
75
|
-
if (data.data.username.length < 3) {
|
|
76
|
-
return NextResponse.json(
|
|
77
|
-
{
|
|
78
|
-
error: "Username must be at least 3 characters long",
|
|
79
|
-
},
|
|
80
|
-
{ status: 404 }
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (data.data.username.length > 20) {
|
|
85
|
-
return NextResponse.json(
|
|
86
|
-
{
|
|
87
|
-
error: "Username too long.",
|
|
88
|
-
},
|
|
89
|
-
{ status: 404 }
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (!/^[a-z0-9]+$/i.test(data.data.username)) {
|
|
94
|
-
return NextResponse.json(
|
|
95
|
-
{
|
|
96
|
-
error: "Username can only contain letters (a-z) and numbers (0-9)",
|
|
97
|
-
},
|
|
98
|
-
{ status: 404 }
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
61
|
+
|
|
62
|
+
export async function POST(request: Request): Promise<NextResponse> {
|
|
63
|
+
return protectedApi({
|
|
64
|
+
request,
|
|
65
|
+
schema: Schema,
|
|
66
|
+
authorization: validUser,
|
|
67
|
+
activity: handler,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function handler(
|
|
72
|
+
data: (typeof Schema)["input"]["_type"]
|
|
73
|
+
): Promise<NextResponse<(typeof Schema)["output"]["_type"]>> {
|
|
74
|
+
if (data.data.username !== undefined) {
|
|
75
|
+
if (data.data.username.length < 3) {
|
|
76
|
+
return NextResponse.json(
|
|
77
|
+
{
|
|
78
|
+
error: "Username must be at least 3 characters long",
|
|
79
|
+
},
|
|
80
|
+
{ status: 404 }
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (data.data.username.length > 20) {
|
|
85
|
+
return NextResponse.json(
|
|
86
|
+
{
|
|
87
|
+
error: "Username too long.",
|
|
88
|
+
},
|
|
89
|
+
{ status: 404 }
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!/^[a-z0-9]+$/i.test(data.data.username)) {
|
|
94
|
+
return NextResponse.json(
|
|
95
|
+
{
|
|
96
|
+
error: "Username can only contain letters (a-z) and numbers (0-9)",
|
|
97
|
+
},
|
|
98
|
+
{ status: 404 }
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
103
|
if (validator.trim(data.data.username || "") !== (data.data.username || "")) {
|
|
104
104
|
return NextResponse.json(
|
|
105
105
|
{
|
|
106
106
|
error: "Username can't start or end with spaces.",
|
|
107
107
|
},
|
|
108
|
-
{ status: 404 }
|
|
109
|
-
);
|
|
108
|
+
{ status: 404 }
|
|
109
|
+
);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
data.data.username = removeZeroWidth(data.data.username || "");
|
|
@@ -127,38 +127,38 @@ export async function handler(
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
const user = (await getUserBySession(data.session)) as User;
|
|
130
|
-
|
|
131
|
-
let userData: Database["public"]["Tables"]["profiles"]["Update"];
|
|
132
|
-
|
|
133
|
-
// Find user's entry
|
|
134
|
-
{
|
|
135
|
-
let { data: queryUserData, error } = await supabase
|
|
136
|
-
.from("profiles")
|
|
137
|
-
.select("*")
|
|
138
|
-
.eq("uid", user.id);
|
|
139
|
-
|
|
140
|
-
if (!queryUserData?.length) {
|
|
141
|
-
return NextResponse.json(
|
|
142
|
-
{
|
|
143
|
-
error: "User cannot be retrieved from session",
|
|
144
|
-
},
|
|
145
|
-
{ status: 404 }
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
userData = queryUserData[0];
|
|
149
|
-
}
|
|
150
|
-
|
|
130
|
+
|
|
131
|
+
let userData: Database["public"]["Tables"]["profiles"]["Update"];
|
|
132
|
+
|
|
133
|
+
// Find user's entry
|
|
134
|
+
{
|
|
135
|
+
let { data: queryUserData, error } = await supabase
|
|
136
|
+
.from("profiles")
|
|
137
|
+
.select("*")
|
|
138
|
+
.eq("uid", user.id);
|
|
139
|
+
|
|
140
|
+
if (!queryUserData?.length) {
|
|
141
|
+
return NextResponse.json(
|
|
142
|
+
{
|
|
143
|
+
error: "User cannot be retrieved from session",
|
|
144
|
+
},
|
|
145
|
+
{ status: 404 }
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
userData = queryUserData[0];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
151
|
if (
|
|
152
152
|
userData.ban == "excluded" ||
|
|
153
153
|
userData.ban == "restricted" ||
|
|
154
154
|
userData.ban == "silenced"
|
|
155
155
|
) {
|
|
156
|
-
return NextResponse.json(
|
|
157
|
-
{
|
|
158
|
-
error:
|
|
159
|
-
"Silenced, restricted or excluded players can't update their profile.",
|
|
160
|
-
},
|
|
161
|
-
{ status: 404 }
|
|
156
|
+
return NextResponse.json(
|
|
157
|
+
{
|
|
158
|
+
error:
|
|
159
|
+
"Silenced, restricted or excluded players can't update their profile.",
|
|
160
|
+
},
|
|
161
|
+
{ status: 404 }
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -236,13 +236,13 @@ export async function handler(
|
|
|
236
236
|
id: userData.id,
|
|
237
237
|
computedUsername: data.data.username?.toLowerCase(),
|
|
238
238
|
...data.data,
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
const upsertResult = await supabase
|
|
242
|
-
.from("profiles")
|
|
243
|
-
.upsert(upsertPayload)
|
|
244
|
-
.select();
|
|
245
|
-
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const upsertResult = await supabase
|
|
242
|
+
.from("profiles")
|
|
243
|
+
.upsert(upsertPayload)
|
|
244
|
+
.select();
|
|
245
|
+
|
|
246
246
|
if (upsertResult.error) {
|
|
247
247
|
if (
|
|
248
248
|
usernameHasChanged &&
|
|
@@ -287,10 +287,10 @@ export async function handler(
|
|
|
287
287
|
return NextResponse.json(
|
|
288
288
|
{
|
|
289
289
|
error: "Can't update, username might be used by someone else!",
|
|
290
|
-
},
|
|
291
|
-
{ status: 404 }
|
|
292
|
-
);
|
|
293
|
-
}
|
|
290
|
+
},
|
|
291
|
+
{ status: 404 }
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
294
|
|
|
295
295
|
return NextResponse.json({});
|
|
296
296
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export const COUNTRY_LIST = [
|
|
2
|
+
"US",
|
|
3
|
+
"AE",
|
|
4
|
+
"AM",
|
|
5
|
+
"AR",
|
|
6
|
+
"AT",
|
|
7
|
+
"AU",
|
|
8
|
+
"AZ",
|
|
9
|
+
"BA",
|
|
10
|
+
"BB",
|
|
11
|
+
"BD",
|
|
12
|
+
"BE",
|
|
13
|
+
"BG",
|
|
14
|
+
"BH",
|
|
15
|
+
"BN",
|
|
16
|
+
"BO",
|
|
17
|
+
"BR",
|
|
18
|
+
"BT",
|
|
19
|
+
"BW",
|
|
20
|
+
"BY",
|
|
21
|
+
"CA",
|
|
22
|
+
"CH",
|
|
23
|
+
"CI",
|
|
24
|
+
"CL",
|
|
25
|
+
"CN",
|
|
26
|
+
"CO",
|
|
27
|
+
"CR",
|
|
28
|
+
"CU",
|
|
29
|
+
"CW",
|
|
30
|
+
"CY",
|
|
31
|
+
"CZ",
|
|
32
|
+
"DE",
|
|
33
|
+
"DJ",
|
|
34
|
+
"DK",
|
|
35
|
+
"DO",
|
|
36
|
+
"DZ",
|
|
37
|
+
"EC",
|
|
38
|
+
"EE",
|
|
39
|
+
"EG",
|
|
40
|
+
"ES",
|
|
41
|
+
"ET",
|
|
42
|
+
"FI",
|
|
43
|
+
"FJ",
|
|
44
|
+
"FO",
|
|
45
|
+
"FR",
|
|
46
|
+
"GA",
|
|
47
|
+
"GB",
|
|
48
|
+
"GE",
|
|
49
|
+
"GH",
|
|
50
|
+
"GR",
|
|
51
|
+
"GT",
|
|
52
|
+
"GU",
|
|
53
|
+
"HK",
|
|
54
|
+
"HN",
|
|
55
|
+
"HR",
|
|
56
|
+
"HU",
|
|
57
|
+
"ID",
|
|
58
|
+
"IE",
|
|
59
|
+
"IL",
|
|
60
|
+
"IM",
|
|
61
|
+
"IN",
|
|
62
|
+
"IQ",
|
|
63
|
+
"IR",
|
|
64
|
+
"IS",
|
|
65
|
+
"IT",
|
|
66
|
+
"JE",
|
|
67
|
+
"JM",
|
|
68
|
+
"JO",
|
|
69
|
+
"JP",
|
|
70
|
+
"KE",
|
|
71
|
+
"KG",
|
|
72
|
+
"KH",
|
|
73
|
+
"KR",
|
|
74
|
+
"KW",
|
|
75
|
+
"LI",
|
|
76
|
+
"LK",
|
|
77
|
+
"LT",
|
|
78
|
+
"LU",
|
|
79
|
+
"LV",
|
|
80
|
+
"MA",
|
|
81
|
+
"MC",
|
|
82
|
+
"MD",
|
|
83
|
+
"MG",
|
|
84
|
+
"MK",
|
|
85
|
+
"MM",
|
|
86
|
+
"MN",
|
|
87
|
+
"MT",
|
|
88
|
+
"MU",
|
|
89
|
+
"MV",
|
|
90
|
+
"MX",
|
|
91
|
+
"MY",
|
|
92
|
+
"NA",
|
|
93
|
+
"NC",
|
|
94
|
+
"NG",
|
|
95
|
+
"NL",
|
|
96
|
+
"NO",
|
|
97
|
+
"NP",
|
|
98
|
+
"NZ",
|
|
99
|
+
"OM",
|
|
100
|
+
"PA",
|
|
101
|
+
"PE",
|
|
102
|
+
"PG",
|
|
103
|
+
"PH",
|
|
104
|
+
"PK",
|
|
105
|
+
"PL",
|
|
106
|
+
"PR",
|
|
107
|
+
"PS",
|
|
108
|
+
"PT",
|
|
109
|
+
"PY",
|
|
110
|
+
"QA",
|
|
111
|
+
"RE",
|
|
112
|
+
"RO",
|
|
113
|
+
"RU",
|
|
114
|
+
"SA",
|
|
115
|
+
"SD",
|
|
116
|
+
"SE",
|
|
117
|
+
"SG",
|
|
118
|
+
"SI",
|
|
119
|
+
"SK",
|
|
120
|
+
"SL",
|
|
121
|
+
"SN",
|
|
122
|
+
"SR",
|
|
123
|
+
"SV",
|
|
124
|
+
"SY",
|
|
125
|
+
"TG",
|
|
126
|
+
"TH",
|
|
127
|
+
"TN",
|
|
128
|
+
"TR",
|
|
129
|
+
"TT",
|
|
130
|
+
"TW",
|
|
131
|
+
"TZ",
|
|
132
|
+
"UA",
|
|
133
|
+
"UY",
|
|
134
|
+
"UZ",
|
|
135
|
+
"KZ",
|
|
136
|
+
"VE",
|
|
137
|
+
"VN",
|
|
138
|
+
"XK",
|
|
139
|
+
"ZA",
|
|
140
|
+
"ZW",
|
|
141
|
+
] as const;
|