@secret-momo/notion 2.6.0 → 3.0.0
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.
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export declare function contentTypeFromPath(absolutePath: string): string;
|
|
2
|
+
export declare function ensureLocalFileReadable(absolutePath: string): Promise<void>;
|
|
3
|
+
export interface TemporaryGzipFile {
|
|
4
|
+
filePath: string;
|
|
5
|
+
cleanup: () => Promise<void>;
|
|
6
|
+
}
|
|
2
7
|
/**
|
|
3
8
|
* Notion 的 send 接口经 Cloudflare;原始 HTML(尤其公众号全文)易触发 WAF 403。
|
|
4
|
-
*
|
|
9
|
+
* 流式压缩到临时文件,避免同时在内存中保留原文件和完整 gzip 结果。
|
|
5
10
|
*/
|
|
6
|
-
export declare function
|
|
7
|
-
buffer: Buffer;
|
|
8
|
-
displayName: string;
|
|
9
|
-
mime: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function ensureLocalFileReadable(absolutePath: string): Promise<void>;
|
|
11
|
+
export declare function createTemporaryGzipFile(absolutePath: string): Promise<TemporaryGzipFile>;
|
|
12
12
|
export declare function runWithConcurrency<T>(items: T[], concurrency: number, worker: (item: T) => Promise<void>): Promise<void>;
|
|
13
13
|
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/helpers/upload/helper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/helpers/upload/helper.ts"],"names":[],"mappings":"AASA,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAGhE;AAED,wBAAsB,uBAAuB,CAAC,YAAY,EAAE,MAAM,iBAMjE;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAe9F;AAED,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,KAAK,EAAE,CAAC,EAAE,EACV,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,iBAqCnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{constants as l,createReadStream as h,createWriteStream as w}from"node:fs";import{access as y,mkdtemp as E,rm as u}from"node:fs/promises";import{tmpdir as d}from"node:os";import{extname as F,join as m}from"node:path";import{pipeline as g}from"node:stream/promises";import{createGzip as R}from"node:zlib";import{MIME_BY_EXT as v}from"./config.js";function z(t){const r=F(t).toLowerCase();return v[r]??"application/octet-stream"}async function C(t){try{await y(t,l.R_OK)}catch{throw new Error(`\u627E\u4E0D\u5230\u8981\u4E0A\u4F20\u7684\u6587\u4EF6: ${t}`)}}async function M(t){const r=await E(m(d(),"secret-momo-notion-upload-")),e=m(r,"payload.gz");try{await g(h(t),R(),w(e))}catch(o){throw await u(r,{recursive:!0,force:!0}),o}return{filePath:e,cleanup:()=>u(r,{recursive:!0,force:!0})}}async function P(t,r,e){if(!Number.isInteger(r)||r<1)throw new RangeError("concurrency \u5FC5\u987B\u662F\u5927\u4E8E 0 \u7684\u6574\u6570");let o=0,n=!1,a=!1,c;const s=Math.min(r,t.length);if(await Promise.all(Array.from({length:s},async()=>{for(;!n&&o<t.length;){const f=o++,i=t[f];if(i===void 0)return;try{await e(i)}catch(p){a||(a=!0,c=p),n=!0}}})),a)throw c}export{z as contentTypeFromPath,M as createTemporaryGzipFile,C as ensureLocalFileReadable,P as runWithConcurrency};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/upload/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/upload/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AA8H/C,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAoB5E;AAED,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAW/F;AAED,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAU7E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{open as h}from"node:fs/promises";import{basename as c,extname as _}from"node:path";import{SINGLE_PART_MAX_BYTES as T,MULTIPART_CHUNK_BYTES as p,MULTIPART_UPLOAD_CONCURRENCY as B}from"./config.js";import{ensureLocalFileReadable as f,contentTypeFromPath as d,createTemporaryGzipFile as A,runWithConcurrency as C}from"./helper.js";async function y(e,t,u){const a=Buffer.allocUnsafe(u);let i=0;for(;i<u;){const o=await e.read(a,i,u-i,t+i);if(o.bytesRead===0)throw new Error("\u8BFB\u53D6\u4E0A\u4F20\u6587\u4EF6\u65F6\u63D0\u524D\u5230\u8FBE\u6587\u4EF6\u672B\u5C3E\uFF0C\u6587\u4EF6\u53EF\u80FD\u5DF2\u88AB\u4FEE\u6539");i+=o.bytesRead}return a}async function s({client:e,displayName:t,contentType:u,filePath:a}){const i=await h(a,"r");try{const o=await i.stat();if(!o.isFile())throw new Error(`\u8981\u4E0A\u4F20\u7684\u8DEF\u5F84\u4E0D\u662F\u6587\u4EF6: ${a}`);if(o.size<=T){const r=new Blob([await y(i,0,o.size)],{type:u}),n=await e.fileUploads.create({mode:"single_part",filename:t,content_type:u}),l=await e.fileUploads.send({file_upload_id:n.id,file:{filename:t,data:r}});if(l.status!=="uploaded")throw new Error(`\u6587\u4EF6\u4E0A\u4F20\u672A\u5C31\u7EEA\uFF0C\u72B6\u6001: ${l.status}`);return n.id}const E=Math.ceil(o.size/p),F=await e.fileUploads.create({mode:"multi_part",filename:t,content_type:u,number_of_parts:E});await C(Array.from({length:E},(r,n)=>n+1),B,async r=>{const n=(r-1)*p,l=Math.min(p,o.size-n),m=new Blob([await y(i,n,l)],{type:u});await e.fileUploads.send({file_upload_id:F.id,part_number:String(r),file:{filename:t,data:m}})});const w=await e.fileUploads.complete({file_upload_id:F.id});if(w.status!=="uploaded")throw new Error(`\u591A\u6BB5\u6587\u4EF6\u4E0A\u4F20\u672A\u5B8C\u6210\uFF0C\u72B6\u6001: ${w.status}`);return F.id}finally{await i.close()}}async function D(e,t){const u=c(t);await f(t);const a=d(t);if(_(t).toLowerCase()!==".html")return s({client:e,displayName:u,contentType:a,filePath:t});const i=await A(t);try{return await s({client:e,displayName:u.endsWith(".gz")?u:`${u}.gz`,contentType:"application/gzip",filePath:i.filePath})}finally{await i.cleanup()}}async function N(e,t){await f(t);const u=c(t),a=d(t);if(!a.startsWith("image/"))throw new Error(`\u4E0D\u662F\u56FE\u7247 MIME\uFF08${a}\uFF09\uFF0C\u8BF7\u4F20\u56FE\u7247\u8DEF\u5F84\u6216\u663E\u5F0F\u6307\u5B9A contentType`);return s({client:e,displayName:u,contentType:a,filePath:t})}async function P(e,t){const u=c(t);await f(t);const a=d(t);if(!a.startsWith("video/"))throw new Error(`\u4E0D\u662F\u89C6\u9891 MIME\uFF08${a}\uFF09\uFF0C\u8BF7\u4F20\u89C6\u9891\u8DEF\u5F84\u6216\u663E\u5F0F\u6307\u5B9A contentType`);return s({client:e,displayName:u,contentType:a,filePath:t})}export{D as uploadFileToNotion,N as uploadImageToNotion,P as uploadVideoToNotion};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secret-momo/notion",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": "24.19.0"
|
|
6
6
|
},
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@notionhq/client": "5.26.0",
|
|
31
|
-
"@secret-momo/utils": "1.
|
|
31
|
+
"@secret-momo/utils": "1.5.0",
|
|
32
32
|
"@tryfabric/martian": "1.2.4"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|