2017-10-21 21:10:33 -04:00
|
|
|
"use strict";
|
|
|
|
|
2018-04-01 21:27:46 -04:00
|
|
|
const sourceIdService = require('../services/source_id');
|
2017-12-19 23:22:21 -05:00
|
|
|
const sql = require('../services/sql');
|
2018-08-07 13:33:10 +02:00
|
|
|
const attributeService = require('../services/attributes');
|
2018-04-02 21:34:28 -04:00
|
|
|
const config = require('../services/config');
|
2018-06-08 23:18:53 -04:00
|
|
|
const optionService = require('../services/options');
|
2019-05-29 23:13:15 +02:00
|
|
|
const log = require('../services/log');
|
2019-12-29 23:46:40 +01:00
|
|
|
const env = require('../services/env');
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2018-03-30 19:31:22 -04:00
|
|
|
async function index(req, res) {
|
2018-09-06 11:54:04 +02:00
|
|
|
const options = await optionService.getOptionsMap();
|
|
|
|
|
2018-12-28 23:47:06 +01:00
|
|
|
const view = req.cookies['trilium-device'] === 'mobile' ? 'mobile' : 'desktop';
|
|
|
|
|
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,
|
2018-09-06 11:54:04 +02:00
|
|
|
theme: options.theme,
|
2019-01-13 21:27:32 +01:00
|
|
|
mainFontSize: parseInt(options.mainFontSize),
|
|
|
|
treeFontSize: parseInt(options.treeFontSize),
|
|
|
|
detailFontSize: parseInt(options.detailFontSize),
|
2018-04-01 21:27:46 -04:00
|
|
|
sourceId: await sourceIdService.generateSourceId(),
|
2018-03-07 23:24:23 -05:00
|
|
|
maxSyncIdAtLoad: await sql.getValue("SELECT MAX(id) FROM sync"),
|
2018-04-02 21:34:28 -04:00
|
|
|
instanceName: config.General ? config.General.instanceName : null,
|
2019-12-29 23:46:40 +01:00
|
|
|
appCssNoteIds: await getAppCssNoteIds(),
|
|
|
|
isDev: env.isDev()
|
2017-12-16 20:48:34 -05:00
|
|
|
});
|
2018-03-30 19:31:22 -04:00
|
|
|
}
|
2017-10-14 23:31:44 -04:00
|
|
|
|
2019-01-27 17:01:37 +01:00
|
|
|
async function getAppCssNoteIds() {
|
|
|
|
return (await attributeService.getNotesWithLabels(['appCss', 'appTheme']))
|
|
|
|
.map(note => note.noteId);
|
2018-03-07 23:24:23 -05:00
|
|
|
}
|
|
|
|
|
2018-03-30 19:31:22 -04:00
|
|
|
module.exports = {
|
|
|
|
index
|
|
|
|
};
|