From d9bbf58aa6614db9940326807c445d895747b95f Mon Sep 17 00:00:00 2001 From: LooseLi <1329307562@qq.com> Date: Tue, 27 May 2025 10:11:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20TypeScript=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/CustomNotionApi.ts | 60 ++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/lib/notion/CustomNotionApi.ts b/lib/notion/CustomNotionApi.ts index fc5f46c9..2266055e 100644 --- a/lib/notion/CustomNotionApi.ts +++ b/lib/notion/CustomNotionApi.ts @@ -1,16 +1,29 @@ -const axios = require('axios') +import axios from 'axios' + +// 定义内容项的接口 +interface ContentItem { + type: string + content: string +} + +// 定义Notion块的接口 +interface NotionBlock { + object: string + type: string + [key: string]: unknown +} // 发送 Notion API 请求 async function postNotion( - properties: any, + properties: Record, databaseId: string, - listContentMain: any[], + listContentMain: ContentItem[], token: string -) { +): Promise<{ status: number; data: Record }> { const url = 'https://api.notion.com/v1/pages' const children = listContentMain - .map(contentMain => { + .map((contentMain: ContentItem): NotionBlock | null => { if (contentMain.type === 'paragraph') { return { object: 'block', @@ -51,14 +64,21 @@ async function postNotion( try { const response = await axios.post(url, payload, { headers }) return response - } catch (error: any) { + } catch (error) { console.error('写入Notion异常', error) - throw new Error(`Error posting to Notion: ${error.message}`) + const errorMessage = error instanceof Error ? error.message : String(error) + throw new Error(`Error posting to Notion: ${errorMessage}`) } } +// 定义响应结果的接口 +interface NotionResponse { + status: number + data: Record +} + // 处理响应结果 -function responseResult(response: { status: number; data: any }) { +function responseResult(response: NotionResponse): void { if (response.status === 200) { console.log('成功...') console.log(response.data) @@ -68,15 +88,25 @@ function responseResult(response: { status: number; data: any }) { } } +// 定义用户属性的接口 +interface UserProperties { + id: string + avatar: string + name: string + mail: string + lastLoginTime: string + token: string +} + // 准备属性字段 function notionProperty( - id: any, - avatar: any, - name: any, - mail: any, - lastLoginTime: any, - token: any -) { + id: string, + avatar: string, + name: string, + mail: string, + lastLoginTime: string, + token: string +): Record { return { id: { rich_text: [