mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
some tweaks mainly for electron support
This commit is contained in:
parent
0481b1b79c
commit
b890c9982b
16
app.js
16
app.js
@ -10,6 +10,7 @@ const os = require('os');
|
|||||||
const options = require('./services/options');
|
const options = require('./services/options');
|
||||||
const log = require('./services/log');
|
const log = require('./services/log');
|
||||||
const utils = require('./services/utils');
|
const utils = require('./services/utils');
|
||||||
|
const sql = require('./services/sql');
|
||||||
|
|
||||||
const dataDir = require('./services/data_dir');
|
const dataDir = require('./services/data_dir');
|
||||||
const sessionSecret = require('./services/session_secret');
|
const sessionSecret = require('./services/session_secret');
|
||||||
@ -17,6 +18,15 @@ const sessionSecret = require('./services/session_secret');
|
|||||||
const db = require('sqlite');
|
const db = require('sqlite');
|
||||||
|
|
||||||
db.open(dataDir.DOCUMENT_PATH, { Promise }).then(async () => {
|
db.open(dataDir.DOCUMENT_PATH, { Promise }).then(async () => {
|
||||||
|
const tableResults = await sql.getResults("SELECT name FROM sqlite_master WHERE type='table' AND name='notes'");
|
||||||
|
|
||||||
|
console.log(tableResults);
|
||||||
|
|
||||||
|
if (tableResults.length !== 1) {
|
||||||
|
console.log("No connection to initialized DB.");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (!await options.getOption('document_id')) {
|
if (!await options.getOption('document_id')) {
|
||||||
await options.setOption('document_id', utils.randomString(32));
|
await options.setOption('document_id', utils.randomString(32));
|
||||||
}
|
}
|
||||||
@ -24,7 +34,11 @@ db.open(dataDir.DOCUMENT_PATH, { Promise }).then(async () => {
|
|||||||
if (!await options.getOption('document_secret')) {
|
if (!await options.getOption('document_secret')) {
|
||||||
await options.setOption('document_secret', utils.randomSecureToken(32));
|
await options.setOption('document_secret', utils.randomSecureToken(32));
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(e => {
|
||||||
|
console.log("Error connecting to DB.", e);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
5
build.sh
Executable file
5
build.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
./node_modules/.bin/electron-packager . --out=dist --platform=linux,win32 --overwrite
|
||||||
|
|
||||||
|
#./node_modules/.bin/electron-installer-debian --src dist/trilium-linux-x64/ --dest dist/installers/ --arch amd64
|
56
package.json
56
package.json
@ -1,20 +1,28 @@
|
|||||||
{
|
{
|
||||||
"name": "trilium",
|
"name": "trilium",
|
||||||
|
"description": "Trilium",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./bin/www",
|
"start": "node ./bin/www",
|
||||||
"test-electron": "xo",
|
"test-electron": "xo",
|
||||||
"start-electron": "electron .",
|
"start-electron": "electron .",
|
||||||
"build-electron": "electron-packager . --out=dist --asar --overwrite --all"
|
"build-electron": "electron-packager . --out=dist --asar --overwrite --all",
|
||||||
|
"start-forge": "electron-forge start",
|
||||||
|
"package-forge": "electron-forge package",
|
||||||
|
"make-forge": "electron-forge make",
|
||||||
|
"publish-forge": "electron-forge publish"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"electron-compile": "^6.4.2",
|
||||||
|
"electron-squirrel-startup": "^1.0.0",
|
||||||
"body-parser": "~1.18.2",
|
"body-parser": "~1.18.2",
|
||||||
"cookie-parser": "~1.4.3",
|
"cookie-parser": "~1.4.3",
|
||||||
"debug": "~3.1.0",
|
"debug": "~3.1.0",
|
||||||
"ejs": "~2.5.7",
|
"ejs": "~2.5.7",
|
||||||
"electron": "^1.7.9",
|
"electron": "^1.8.2-beta.1",
|
||||||
"electron-debug": "^1.0.0",
|
"electron-debug": "^1.0.0",
|
||||||
|
"electron-forge": "^4.1.2",
|
||||||
"electron-rebuild": "^1.6.0",
|
"electron-rebuild": "^1.6.0",
|
||||||
"express": "~4.16.2",
|
"express": "~4.16.2",
|
||||||
"express-session": "^1.15.6",
|
"express-session": "^1.15.6",
|
||||||
@ -34,7 +42,49 @@
|
|||||||
"devtron": "^1.1.0",
|
"devtron": "^1.1.0",
|
||||||
"electron-packager": "^8.0.0",
|
"electron-packager": "^8.0.0",
|
||||||
"electron": "^1.6.6",
|
"electron": "^1.6.6",
|
||||||
"xo": "^0.18.0"
|
"xo": "^0.18.0",
|
||||||
|
"babel-plugin-transform-async-to-generator": "^6.24.1",
|
||||||
|
"babel-preset-env": "^1.6.1",
|
||||||
|
"babel-preset-react": "^6.24.1",
|
||||||
|
"electron-forge": "^4.1.2",
|
||||||
|
"electron-prebuilt-compile": "1.7.9",
|
||||||
|
"eslint": "^3.19.0",
|
||||||
|
"eslint-config-airbnb": "^15.1.0",
|
||||||
|
"eslint-plugin-import": "^2.8.0",
|
||||||
|
"eslint-plugin-jsx-a11y": "^5.1.1",
|
||||||
|
"eslint-plugin-react": "^7.4.0"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"forge": {
|
||||||
|
"make_targets": {
|
||||||
|
"win32": [
|
||||||
|
"squirrel"
|
||||||
|
],
|
||||||
|
"darwin": [
|
||||||
|
"zip"
|
||||||
|
],
|
||||||
|
"linux": [
|
||||||
|
"deb",
|
||||||
|
"rpm"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"electronPackagerConfig": {
|
||||||
|
"packageManager": "npm"
|
||||||
|
},
|
||||||
|
"electronWinstallerConfig": {
|
||||||
|
"name": "trilium"
|
||||||
|
},
|
||||||
|
"electronInstallerDebian": {},
|
||||||
|
"electronInstallerRedhat": {},
|
||||||
|
"github_repository": {
|
||||||
|
"owner": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
"windowsStoreConfig": {
|
||||||
|
"packageName": "",
|
||||||
|
"name": "trilium"
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"xo": {
|
"xo": {
|
||||||
"envs": [
|
"envs": [
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const migration = require('./migration');
|
const migration = require('./migration');
|
||||||
|
const utils = require('./utils');
|
||||||
|
|
||||||
async function checkAuth(req, res, next) {
|
async function checkAuth(req, res, next) {
|
||||||
if (!req.session.loggedIn) {
|
if (!req.session.loggedIn && !utils.isElectron()) {
|
||||||
res.redirect("login");
|
res.redirect("login");
|
||||||
}
|
}
|
||||||
else if (await migration.isDbUpToDate()) {
|
else if (await migration.isDbUpToDate()) {
|
||||||
@ -15,7 +16,7 @@ async function checkAuth(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkAuthWithoutMigration(req, res, next) {
|
async function checkAuthWithoutMigration(req, res, next) {
|
||||||
if (!req.session.loggedIn) {
|
if (!req.session.loggedIn && !utils.isElectron()) {
|
||||||
res.redirect("login");
|
res.redirect("login");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -24,7 +25,7 @@ async function checkAuthWithoutMigration(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkApiAuth(req, res, next) {
|
async function checkApiAuth(req, res, next) {
|
||||||
if (!req.session.loggedIn) {
|
if (!req.session.loggedIn && !utils.isElectron()) {
|
||||||
res.status(401).send("Not authorized");
|
res.status(401).send("Not authorized");
|
||||||
}
|
}
|
||||||
else if (await migration.isDbUpToDate()) {
|
else if (await migration.isDbUpToDate()) {
|
||||||
@ -36,7 +37,7 @@ async function checkApiAuth(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkApiAuthWithoutMigration(req, res, next) {
|
async function checkApiAuthWithoutMigration(req, res, next) {
|
||||||
if (!req.session.loggedIn) {
|
if (!req.session.loggedIn && !utils.isElectron()) {
|
||||||
res.status(401).send("Not authorized");
|
res.status(401).send("Not authorized");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -170,4 +170,4 @@ module.exports = {
|
|||||||
updateNote,
|
updateNote,
|
||||||
addNoteAudits,
|
addNoteAudits,
|
||||||
deleteNote
|
deleteNote
|
||||||
}
|
};
|
@ -225,7 +225,22 @@ async function sync() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const syncContext = await login();
|
try {
|
||||||
|
const syncContext = await login();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
if (e.message.indexOf('ECONNREFUSED') !== -1) {
|
||||||
|
logSync("No connection to sync server.");
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "No connection to sync server."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await pushSync(syncContext);
|
await pushSync(syncContext);
|
||||||
|
|
||||||
@ -261,8 +276,6 @@ function logSyncError(message, e) {
|
|||||||
completeMessage += ", inner exception: " + e.stack;
|
completeMessage += ", inner exception: " + e.stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info(completeMessage);
|
|
||||||
|
|
||||||
throw new Error(completeMessage);
|
throw new Error(completeMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,10 @@ function browserId(req) {
|
|||||||
return req.get('x-browser-id');
|
return req.get('x-browser-id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isElectron() {
|
||||||
|
return !!process.versions['electron'];
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
randomSecureToken,
|
randomSecureToken,
|
||||||
randomString,
|
randomString,
|
||||||
@ -52,5 +56,6 @@ module.exports = {
|
|||||||
toBase64,
|
toBase64,
|
||||||
fromBase64,
|
fromBase64,
|
||||||
hmac,
|
hmac,
|
||||||
browserId
|
browserId,
|
||||||
|
isElectron
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user