fix: stuff

This commit is contained in:
Dhravya Shah 2024-08-03 16:09:39 -07:00
parent 626ca898e4
commit e30e9f4e0b
6 changed files with 7727 additions and 15754 deletions

View file

@ -2,6 +2,7 @@ import { type NextRequest } from "next/server";
import { addFromAPIType } from "@repo/shared-types";
import { ensureAuth } from "../ensureAuth";
import { createMemoryFromAPI } from "./helper";
import { getRawTweet } from "@repo/shared-types/utils";
export const runtime = "edge";
@ -22,14 +23,36 @@ export async function POST(req: NextRequest) {
body = await req.json();
} catch (e) {
const error = (e as Error).message;
return new Response(
JSON.stringify({
message: "A JSON was not sent to the API. " + error,
}),
{
status: 400,
},
);
console.log(error);
const tryJson = getRawTweet(await req.text());
console.log(tryJson);
if (tryJson) {
try {
body = JSON.parse(tryJson);
} catch (e) {
console.log(e);
return new Response(
JSON.stringify({
message: "Raw found but not json?" + error,
}),
{
status: 400,
},
);
}
} else {
return new Response(
JSON.stringify({
message: "Raw not found & not json." + error,
}),
{
status: 400,
},
);
}
}
const validated = addFromAPIType.safeParse(body);