-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feat - open seminar information 노션 db 연결 추가 #44
- Loading branch information
Showing
4 changed files
with
63 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Client } from '@notionhq/client'; | ||
import { NotionToMarkdown } from "notion-to-md"; | ||
import { NextRequest } from 'next/server'; | ||
|
||
const notion = new Client({ | ||
auth: process.env.NOTION_SECRET_KEY, | ||
}); | ||
|
||
const n2m = new NotionToMarkdown({ notionClient: notion }); | ||
|
||
async function getPageMarkdown(pageId: string): Promise<any> { | ||
const mdblocks = await n2m.pageToMarkdown(pageId); | ||
const mdString = n2m.toMarkdownString(mdblocks); | ||
return mdString; | ||
} | ||
|
||
|
||
// Next.js의 API 라우트 핸들러 | ||
export async function GET(req: NextRequest) { | ||
const url = new URL(req.url); | ||
const pageId = url.searchParams.get('pageId'); | ||
|
||
if (!pageId) { | ||
return new Response(JSON.stringify({ message: 'pageId is required' }), { | ||
status: 400, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} | ||
|
||
try { | ||
const pageContent = await getPageMarkdown(pageId); | ||
return new Response(JSON.stringify({ data: pageContent, message: 'Success' }), { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} catch (error) { | ||
return new Response(JSON.stringify({ message: `Failed: ${error?.toString()}` }), { | ||
status: 500, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters