mirror of
https://github.com/zadam/trilium.git
synced 2025-10-29 17:26:38 +01:00
feat(edit-demo): unzip demo for easy diffing
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import cls from "./src/services/cls.js";
|
||||
import fs from "fs/promises";
|
||||
import fsExtra from "fs-extra";
|
||||
import path from "path";
|
||||
|
||||
export async function initializeDatabase() {
|
||||
const sqlInit = (await import("./src/services/sql_init.js")).default;
|
||||
@@ -55,3 +58,27 @@ export function importData(input: Buffer, rootId: string) {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
export async function extractZip(zipFilePath: string, outputPath: string) {
|
||||
const deferred = (await import("./src/services/utils.js")).deferred;
|
||||
|
||||
const promise = deferred<void>()
|
||||
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(outputPath, entry.fileName);
|
||||
const fileContent = await readContent(zip, entry);
|
||||
|
||||
await fsExtra.mkdirs(path.dirname(destPath));
|
||||
await fs.writeFile(destPath, fileContent);
|
||||
}
|
||||
|
||||
zip.readEntry();
|
||||
});
|
||||
promise.resolve();
|
||||
}, 1000);
|
||||
await promise;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user