From 70e5756e30acaf579a67348fb08689e181c8d744 Mon Sep 17 00:00:00 2001 From: cp-20 <47262658+mario-hsp@users.noreply.github.com> Date: Sat, 3 Feb 2024 20:05:13 +0900 Subject: [PATCH] =?UTF-8?q?qiita=20api=E3=81=AE=E3=83=AA=E3=82=AF=E3=82=A8?= =?UTF-8?q?=E3=82=B9=E3=83=88=E6=99=82=E3=81=AB`QIITA=5FAPI=5FTOKEN`?= =?UTF-8?q?=E7=92=B0=E5=A2=83=E5=A4=89=E6=95=B0=E3=81=8C=E3=81=82=E3=82=8C?= =?UTF-8?q?=E3=81=B0=E3=81=9D=E3=82=8C=E3=82=92Bearer=E3=83=88=E3=83=BC?= =?UTF-8?q?=E3=82=AF=E3=83=B3=E3=81=AB=E6=8C=87=E5=AE=9A=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/lib/src/crawler/qiita.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/lib/src/crawler/qiita.ts b/packages/lib/src/crawler/qiita.ts index 1e88927..7343786 100644 --- a/packages/lib/src/crawler/qiita.ts +++ b/packages/lib/src/crawler/qiita.ts @@ -6,11 +6,15 @@ const qiitaApiSchema = z.object({ rendered_body: z.string(), }); +const apiToken = process.env.QIITA_API_TOKEN; + export const fetchArticleFromQiita = async (url: string) => { const { pathname } = new URL(url); const key = pathname.split('/').slice(-1)[0]; - const apiResponse = await fetch(`https://qiita.com/api/v2/items/${key}`); + const apiResponse = await fetch(`https://qiita.com/api/v2/items/${key}`, { + headers: { Authorization: apiToken ? `Bearer ${apiToken}` : '' }, + }); const query = qiitaApiSchema.parse(await apiResponse.json()); const { title, rendered_body: body } = query;