Make data transfer creation endpoint actually work
This commit is contained in:
@ -1,12 +1,12 @@
|
|||||||
import { jsonError } from "../../common.js";
|
import { jsonError } from "../../common.js";
|
||||||
|
|
||||||
export async function onRequestPost(context: RequestContext) {
|
export async function onRequestPost(context: RequestContext) {
|
||||||
const { cookie, has_access } = context.data.body;
|
const { cookie, is_banned } = context.data.body;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof has_access !== "boolean" ||
|
typeof is_banned !== "boolean" ||
|
||||||
(!has_access && typeof cookie !== "string") ||
|
(is_banned && typeof cookie !== "string") ||
|
||||||
(!has_access &&
|
(is_banned &&
|
||||||
!cookie.match(
|
!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]+/,
|
/_\|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]+/,
|
||||||
))
|
))
|
||||||
@ -18,7 +18,7 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
Date.now().toString() +
|
Date.now().toString() +
|
||||||
crypto.randomUUID().replaceAll("-", "");
|
crypto.randomUUID().replaceAll("-", "");
|
||||||
|
|
||||||
if (has_access) {
|
if (!is_banned) {
|
||||||
await context.env.DATA.put(`datatransfer_${id}`, "{}", {
|
await context.env.DATA.put(`datatransfer_${id}`, "{}", {
|
||||||
expirationTtl: 3600,
|
expirationTtl: 3600,
|
||||||
});
|
});
|
||||||
@ -54,30 +54,9 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
|
|
||||||
const authedUser: { id: number; name: string } = await authedUserReq.json();
|
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(
|
await context.env.DATA.put(
|
||||||
`datatransfer_${id}`,
|
`datatransfer_${id}`,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
cardId,
|
|
||||||
oldUser: authedUser,
|
oldUser: authedUser,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
@ -87,7 +66,7 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
|
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
headers: {
|
headers: {
|
||||||
location: `/data-transfer/${id}`,
|
location: "/data-transfer/destination-account",
|
||||||
},
|
},
|
||||||
status: 201,
|
status: 201,
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user