Skip to content
Permalink
05a0d192c3
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
41 lines (32 sloc) 1012 Bytes
function makeResponse(body: string, status: number): Response {
return new Response(body, {
headers: {
"content-type": "application/json",
},
status,
});
}
export async function onRequestPost(context: RequestContext) {
const { user } = context.data.body;
if (!user) return makeResponse('{"error":"No user provided"}', 400);
const existingUser = await context.env.DATA.get(`gamemod_${user}`);
if (existingUser)
return makeResponse('{"error":"Cannot add an existing user"}', 400);
if (
["165594923586945025", "289372404541554689", "396347223736057866"].includes(
user,
)
)
return new Response(null, {
status: 204,
});
if (!user.match(/^\d{17,19}$/))
return makeResponse('{"error":"Invalid User ID"}', 400);
const data = { time: Date.now(), user: context.data.current_user.id };
await context.env.DATA.put(`gamemod_${user}`, JSON.stringify(data), {
metadata: data,
});
return new Response(null, {
status: 204,
});
}