Skip to content

Commit

Permalink
Edit statuscode on successful post; Add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrezerino committed Apr 28, 2024
1 parent 8399d99 commit 057d1b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions app/api/posts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { NextRequest, NextResponse } from 'next/server';
export const POST = async (req: NextRequest) => {
try {
const ip = req.headers.get('x-real-ip');
if (ip && process.env.BANLIST?.includes(ip)) {
if (ip && process.env.BANLIST?.split('').includes(ip)) {
throw { message: 'Can not post at this time.', status: 403 };
}

Expand Down Expand Up @@ -82,13 +82,15 @@ export const POST = async (req: NextRequest) => {
await upload.done();
}

newPost.imageUrl = image && image.size > 0 ? `${AWS_URL}/img/posts/${filename}` : ''

// Set post's imageUrl as the url of the image we just uploaded, and delete file
newPost.imageUrl = image && image.size > 0 ? `${AWS_URL}/img/posts/${filename}` : '';
delete newPost.image;

// Finally, save post to database
const result = await (await db()).collection('posts').insertOne(newPost);

if (result.acknowledged && result.insertedId !== null) {
return NextResponse.json('ok', { status: 200 });
return NextResponse.json('Created', { status: 201 });
}
} catch (e) {
return NextResponse.json(
Expand Down
2 changes: 1 addition & 1 deletion app/ui/dashboard/post/postForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const PostFormBig = ({ op }: { op: PostType | null }) => {

response && setLoading(false);

if (response.status === 200) {
if (response.status === 201) {
// Clear state on successful post
setContent('');
setImage(null);
Expand Down

0 comments on commit 057d1b8

Please sign in to comment.