mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-01 20:32:19 +08:00
feat(edit-docs): start importing zip
This commit is contained in:
parent
15936ff8b8
commit
8ac5d01f43
@ -5,7 +5,8 @@ import type NoteMeta from "./src/services/meta/note_meta.js";
|
|||||||
import type { NoteMetaFile } from "./src/services/meta/note_meta.js";
|
import type { NoteMetaFile } from "./src/services/meta/note_meta.js";
|
||||||
import cls from "./src/services/cls.js";
|
import cls from "./src/services/cls.js";
|
||||||
import { initializeTranslations } from "./src/services/i18n.js";
|
import { initializeTranslations } from "./src/services/i18n.js";
|
||||||
import archiver from "archiver";
|
import archiver, { type Archiver } from "archiver";
|
||||||
|
import type { WriteStream } from "fs";
|
||||||
|
|
||||||
const NOTE_ID_USER_GUIDE = "_help_user_guide";
|
const NOTE_ID_USER_GUIDE = "_help_user_guide";
|
||||||
const destRootPath = path.join("src", "public", "app", "doc_notes", "en", "User Guide");
|
const destRootPath = path.join("src", "public", "app", "doc_notes", "en", "User Guide");
|
||||||
@ -16,10 +17,10 @@ async function startElectron() {
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await initializeTranslations();
|
await initializeTranslations();
|
||||||
await createImportZip();
|
const zipBuffer = await createImportZip();
|
||||||
await initializeDatabase();
|
await initializeDatabase();
|
||||||
cls.init(() => {
|
cls.init(() => {
|
||||||
importData();
|
importData(zipBuffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
await startElectron();
|
await startElectron();
|
||||||
@ -36,20 +37,25 @@ async function initializeDatabase() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function importData() {
|
async function importData(input: Buffer) {
|
||||||
const beccaLoader = ((await import("./src/becca/becca_loader.js")).default);
|
const beccaLoader = ((await import("./src/becca/becca_loader.js")).default);
|
||||||
const notes = ((await import("./src/services/notes.js")).default);
|
const notes = ((await import("./src/services/notes.js")).default);
|
||||||
beccaLoader.load();
|
beccaLoader.load();
|
||||||
|
|
||||||
const becca = ((await import("./src/becca/becca.js")).default);
|
const becca = ((await import("./src/becca/becca.js")).default);
|
||||||
|
|
||||||
notes.createNewNoteWithTarget("into", "none_root", {
|
const { note } = notes.createNewNoteWithTarget("into", "none_root", {
|
||||||
parentNoteId: "root",
|
parentNoteId: "root",
|
||||||
noteId: NOTE_ID_USER_GUIDE,
|
noteId: NOTE_ID_USER_GUIDE,
|
||||||
title: "User Guide",
|
title: "User Guide",
|
||||||
content: "The sub-children of this note are automatically synced.",
|
content: "The sub-children of this note are automatically synced.",
|
||||||
type: "text"
|
type: "text"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const TaskContext = (await import("./src/services/task_context.js")).default;
|
||||||
|
const { importZip } = ((await import("./src/services/import/zip.js")).default);
|
||||||
|
const context = new TaskContext("no-report");
|
||||||
|
await importZip(context, input, note);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createImportZip() {
|
async function createImportZip() {
|
||||||
@ -58,6 +64,7 @@ async function createImportZip() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function iterate(currentPath: string) {
|
async function iterate(currentPath: string) {
|
||||||
|
console.log(currentPath);
|
||||||
for (const entry of await fs.readdir(path.join(destRootPath, currentPath), { withFileTypes: true })) {
|
for (const entry of await fs.readdir(path.join(destRootPath, currentPath), { withFileTypes: true })) {
|
||||||
const entryPath = path.join(currentPath, entry.name);
|
const entryPath = path.join(currentPath, entry.name);
|
||||||
|
|
||||||
@ -77,7 +84,17 @@ async function createImportZip() {
|
|||||||
|
|
||||||
const outputStream = fsExtra.createWriteStream("input.zip");
|
const outputStream = fsExtra.createWriteStream("input.zip");
|
||||||
archive.pipe(outputStream);
|
archive.pipe(outputStream);
|
||||||
await archive.finalize();
|
await waitForEnd(archive, outputStream);
|
||||||
|
|
||||||
|
return await fsExtra.readFile("input.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
function waitForEnd(archive: Archiver, stream: WriteStream) {
|
||||||
|
return new Promise<void>(async (res, rej) => {
|
||||||
|
stream.on("finish", () => res());
|
||||||
|
await archive.finalize();
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function exportData() {
|
async function exportData() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user