trilium/src/routes/index.js

45 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-10-22 09:10:33 +08:00
"use strict";
const sourceIdService = require('../services/source_id');
const sql = require('../services/sql');
const attributeService = require('../services/attributes');
2018-04-03 09:34:28 +08:00
const config = require('../services/config');
const optionService = require('../services/options');
const log = require('../services/log');
async function index(req, res) {
2018-09-06 17:54:04 +08:00
const options = await optionService.getOptionsMap();
2018-12-29 06:47:06 +08:00
const view = req.cookies['trilium-device'] === 'mobile' ? 'mobile' : 'desktop';
const csrfToken = req.csrfToken();
log.info(`Generated CSRF token ${csrfToken} with secret ${res.getHeader('set-cookie')}`);
2018-12-29 06:47:06 +08:00
res.render(view, {
csrfToken: csrfToken,
2018-09-06 17:54:04 +08:00
theme: options.theme,
leftPaneMinWidth: parseInt(options.leftPaneMinWidth),
leftPaneWidthPercent: parseInt(options.leftPaneWidthPercent),
rightPaneWidthPercent: 100 - parseInt(options.leftPaneWidthPercent),
2019-08-20 05:02:19 +08:00
sidebarMinWidth: parseInt(options.sidebarMinWidth),
sidebarWidthPercent: parseInt(options.sidebarWidthPercent),
2019-08-29 03:15:16 +08:00
contentWidthPercent: 100 - parseInt(options.sidebarWidthPercent),
2019-01-14 04:27:32 +08:00
mainFontSize: parseInt(options.mainFontSize),
treeFontSize: parseInt(options.treeFontSize),
detailFontSize: parseInt(options.detailFontSize),
sourceId: await sourceIdService.generateSourceId(),
maxSyncIdAtLoad: await sql.getValue("SELECT MAX(id) FROM sync"),
2018-04-03 09:34:28 +08:00
instanceName: config.General ? config.General.instanceName : null,
appCssNoteIds: await getAppCssNoteIds()
});
}
async function getAppCssNoteIds() {
return (await attributeService.getNotesWithLabels(['appCss', 'appTheme']))
.map(note => note.noteId);
}
module.exports = {
index
};