Skip to content

Commit

Permalink
Remove unused import and handle missing post URL
Browse files Browse the repository at this point in the history
  • Loading branch information
thebkht committed Nov 27, 2023
1 parent fea4240 commit a93e049
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions app/api/posts/[username]/opengraph-image/route.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @next/next/no-img-element */
import { Icons } from "@/components/icon";
import { ImageResponse } from "next/og";
import { NextRequest, NextResponse } from "next/server";

Expand Down Expand Up @@ -29,20 +28,23 @@ export async function GET(req: NextRequest, { params }: { params: { username: st
regularFont,
boldFont,
]);
try {
const { username } = params
const postUrl = req.nextUrl.searchParams.get("url");
if (!postUrl) {
return NextResponse.json("Missing post url", { status: 400 });
}
const { username } = params;
const postUrl = req.nextUrl.searchParams.get("url");

if (!postUrl) {
return NextResponse.json("Missing post url", { status: 400 });
}

try {
const response = await fetch(`${process.env.DOMAIN}/api/posts/${username}/${postUrl}`);

if (!response.ok) {
return NextResponse.json("Error fetching user data", { status: 500 });

}

const data = await response.json();
const post = data;

return new ImageResponse(
(
post.cover ? (
Expand Down Expand Up @@ -136,7 +138,8 @@ export async function GET(req: NextRequest, { params }: { params: { username: st
},
);
} catch (error) {
console.error(error);
console.error("Error fetching user data", error);
return NextResponse.json("Error occurred", { status: 500 });
}
}

Expand Down

0 comments on commit a93e049

Please sign in to comment.