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]/_middleware.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35 lines (24 sloc)
962 Bytes
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 { pathname } = new URL(context.request.url); | |
// Fix weirdo routing issue | |
if (pathname.endsWith("/submit") || pathname.endsWith("/toggle")) | |
return await context.next(); | |
const { permissions } = context.data.current_user; | |
if (!(permissions & (1 << 0)) && !(permissions & (1 << 11))) | |
return jsonError("Forbidden", 403); | |
const { body } = context.data; | |
const id = context.params.id as string; | |
context.data.targetId = id; | |
if (!pathname.endsWith("/ban")) { | |
const key = await context.env.DATA.get(`appeal_${id}`); | |
if (!key) return jsonError("No appeal with that ID exists", 404); | |
context.data.appeal = JSON.parse(key); | |
} | |
if ( | |
body.feedback && | |
(typeof body.feedback !== "string" || body.feedback.length > 512) | |
) | |
return jsonError("Invalid feedback", 400); | |
return await context.next(); | |
} |