route.ts
1import { BskyAgent } from '@atproto/api'
2import { NextResponse } from 'next/server'
3
4export async function GET() {
5 try {
6 const identifier = process.env.BLUESKY_IDENTIFIER
7 const password = process.env.BLUESKY_PASSWORD
8
9 if (!identifier || !password) {
10 return NextResponse.json(
11 { error: 'Bluesky credentials are not configured' },
12 { status: 500 },
13 )
14 }
15
16 const agent = new BskyAgent({ service: 'https://bsky.social' })
17 await agent.login({
18 identifier: identifier,
19 password,
20 })
21
22 const response = await agent.getAuthorFeed({
23 actor: 'choco.rip',
24 limit: 20,
25 })
26
27 const posts = response.data.feed.map((item) => item.post)
28
29 return NextResponse.json(posts, {
30 headers: {
31 'Content-Type': 'application/json',
32 },
33 })
34 } catch (error) {
35 console.error('Error fetching Bluesky posts:', error)
36 return NextResponse.json(
37 { error: 'Failed to fetch posts' },
38 { status: 500 },
39 )
40 }
41}
42
43export const runtime = 'edge'
44