mirror of
https://github.com/zadam/trilium.git
synced 2024-12-26 17:21:23 +08:00
26 lines
No EOL
689 B
JavaScript
26 lines
No EOL
689 B
JavaScript
"use strict";
|
|
|
|
const fs = require('fs');
|
|
const crypto = require('crypto');
|
|
const dataDir = require('./data_dir');
|
|
|
|
const sessionSecretPath = dataDir.TRILIUM_DATA_DIR + "/session_secret.txt";
|
|
|
|
let sessionSecret;
|
|
|
|
function randomValueHex(len) {
|
|
return crypto.randomBytes(Math.ceil(len / 2))
|
|
.toString('hex') // convert to hexadecimal format
|
|
.slice(0, len).toUpperCase(); // return required number of characters
|
|
}
|
|
|
|
if (!fs.existsSync(sessionSecretPath)) {
|
|
sessionSecret = randomValueHex(64);
|
|
|
|
fs.writeFileSync(sessionSecretPath, sessionSecret, 'ASCII');
|
|
}
|
|
else {
|
|
sessionSecret = fs.readFileSync(sessionSecretPath, 'ASCII');
|
|
}
|
|
|
|
module.exports = sessionSecret; |