2017-10-21 21:10:33 -04:00
|
|
|
"use strict";
|
|
|
|
|
2024-02-16 22:44:12 +02:00
|
|
|
const sql = require('../services/sql');
|
2023-11-22 19:34:48 +01:00
|
|
|
const attributeService = require('../services/attributes.js');
|
2024-02-17 11:43:30 +02:00
|
|
|
const config = require('../services/config');
|
2024-02-17 11:42:19 +02:00
|
|
|
const optionService = require('../services/options');
|
2024-02-16 21:17:33 +02:00
|
|
|
const log = require('../services/log');
|
2024-02-17 11:54:55 +02:00
|
|
|
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');
|
2021-11-21 17:20:28 +01:00
|
|
|
const packageJson = require('../../package.json');
|
2023-11-22 19:34:48 +01:00
|
|
|
const assetPath = require('../services/asset_path.js');
|
|
|
|
const appPath = require('../services/app_path.js');
|
2017-10-14 23:31:44 -04:00
|
|
|
|
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')
|
2021-10-31 20:25:54 +01:00
|
|
|
? 'mobile'
|
|
|
|
: 'desktop';
|
2020-04-23 23:08:15 +02:00
|
|
|
|
2019-05-29 23:13: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, {
|
2019-05-29 23:13:15 +02:00
|
|
|
csrfToken: csrfToken,
|
2021-09-26 15:24:37 +02:00
|
|
|
themeCssUrl: getThemeCssUrl(options.theme),
|
2021-03-09 22:06:40 +01:00
|
|
|
headingStyle: options.headingStyle,
|
2019-01-13 21:27:32 +01:00
|
|
|
mainFontSize: parseInt(options.mainFontSize),
|
|
|
|
treeFontSize: parseInt(options.treeFontSize),
|
|
|
|
detailFontSize: parseInt(options.detailFontSize),
|
2020-08-02 23:27:48 +02:00
|
|
|
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,
|
2021-10-31 21:55:11 +01:00
|
|
|
isProtectedSessionAvailable: protectedSessionService.isProtectedSessionAvailable(),
|
2021-11-14 21:52:18 +01:00
|
|
|
maxContentWidth: parseInt(options.maxContentWidth),
|
2022-10-26 23:50:54 +02:00
|
|
|
triliumVersion: packageJson.version,
|
2022-12-25 11:58:24 +01:00
|
|
|
assetPath: assetPath,
|
|
|
|
appPath: appPath
|
2017-12-16 20:48:34 -05:00
|
|
|
});
|
2018-03-30 19:31:22 -04:00
|
|
|
}
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2021-09-26 15:24:37 +02:00
|
|
|
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') {
|
2022-10-26 23:50:54 +02:00
|
|
|
return `${assetPath}/stylesheets/theme-dark.css`;
|
2023-06-29 23:32:19 +02:00
|
|
|
} else {
|
2021-09-26 15:24:37 +02:00
|
|
|
const themeNote = attributeService.getNoteWithLabel('appTheme', theme);
|
|
|
|
|
|
|
|
if (themeNote) {
|
|
|
|
return `api/notes/download/${themeNote.noteId}`;
|
2023-06-29 23:32:19 +02:00
|
|
|
} else {
|
2021-09-26 15:24:37 +02:00
|
|
|
return false; // baseline light theme
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
function getAppCssNoteIds() {
|
2021-09-26 15:24:37 +02:00
|
|
|
return attributeService.getNotesWithLabel('appCss').map(note => note.noteId);
|
2018-03-07 23:24:23 -05:00
|
|
|
}
|
|
|
|
|
2018-03-30 19:31:22 -04:00
|
|
|
module.exports = {
|
|
|
|
index
|
|
|
|
};
|