@secret-momo/notion 1.0.3 → 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/client.d.ts.map +1 -1
- package/lib/client.js +3 -0
- package/lib/index.d.ts +5 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -2
- package/lib/upload.d.ts +6 -0
- package/lib/upload.d.ts.map +1 -1
- package/lib/upload.js +6 -3
- package/package.json +1 -1
package/lib/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAoD1C,wBAAgB,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,UAQjD"}
|
package/lib/client.js
CHANGED
|
@@ -8,6 +8,9 @@ function isCertOrTlsError(message) {
|
|
|
8
8
|
async function customFetch(input, init) {
|
|
9
9
|
const mergedInit = {
|
|
10
10
|
...init,
|
|
11
|
+
// https://github.com/oven-sh/bun/blob/7abe6c38/src/bun.js/webcore/fetch.zig
|
|
12
|
+
// @ts-expect-error Bun 专有参数:关闭 fetch 内置的 5 分钟空闲超时
|
|
13
|
+
timeout: false,
|
|
11
14
|
headers: {
|
|
12
15
|
...init?.headers,
|
|
13
16
|
Connection: "close"
|
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;
|
|
@@ -11,4 +11,8 @@ export declare function traverseDataSource(cb: (item: PageObjectResponse) => voi
|
|
|
11
11
|
* @returns 可在浏览器打开的 Notion 页面地址
|
|
12
12
|
*/
|
|
13
13
|
export declare function buildNotionPageWebUrl(pageId: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* 获取数据库页面的 ID
|
|
16
|
+
*/
|
|
17
|
+
export declare function getId(page: PageObjectResponse): number;
|
|
14
18
|
//# sourceMappingURL=index.d.ts.map
|
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;
|
|
@@ -13,5 +13,16 @@ async function traverseDataSource(cb, dataSourceId) {
|
|
|
13
13
|
function buildNotionPageWebUrl(pageId) {
|
|
14
14
|
return `https://www.notion.so/${pageId.replace(/-/g, "")}`;
|
|
15
15
|
}
|
|
16
|
+
function getId(page) {
|
|
17
|
+
const idProperty = page.properties["ID"];
|
|
18
|
+
if (idProperty?.type !== "unique_id") {
|
|
19
|
+
throw new Error("ID \u5C5E\u6027\u4E0D\u662F unique_id \u7C7B\u578B");
|
|
20
|
+
}
|
|
21
|
+
const id = idProperty.unique_id.number;
|
|
22
|
+
if (id === null) {
|
|
23
|
+
throw new Error("ID \u5C5E\u6027\u4E3A\u7A7A");
|
|
24
|
+
}
|
|
25
|
+
return id;
|
|
26
|
+
}
|
|
16
27
|
|
|
17
|
-
export { buildNotionPageWebUrl, n, newNotionClient, traverseDataSource };
|
|
28
|
+
export { buildNotionPageWebUrl, getId, n, newNotionClient, traverseDataSource };
|
package/lib/upload.d.ts
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
* @param contentType - 可选;默认按扩展名推断,未知则为 application/octet-stream
|
|
6
6
|
*/
|
|
7
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>;
|
|
8
14
|
/**
|
|
9
15
|
* 上传本地图片并在页面正文插入「图片」块(`image`)。
|
|
10
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":"AA+IA;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBAuBnF;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,
|
|
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 { uploadLocalFileToPageBody, uploadLocalImageToPageBody, uploadLocalVideoToPageBody };
|
|
169
|
+
export { uploadLocalFileToPageBody, uploadLocalImageToNotion, uploadLocalImageToPageBody, uploadLocalVideoToPageBody };
|