Notes/src/routes/index.js

69 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-10-21 21:10:33 -04:00
"use strict";
2024-02-16 22:44:12 +02:00
const sql = require('../services/sql');
const attributeService = require('../services/attributes.js');
const config = require('../services/config');
const optionService = require('../services/options');
const log = require('../services/log');
const env = require('../services/env');
2024-02-16 21:38:09 +02:00
const utils = require('../services/utils');
2024-02-16 23:09:59 +02:00
const protectedSessionService = require('../services/protected_session');
const packageJson = require('../../package.json');
const assetPath = require('../services/asset_path.js');
const appPath = require('../services/app_path.js');
2020-06-20 12:31:38 +02:00
function index(req, res) {
2023-06-29 22:10:13 +02:00
const options = optionService.getOptionMap();
2018-09-06 11:54:04 +02:00
2023-06-29 23:32:19 +02:00
const view = (!utils.isElectron() && req.cookies['trilium-device'] === 'mobile')
? 'mobile'
: 'desktop';
2020-04-23 23:08:15 +02:00
const csrfToken = req.csrfToken();
log.info(`Generated CSRF token ${csrfToken} with secret ${res.getHeader('set-cookie')}`);
2018-12-28 23:47:06 +01:00
res.render(view, {
csrfToken: csrfToken,
themeCssUrl: getThemeCssUrl(options.theme),
headingStyle: options.headingStyle,
2019-01-13 21:27:32 +01:00
mainFontSize: parseInt(options.mainFontSize),
treeFontSize: parseInt(options.treeFontSize),
detailFontSize: parseInt(options.detailFontSize),
maxEntityChangeIdAtLoad: sql.getValue("SELECT COALESCE(MAX(id), 0) FROM entity_changes"),
2021-03-21 22:43:41 +01:00
maxEntityChangeSyncIdAtLoad: sql.getValue("SELECT COALESCE(MAX(id), 0) FROM entity_changes WHERE isSynced = 1"),
2018-04-02 21:34:28 -04:00
instanceName: config.General ? config.General.instanceName : null,
2020-06-20 12:31:38 +02:00
appCssNoteIds: getAppCssNoteIds(),
2020-04-25 23:52:13 +02:00
isDev: env.isDev(),
2023-04-03 23:47:24 +02:00
isMainWindow: !req.query.extraWindow,
isProtectedSessionAvailable: protectedSessionService.isProtectedSessionAvailable(),
maxContentWidth: parseInt(options.maxContentWidth),
triliumVersion: packageJson.version,
assetPath: assetPath,
appPath: appPath
});
}
function getThemeCssUrl(theme) {
if (theme === 'light') {
return false; // light theme is always loaded as baseline
2023-06-29 23:32:19 +02:00
} else if (theme === 'dark') {
return `${assetPath}/stylesheets/theme-dark.css`;
2023-06-29 23:32:19 +02:00
} else {
const themeNote = attributeService.getNoteWithLabel('appTheme', theme);
if (themeNote) {
return `api/notes/download/${themeNote.noteId}`;
2023-06-29 23:32:19 +02:00
} else {
return false; // baseline light theme
}
}
}
2020-06-20 12:31:38 +02:00
function getAppCssNoteIds() {
return attributeService.getNotesWithLabel('appCss').map(note => note.noteId);
}
module.exports = {
index
};