@secret-momo/notion 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/upload.d.ts +6 -6
- package/lib/upload.d.ts.map +1 -1
- package/lib/upload.js +6 -3
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type NumberPropertyItemObjectResponse, type PageObjectResponse, type RichTextItemResponse } from '@notionhq/client';
|
|
2
2
|
import { newNotionClient } from './client';
|
|
3
|
-
export { uploadLocalFileToPageBody, uploadLocalImageToPageBody, uploadLocalVideoToPageBody, } from './upload';
|
|
3
|
+
export { uploadLocalFileToPageBody, uploadLocalImageToPageBody, uploadLocalVideoToPageBody, uploadLocalImageToNotion, } from './upload';
|
|
4
4
|
export { newNotionClient };
|
|
5
5
|
export type { NumberPropertyItemObjectResponse, PageObjectResponse, RichTextItemResponse };
|
|
6
6
|
export declare function n(num?: number): number | null;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,YAAY,EAAE,gCAAgC,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,CAAC;AAE3F,wBAAgB,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,iBAE7B;AAED,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,EACtC,YAAY,CAAC,EAAE,MAAM,iBAMtB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,CActD"}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@notionhq/client';
|
|
2
2
|
import { newNotionClient } from './client.js';
|
|
3
|
-
export { uploadLocalFileToPageBody, uploadLocalImageToPageBody, uploadLocalVideoToPageBody } from './upload.js';
|
|
3
|
+
export { uploadLocalFileToPageBody, uploadLocalImageToNotion, uploadLocalImageToPageBody, uploadLocalVideoToPageBody } from './upload.js';
|
|
4
4
|
|
|
5
5
|
function n(num) {
|
|
6
6
|
return num ?? null;
|
package/lib/upload.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 创建并完成 Notion File Upload,返回 `file_upload_id`。
|
|
3
|
-
* ≤20 MiB 用单段;更大文件用官方多段流程(每段约 10 MiB,最后一段可更小)。
|
|
4
|
-
* Blob 的 MIME 须与 create 时一致。
|
|
5
|
-
*/
|
|
6
|
-
export declare function completeFileUpload(displayName: string, contentType: string, fileBuffer: Buffer): Promise<string>;
|
|
7
1
|
/**
|
|
8
2
|
* 将本地文件经 Notion File Upload API 上传后,作为「文件」块挂到页面正文中。
|
|
9
3
|
* @param pageId - 页面 ID
|
|
@@ -11,6 +5,12 @@ export declare function completeFileUpload(displayName: string, contentType: str
|
|
|
11
5
|
* @param contentType - 可选;默认按扩展名推断,未知则为 application/octet-stream
|
|
12
6
|
*/
|
|
13
7
|
export declare function uploadLocalFileToPageBody(pageId: string, absolutePath: string): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* 上传本地图片到 Notion(数据库中附件中需要使用到这个函数)
|
|
10
|
+
* @param absolutePath - 本地图片路径
|
|
11
|
+
* @returns - 文件上传 ID
|
|
12
|
+
*/
|
|
13
|
+
export declare function uploadLocalImageToNotion(absolutePath: string): Promise<string>;
|
|
14
14
|
/**
|
|
15
15
|
* 上传本地图片并在页面正文插入「图片」块(`image`)。
|
|
16
16
|
* @param contentType - 可选;默认按扩展名推断,须为 image/*
|
package/lib/upload.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AA+IA;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBAuBnF;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAYpF;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBAYpF;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBAqBpF"}
|
package/lib/upload.js
CHANGED
|
@@ -124,7 +124,7 @@ async function uploadLocalFileToPageBody(pageId, absolutePath) {
|
|
|
124
124
|
}
|
|
125
125
|
]);
|
|
126
126
|
}
|
|
127
|
-
async function
|
|
127
|
+
async function uploadLocalImageToNotion(absolutePath) {
|
|
128
128
|
const displayName = basename(absolutePath);
|
|
129
129
|
await ensureLocalFileReadable(absolutePath);
|
|
130
130
|
const mime = contentTypeFromPath(absolutePath);
|
|
@@ -132,7 +132,10 @@ async function uploadLocalImageToPageBody(pageId, absolutePath) {
|
|
|
132
132
|
throw new Error(`\u4E0D\u662F\u56FE\u7247 MIME\uFF08${mime}\uFF09\uFF0C\u8BF7\u4F20\u56FE\u7247\u8DEF\u5F84\u6216\u663E\u5F0F\u6307\u5B9A contentType`);
|
|
133
133
|
}
|
|
134
134
|
const fileBuffer = await readFile(absolutePath);
|
|
135
|
-
|
|
135
|
+
return completeFileUpload(displayName, mime, fileBuffer);
|
|
136
|
+
}
|
|
137
|
+
async function uploadLocalImageToPageBody(pageId, absolutePath) {
|
|
138
|
+
const fileUploadId = await uploadLocalImageToNotion(absolutePath);
|
|
136
139
|
await appendBlocksToPage(pageId, [
|
|
137
140
|
{
|
|
138
141
|
type: "image",
|
|
@@ -163,4 +166,4 @@ async function uploadLocalVideoToPageBody(pageId, absolutePath) {
|
|
|
163
166
|
]);
|
|
164
167
|
}
|
|
165
168
|
|
|
166
|
-
export {
|
|
169
|
+
export { uploadLocalFileToPageBody, uploadLocalImageToNotion, uploadLocalImageToPageBody, uploadLocalVideoToPageBody };
|