New page
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import { jsonError } from "../../common.js";
|
||||
|
||||
export async function onRequestPost(context: RequestContext) {
|
||||
const { user } = context.data.body;
|
||||
const { user, name } = context.data.body;
|
||||
|
||||
if (!user) return jsonError("No user provided", 400);
|
||||
|
||||
if (typeof name !== "string" || name.length > 32)
|
||||
return jsonError("Invalid name", 400);
|
||||
|
||||
const existingUser = await context.env.DATA.get(`gamemod_${user}`);
|
||||
|
||||
if (existingUser) return jsonError("Cannot add an existing user", 400);
|
||||
@@ -21,9 +24,10 @@ export async function onRequestPost(context: RequestContext) {
|
||||
if (!user.match(/^\d{17,19}$/)) return jsonError("Invalid User ID", 400);
|
||||
|
||||
const data = {
|
||||
time: Date.now(),
|
||||
user: context.data.current_user.id,
|
||||
name: context.data.current_user.username,
|
||||
created_at: Date.now(),
|
||||
created_by: context.data.current_user.id,
|
||||
id: user,
|
||||
name,
|
||||
};
|
||||
|
||||
await context.env.DATA.put(`gamemod_${user}`, JSON.stringify(data), {
|
||||
|
||||
Reference in New Issue
Block a user