mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	feat(edit-docs): clean up ZIP file
This commit is contained in:
		| @@ -17,29 +17,40 @@ async function exportData() { | |||||||
|     const zipFilePath = "output.zip"; |     const zipFilePath = "output.zip"; | ||||||
|     const destRootPath = path.join("src", "public", "app", "doc_notes", "en", "User Guide"); |     const destRootPath = path.join("src", "public", "app", "doc_notes", "en", "User Guide"); | ||||||
|  |  | ||||||
|     await fsExtra.remove(destRootPath); |     const deferred = (await import("./src/services/utils.js")).deferred; | ||||||
|     await fsExtra.mkdir(destRootPath); |  | ||||||
|  |  | ||||||
|     // First export as zip. |     try { | ||||||
|     const { exportToZipFile } = (await import("./src/services/export/zip.js")).default; |         await fsExtra.remove(destRootPath); | ||||||
|     await exportToZipFile(NOTE_ID_USER_GUIDE, "html", zipFilePath); |         await fsExtra.mkdir(destRootPath); | ||||||
|  |  | ||||||
|     setTimeout(async () => { |         // First export as zip. | ||||||
|         // Then extract the zip. |         const { exportToZipFile } = (await import("./src/services/export/zip.js")).default; | ||||||
|         const { readZipFile, readContent } = (await import("./src/services/import/zip.js")); |         await exportToZipFile(NOTE_ID_USER_GUIDE, "html", zipFilePath); | ||||||
|         await readZipFile(await fs.readFile(zipFilePath), async (zip, entry) => { |  | ||||||
|             // We ignore directories since they can appear out of order anyway. |  | ||||||
|             if (!entry.fileName.endsWith("/")) { |  | ||||||
|                 const destPath = path.join(destRootPath, entry.fileName); |  | ||||||
|                 const fileContent = await readContent(zip, entry); |  | ||||||
|  |  | ||||||
|                 await fsExtra.mkdirs(path.dirname(destPath)); |         const promise = deferred<void>() | ||||||
|                 await fs.writeFile(destPath, fileContent); |         setTimeout(async () => { | ||||||
|             } |             // Then extract the zip. | ||||||
|  |             const { readZipFile, readContent } = (await import("./src/services/import/zip.js")); | ||||||
|  |             await readZipFile(await fs.readFile(zipFilePath), async (zip, entry) => { | ||||||
|  |                 // We ignore directories since they can appear out of order anyway. | ||||||
|  |                 if (!entry.fileName.endsWith("/")) { | ||||||
|  |                     const destPath = path.join(destRootPath, entry.fileName); | ||||||
|  |                     const fileContent = await readContent(zip, entry); | ||||||
|  |  | ||||||
|             zip.readEntry(); |                     await fsExtra.mkdirs(path.dirname(destPath)); | ||||||
|         }); |                     await fs.writeFile(destPath, fileContent); | ||||||
|     }, 1000); |                 } | ||||||
|  |  | ||||||
|  |                 zip.readEntry(); | ||||||
|  |             }); | ||||||
|  |             promise.resolve(); | ||||||
|  |         }, 1000); | ||||||
|  |         await promise; | ||||||
|  |     } finally { | ||||||
|  |         if (await fsExtra.exists(zipFilePath)) { | ||||||
|  |             await fsExtra.rm(zipFilePath); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| await main(); | await main(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user