diff --git a/src/NotionExporter.ts b/src/NotionExporter.ts index 718bb3c..e403d13 100644 --- a/src/NotionExporter.ts +++ b/src/NotionExporter.ts @@ -96,11 +96,25 @@ export class NotionExporter { * * @returns The ZIP as an 'AdmZip' object */ - getZip = async (url: string): Promise => { + private downloadZip = async (url: string): Promise => { const res = await this.client.get(url, { responseType: "arraybuffer" }) return new AdmZip(res.data) } + getZip = (idOrUrl: string): Promise => + this.getZipUrl(idOrUrl).then(this.downloadZip) + + /** + * Downloads and extracts all files in the exported zip to the given folder. + * + * @param idOrUrl BlockId or URL of the page/block/DB to export + * @param path Folder path where the files are unzipped + */ + getMdFiles = async (idOrUrl: string, path: string): Promise => { + const zip = await this.getZip(idOrUrl) + zip.extractAllTo(path) + } + /** * Exports the given block as ZIP and downloads it. Returns the matched file * in the ZIP as a string. @@ -113,7 +127,7 @@ export class NotionExporter { idOrUrl: string, predicate: (entry: AdmZip.IZipEntry) => boolean ): Promise { - const zip = await this.getZipUrl(idOrUrl).then(this.getZip) + const zip = await this.getZip(idOrUrl) const entry = zip.getEntries().find(predicate) return ( entry?.getData().toString().trim() ||