Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make data transfer creation endpoint actually work
  • Loading branch information
regalijan committed Nov 21, 2023
1 parent f58df23 commit cecb254
Showing 1 changed file with 6 additions and 27 deletions.
33 changes: 6 additions & 27 deletions functions/api/data-transfers/create.ts
@@ -1,12 +1,12 @@
import { jsonError } from "../../common.js";

export async function onRequestPost(context: RequestContext) {
const { cookie, has_access } = context.data.body;
const { cookie, is_banned } = context.data.body;

if (
typeof has_access !== "boolean" ||
(!has_access && typeof cookie !== "string") ||
(!has_access &&
typeof is_banned !== "boolean" ||
(is_banned && typeof cookie !== "string") ||
(is_banned &&
!cookie.match(
/_\|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]+/,
))
Expand All @@ -18,7 +18,7 @@ export async function onRequestPost(context: RequestContext) {
Date.now().toString() +
crypto.randomUUID().replaceAll("-", "");

if (has_access) {
if (!is_banned) {
await context.env.DATA.put(`datatransfer_${id}`, "{}", {
expirationTtl: 3600,
});
Expand Down Expand Up @@ -54,30 +54,9 @@ export async function onRequestPost(context: RequestContext) {

const authedUser: { id: number; name: string } = await authedUserReq.json();

const createCardReq = await fetch(
`https://api.trello.com/1/cards?key=${context.env.TRELLO_API_KEY}&token=${context.env.TRELLO_API_TOKEN}`,
{
body: JSON.stringify({
desc: `Old account: ${authedUser.name} (${authedUser.id})`,
idList: "5fbd440cd30b6377f959e244",
name: `${authedUser.name} | Data Transfer`,
}),
headers: {
accept: "application/json",
"content-type": "application/json",
},
method: "POST",
},
);

if (!createCardReq.ok) return jsonError("Failed to create entry", 500);

const { id: cardId }: { id: string } = await createCardReq.json();

await context.env.DATA.put(
`datatransfer_${id}`,
JSON.stringify({
cardId,
oldUser: authedUser,
}),
{
Expand All @@ -87,7 +66,7 @@ export async function onRequestPost(context: RequestContext) {

return new Response(null, {
headers: {
location: `/data-transfer/${id}`,
location: "/data-transfer/destination-account",
},
status: 201,
});
Expand Down

0 comments on commit cecb254

Please sign in to comment.