@mikemajara/notion-cms
Version:
A TypeScript library for using Notion as a headless CMS
1 lines • 1.38 kB
JavaScript
;async function l(t){let r=await fetch(t);if(!r.ok)throw new Error(`Failed to download file: ${r.statusText}`);let i=await r.arrayBuffer();return Buffer.from(i)}async function m(t){try{return await(await import('fs/promises')).access(t),!0}catch{return false}}async function f(t){let r=await import('fs/promises');try{await r.mkdir(t,{recursive:!0});}catch(i){if(i.code!=="EEXIST")throw i}}async function p(t,r){let i=await import('fs/promises'),a=(await import('path')).dirname(t);await f(a),await i.writeFile(t,r);}async function y(t){try{return (await(await import('fs/promises')).stat(t)).size}catch{return 0}}async function u(t){try{let r=await import('fs/promises'),i=await import('path'),e=0,a=await r.readdir(t,{withFileTypes:!0});for(let s of a){let n=i.join(t,s.name);if(s.isFile()){let o=await r.stat(n);e+=o.size;}else s.isDirectory()&&(e+=await u(n));}return e}catch{return 0}}async function d(t,r){try{let i=await import('fs/promises'),e=await import('path'),a=Date.now(),s=await i.readdir(t,{withFileTypes:!0});for(let n of s)if(n.isFile()){let o=e.join(t,n.name),c=await i.stat(o);a-c.mtime.getTime()>r&&await i.unlink(o);}}catch(i){console.warn(`Failed to cleanup old files in ${t}:`,i);}}exports.calculateDirSize=u;exports.cleanupOldFiles=d;exports.downloadFile=l;exports.ensureDir=f;exports.fileExists=m;exports.getFileSize=y;exports.writeFile=p;