Skip to content

Commit

Permalink
Added proper createPost
Browse files Browse the repository at this point in the history
  • Loading branch information
cr4yfish committed Jul 13, 2023
1 parent 796bfd2 commit c1940e8
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/api/createPost/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { LemmyHttp, PostId, CommentId } from "lemmy-js-client"

export async function POST(req: Request) {
try {

const body = await req.json();

let name = body.name || undefined;
let community_id = body.community_id || undefined;
let url = body.url || undefined;
let body_content = body.body || undefined;
let honeypot = body.honeypot || undefined;
let nsfw = body.nsfw || undefined;
let language_id = body.language_id || undefined;
let auth = body.auth || undefined;

if(!name || !community_id || !auth) throw new Error("missing parameters");

let client: LemmyHttp = new LemmyHttp(`https://lemmy.world`);

let response = await client.createPost({
name: name,
community_id: community_id,
url: url,
body: body_content,
honeypot: honeypot,
nsfw: nsfw,
language_id: language_id,
auth: auth
})

return new Response(JSON.stringify(response), { status: 200, headers: { 'Content-Type': 'application/json' } })

} catch (e: any) {
console.error("createComment Error:",e);
return new Response(JSON.stringify({ error: e }), { status: 500, headers: { 'Content-Type': 'application/json' } })
}
}

0 comments on commit c1940e8

Please sign in to comment.