Permalink
Cannot retrieve contributors at this time
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?
car-crushers-portal/functions/api/appeals/[id]/ban.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
40 lines (35 sloc)
1.04 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { jsonError } from "../../../common.js"; | |
export async function onRequestPost(context: RequestContext) { | |
const { current_user: currentUser } = context.data; | |
if (context.data.targetId.search(/^\d{16,19}$/) === -1) | |
return jsonError("Invalid target id", 400); | |
await context.env.D1.prepare( | |
"INSERT INTO appeal_bans (created_at, created_by, user) VALUES (?, ?, ?);", | |
) | |
.bind(Date.now(), context.data.current_user.id, context.data.targetId) | |
.run(); | |
await fetch(context.env.APPEALS_WEBHOOK, { | |
body: JSON.stringify({ | |
embeds: [ | |
{ | |
title: "User Blocked", | |
color: 3756250, | |
description: `User ${context.data.targetId} was blocked from the appeal form.`, | |
fields: [ | |
{ | |
name: "Moderator", | |
value: `${currentUser.username} (${currentUser.id})`, | |
}, | |
], | |
}, | |
], | |
}), | |
headers: { | |
"content-type": "application/json", | |
}, | |
method: "POST", | |
}); | |
return new Response(null, { | |
status: 204, | |
}); | |
} |