refactor(core): use different mechanism for shared bootstrap items

This commit is contained in:
Elian Doran
2026-03-24 16:24:59 +02:00
parent 185a88e655
commit ef8db52ebe
4 changed files with 25 additions and 14 deletions

View File

@@ -5,7 +5,6 @@
import { BootstrapDefinition } from '@triliumnext/commons';
import { entity_changes, getContext, getSharedBootstrapItems, getSql, routes, sql_init } from '@triliumnext/core';
import { getIconConfig } from '@triliumnext/core/src/services/bootstrap_utils';
import packageJson from '../../package.json' with { type: 'json' };
import { type BrowserRequest, BrowserRouter } from './browser_router';
@@ -241,20 +240,23 @@ export function registerRoutes(router: BrowserRouter): void {
function bootstrapRoute(): BootstrapDefinition {
const assetPath = ".";
if (!sql_init.isDbInitialized()) {
const isDbInitialized = sql_init.isDbInitialized();
const commonItems = getSharedBootstrapItems(assetPath, isDbInitialized);
if (!isDbInitialized) {
return {
...commonItems,
dbInitialized: false,
baseApiUrl: "../api/",
assetPath,
themeCssUrl: false,
themeUseNextAsBase: "next",
...getIconConfig(assetPath)
themeUseNextAsBase: "next"
};
}
return {
...commonItems,
dbInitialized: true,
...getSharedBootstrapItems(assetPath),
appPath: assetPath,
device: false, // Let the client detect device type.
csrfToken: "dummy-csrf-token",

View File

@@ -1,6 +1,5 @@
import { BootstrapDefinition } from "@triliumnext/commons";
import { getSharedBootstrapItems, getSql, icon_packs as iconPackService, sql_init } from "@triliumnext/core";
import { getIconConfig } from "@triliumnext/core/src/services/bootstrap_utils";
import type { Request, Response } from "express";
import packageJson from "../../package.json" with { type: "json" };
@@ -28,14 +27,16 @@ export function bootstrap(req: Request, res: Response) {
req.session.csrfInitialized = true;
}
if (!sql_init.isDbInitialized()) {
const isDbInitialized = sql_init.isDbInitialized();
const commonItems = getSharedBootstrapItems(assetPath, isDbInitialized);
if (!isDbInitialized) {
return {
...commonItems,
dbInitialized: false,
baseApiUrl: "../api/",
assetPath,
themeCssUrl: false,
themeUseNextAsBase: "next",
...getIconConfig(assetPath)
};
}
@@ -53,7 +54,7 @@ export function bootstrap(req: Request, res: Response) {
const sql = getSql();
res.send({
...getSharedBootstrapItems(assetPath),
...commonItems,
dbInitialized: true,
device: view,
csrfToken,

View File

@@ -315,7 +315,7 @@ export interface DefinitionObject {
/**
* Subset of bootstrap items that are available both in the main client and in the setup page.
*/
interface BootstrapCommonItems {
export interface BootstrapCommonItems {
baseApiUrl: string;
assetPath: string;
themeCssUrl: string | false;

View File

@@ -1,16 +1,25 @@
import { BootstrapDefinition } from "@triliumnext/commons";
import { BootstrapCommonItems, BootstrapDefinition } from "@triliumnext/commons";
import { getSql } from "./sql";
import protected_session from "./protected_session";
import { generateCss, generateIconRegistry, getIconPacks, MIME_TO_EXTENSION_MAPPINGS } from "./icon_packs";
import options from "./options";
import { getCurrentLocale } from "./i18n";
export default function getSharedBootstrapItems(assetPath: string): Pick<BootstrapDefinition, "assetPath" | "headingStyle" | "layoutOrientation" | "maxEntityChangeIdAtLoad" | "maxEntityChangeSyncIdAtLoad" | "isProtectedSessionAvailable" | "iconRegistry" | "iconPackCss" | "currentLocale" | "isRtl"> {
export default function getSharedBootstrapItems(assetPath: string, dbInitialized: boolean) {
const sql = getSql();
const currentLocale = getCurrentLocale();
return {
const commonItems: Partial<BootstrapCommonItems> = {
assetPath,
...getIconConfig(assetPath)
};
if (!dbInitialized) {
return commonItems;
}
return {
...commonItems,
headingStyle: options.getOption("headingStyle") as "plain" | "underline" | "markdown",
layoutOrientation: options.getOption("layoutOrientation") as "vertical" | "horizontal",
maxEntityChangeIdAtLoad: sql.getValue("SELECT COALESCE(MAX(id), 0) FROM entity_changes"),
@@ -18,7 +27,6 @@ export default function getSharedBootstrapItems(assetPath: string): Pick<Bootstr
isProtectedSessionAvailable: protected_session.isProtectedSessionAvailable(),
currentLocale,
isRtl: !!currentLocale.rtl,
...getIconConfig(assetPath)
}
}