mirror of
https://github.com/zadam/trilium.git
synced 2026-05-07 04:26:17 +02:00
feat(standalone/import): import demo DB
This commit is contained in:
@@ -162,6 +162,11 @@ async function initialize(): Promise<void> {
|
||||
platform: new StandalonePlatformProvider(queryString),
|
||||
translations: translationProvider,
|
||||
schema: schemaModule.default,
|
||||
getDemoArchive: async () => {
|
||||
const response = await fetch("/server-assets/db/demo.zip");
|
||||
if (!response.ok) return null;
|
||||
return new Uint8Array(await response.arrayBuffer());
|
||||
},
|
||||
dbConfig: {
|
||||
provider: sqlProvider!,
|
||||
isReadOnly: false,
|
||||
|
||||
@@ -141,6 +141,7 @@ async function main() {
|
||||
schema: fs.readFileSync(require.resolve("@triliumnext/core/src/assets/schema.sql"), "utf-8"),
|
||||
platform: new DesktopPlatformProvider(),
|
||||
translations: (await import("@triliumnext/server/src/services/i18n.js")).initializeTranslations,
|
||||
getDemoArchive: async () => fs.readFileSync(require.resolve("@triliumnext/server/src/assets/db/demo.zip")),
|
||||
extraAppInfo: {
|
||||
nodeVersion: process.version,
|
||||
dataDirectory: path.resolve(dataDirs.TRILIUM_DATA_DIR)
|
||||
|
||||
@@ -59,6 +59,7 @@ async function startApplication() {
|
||||
schema: fs.readFileSync(require.resolve("@triliumnext/core/src/assets/schema.sql"), "utf-8"),
|
||||
platform: new ServerPlatformProvider(),
|
||||
translations: (await import("./services/i18n.js")).initializeTranslations,
|
||||
getDemoArchive: async () => fs.readFileSync(require.resolve("@triliumnext/server/src/assets/db/demo.zip")),
|
||||
extraAppInfo: {
|
||||
nodeVersion: process.version,
|
||||
dataDirectory: path.resolve(dataDirs.TRILIUM_DATA_DIR)
|
||||
|
||||
@@ -6,7 +6,7 @@ import { SqlService, SqlServiceParams } from "./services/sql/sql";
|
||||
import { initMessaging, MessagingProvider } from "./services/messaging/index";
|
||||
import { initRequest, RequestProvider } from "./services/request";
|
||||
import { initTranslations, TranslationProvider } from "./services/i18n";
|
||||
import { initSchema } from "./services/sql_init";
|
||||
import { initSchema, initDemoArchive } from "./services/sql_init";
|
||||
import appInfo from "./services/app_info";
|
||||
import { type PlatformProvider, initPlatform } from "./services/platform";
|
||||
import { type ZipProvider, initZipProvider } from "./services/import/zip_provider";
|
||||
@@ -103,7 +103,7 @@ export * as routeHelpers from "./routes/helpers";
|
||||
export * as becca_easy_mocking from "./test/becca_easy_mocking";
|
||||
export * as becca_mocking from "./test/becca_mocking";
|
||||
|
||||
export async function initializeCore({ dbConfig, executionContext, crypto, zip, translations, messaging, request, schema, extraAppInfo, platform }: {
|
||||
export async function initializeCore({ dbConfig, executionContext, crypto, zip, translations, messaging, request, schema, extraAppInfo, platform, getDemoArchive }: {
|
||||
dbConfig: SqlServiceParams,
|
||||
executionContext: ExecutionContext,
|
||||
crypto: CryptoProvider,
|
||||
@@ -113,6 +113,7 @@ export async function initializeCore({ dbConfig, executionContext, crypto, zip,
|
||||
schema: string,
|
||||
messaging?: MessagingProvider,
|
||||
request?: RequestProvider,
|
||||
getDemoArchive?: () => Promise<Uint8Array | null>,
|
||||
extraAppInfo?: {
|
||||
nodeVersion: string;
|
||||
dataDirectory: string;
|
||||
@@ -126,6 +127,9 @@ export async function initializeCore({ dbConfig, executionContext, crypto, zip,
|
||||
initContext(executionContext);
|
||||
initSql(new SqlService(dbConfig, getLog()));
|
||||
initSchema(schema);
|
||||
if (getDemoArchive) {
|
||||
initDemoArchive(getDemoArchive);
|
||||
}
|
||||
Object.assign(appInfo, extraAppInfo);
|
||||
if (messaging) {
|
||||
initMessaging(messaging);
|
||||
|
||||
@@ -15,11 +15,16 @@ import migrationService from "./migration";
|
||||
export const dbReady = deferred<void>();
|
||||
|
||||
let schema: string;
|
||||
let getDemoArchive: (() => Promise<Uint8Array | null>) | null = null;
|
||||
|
||||
export function initSchema(schemaStr: string) {
|
||||
schema = schemaStr;
|
||||
}
|
||||
|
||||
export function initDemoArchive(fn: () => Promise<Uint8Array | null>) {
|
||||
getDemoArchive = fn;
|
||||
}
|
||||
|
||||
function schemaExists() {
|
||||
return !!getSql().getValue(/*sql*/`SELECT name FROM sqlite_master
|
||||
WHERE type = 'table' AND name = 'options'`);
|
||||
@@ -177,13 +182,15 @@ async function createInitialDatabase(skipDemoDb?: boolean) {
|
||||
});
|
||||
|
||||
// Import demo content.
|
||||
log.info("Importing demo content...");
|
||||
|
||||
const dummyTaskContext = new TaskContext("no-progress-reporting", "importNotes", null);
|
||||
|
||||
// if (demoFile) {
|
||||
// await zipImportService.importZip(dummyTaskContext, demoFile, rootNote);
|
||||
// }
|
||||
if (getDemoArchive) {
|
||||
log.info("Importing demo content...");
|
||||
const demoFile = await getDemoArchive();
|
||||
if (demoFile) {
|
||||
const { default: zipImportService } = await import("./import/zip.js");
|
||||
const dummyTaskContext = new TaskContext("no-progress-reporting", "importNotes", null);
|
||||
await zipImportService.importZip(dummyTaskContext, demoFile, rootNote);
|
||||
}
|
||||
}
|
||||
|
||||
// Post-demo.
|
||||
sql.transactional(() => {
|
||||
|
||||
Reference in New Issue
Block a user