Greatly reduce repeated code
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import { jsonError } from "../../common.js";
|
||||
|
||||
export async function onRequestPost(context: RequestContext) {
|
||||
const { cookie, has_access } = context.data.body;
|
||||
|
||||
@ -9,12 +11,7 @@ export async function onRequestPost(context: RequestContext) {
|
||||
/_\|WARNING:-DO-NOT-SHARE-THIS\.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items\.\|_[A-F\d]+/,
|
||||
))
|
||||
)
|
||||
return new Response('{"error":"Invalid request"}', {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
status: 400,
|
||||
});
|
||||
return jsonError("Invalid request", 400);
|
||||
|
||||
const id =
|
||||
(context.request.headers.get("cf-ray")?.split("-")[0] as string) +
|
||||
@ -53,13 +50,7 @@ export async function onRequestPost(context: RequestContext) {
|
||||
},
|
||||
);
|
||||
|
||||
if (!authedUserReq.ok)
|
||||
return new Response('{"error":"Cookie is invalid"}', {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
status: 400,
|
||||
});
|
||||
if (!authedUserReq.ok) return jsonError("Cookie is invalid", 400);
|
||||
|
||||
const authedUser: { id: number; name: string } = await authedUserReq.json();
|
||||
|
||||
@ -79,13 +70,7 @@ export async function onRequestPost(context: RequestContext) {
|
||||
},
|
||||
);
|
||||
|
||||
if (!createCardReq.ok)
|
||||
return new Response('{"error":"Failed to create entry"}', {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
status: 500,
|
||||
});
|
||||
if (!createCardReq.ok) return jsonError("Failed to create entry", 500);
|
||||
|
||||
await context.env.DATA.put(
|
||||
`datatransfer_${id}`,
|
||||
|
Reference in New Issue
Block a user