mirror of
https://github.com/zadam/trilium.git
synced 2025-11-09 23:05:51 +01:00
feat(edit-docs): read from input directory instead of the zip
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { extractZip, initializeDatabase, startElectron } from "./utils.js";
|
||||
import { extractZip, importData, initializeDatabase, startElectron } from "./utils.js";
|
||||
import { initializeTranslations } from "@triliumnext/server/src/services/i18n.js";
|
||||
import debounce from "@triliumnext/client/src/services/debounce.js";
|
||||
import fs from "fs/promises";
|
||||
import { join } from "path";
|
||||
import cls from "@triliumnext/server/src/services/cls.js";
|
||||
|
||||
// Paths are relative to apps/edit-docs/dist.
|
||||
const DEMO_ZIP_PATH = join(__dirname, "../../server/src/assets/db/demo.zip");
|
||||
const OUTPUT_DIR = join(__dirname, "../demo");
|
||||
const DEMO_ZIP_DIR_PATH = join(__dirname, "../demo");
|
||||
|
||||
async function main() {
|
||||
const initializedPromise = startElectron(() => {
|
||||
@@ -15,10 +16,23 @@ async function main() {
|
||||
});
|
||||
|
||||
await initializeTranslations();
|
||||
await initializeDatabase(false);
|
||||
await initializeDatabase(true);
|
||||
cls.init(async () => {
|
||||
await importData(DEMO_ZIP_DIR_PATH);
|
||||
setOptions();
|
||||
initializedPromise.resolve();
|
||||
});
|
||||
|
||||
initializedPromise.resolve();
|
||||
}
|
||||
|
||||
async function setOptions() {
|
||||
const optionsService = (await import("@triliumnext/server/src/services/options.js")).default;
|
||||
optionsService.setOption("eraseUnusedAttachmentsAfterSeconds", 10);
|
||||
optionsService.setOption("eraseUnusedAttachmentsAfterTimeScale", 60);
|
||||
optionsService.setOption("compressImages", "false");
|
||||
}
|
||||
|
||||
async function registerHandlers() {
|
||||
const events = (await import("@triliumnext/server/src/services/events.js")).default;
|
||||
const eraseService = (await import("@triliumnext/server/src/services/erase.js")).default;
|
||||
@@ -27,8 +41,8 @@ async function registerHandlers() {
|
||||
eraseService.eraseUnusedAttachmentsNow();
|
||||
await exportData();
|
||||
|
||||
await fs.rmdir(OUTPUT_DIR, { recursive: true }).catch(() => {});
|
||||
await extractZip(DEMO_ZIP_PATH, OUTPUT_DIR);
|
||||
await fs.rmdir(DEMO_ZIP_DIR_PATH, { recursive: true }).catch(() => {});
|
||||
await extractZip(DEMO_ZIP_PATH, DEMO_ZIP_DIR_PATH);
|
||||
}, 10_000);
|
||||
events.subscribe(events.ENTITY_CHANGED, async (e) => {
|
||||
if (e.entityName === "options") {
|
||||
|
||||
Reference in New Issue
Block a user