mirror of
https://github.com/zadam/trilium.git
synced 2025-11-18 03:00:41 +01:00
db upgrades are now handled transparently in the background without bothering the user, closes #119
This commit is contained in:
@@ -12,18 +12,6 @@ async function checkAuth(req, res, next) {
|
||||
else if (!req.session.loggedIn && !utils.isElectron()) {
|
||||
res.redirect("login");
|
||||
}
|
||||
else if (!await sqlInit.isDbUpToDate()) {
|
||||
res.redirect("migration");
|
||||
}
|
||||
else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
async function checkAuthForMigrationPage(req, res, next) {
|
||||
if (!req.session.loggedIn && !utils.isElectron()) {
|
||||
res.redirect("login");
|
||||
}
|
||||
else {
|
||||
next();
|
||||
}
|
||||
@@ -35,27 +23,12 @@ async function checkApiAuthOrElectron(req, res, next) {
|
||||
if (!req.session.loggedIn && !utils.isElectron()) {
|
||||
res.status(401).send("Not authorized");
|
||||
}
|
||||
else if (await sqlInit.isDbUpToDate()) {
|
||||
next();
|
||||
}
|
||||
else {
|
||||
res.status(409).send("Mismatched app versions"); // need better response than that
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
async function checkApiAuth(req, res, next) {
|
||||
if (!req.session.loggedIn) {
|
||||
res.status(401).send("Not authorized");
|
||||
}
|
||||
else if (await sqlInit.isDbUpToDate()) {
|
||||
next();
|
||||
}
|
||||
else {
|
||||
res.status(409).send("Mismatched app versions"); // need better response than that
|
||||
}
|
||||
}
|
||||
|
||||
async function checkApiAuthForMigrationPage(req, res, next) {
|
||||
if (!req.session.loggedIn) {
|
||||
res.status(401).send("Not authorized");
|
||||
}
|
||||
@@ -79,19 +52,14 @@ async function checkSenderToken(req, res, next) {
|
||||
if (await sql.getValue("SELECT COUNT(*) FROM api_tokens WHERE isDeleted = 0 AND token = ?", [token]) === 0) {
|
||||
res.status(401).send("Not authorized");
|
||||
}
|
||||
else if (await sqlInit.isDbUpToDate()) {
|
||||
next();
|
||||
}
|
||||
else {
|
||||
res.status(409).send("Mismatched app versions"); // need better response than that
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkAuth,
|
||||
checkAuthForMigrationPage,
|
||||
checkApiAuth,
|
||||
checkApiAuthForMigrationPage,
|
||||
checkAppNotInitialized,
|
||||
checkApiAuthOrElectron,
|
||||
checkSenderToken
|
||||
|
||||
@@ -2,7 +2,6 @@ const repository = require('./repository');
|
||||
const utils = require('./utils');
|
||||
const dateUtils = require('./date_utils');
|
||||
const appInfo = require('./app_info');
|
||||
const Option = require('../entities/option');
|
||||
|
||||
async function getOption(name) {
|
||||
const option = await repository.getOption(name);
|
||||
@@ -27,6 +26,9 @@ async function setOption(name, value) {
|
||||
}
|
||||
|
||||
async function createOption(name, value, isSynced) {
|
||||
// to avoid circular dependency, need to find better solution
|
||||
const Option = require('../entities/option');
|
||||
|
||||
await new Option({
|
||||
name: name,
|
||||
value: value,
|
||||
|
||||
@@ -42,7 +42,10 @@ const dbReady = new Promise((resolve, reject) => {
|
||||
}
|
||||
|
||||
if (!await isDbUpToDate()) {
|
||||
return;
|
||||
// avoiding circular dependency
|
||||
const migrationService = require('./migration');
|
||||
|
||||
await migrationService.migrate();
|
||||
}
|
||||
|
||||
resolve(db);
|
||||
|
||||
@@ -22,13 +22,6 @@ let syncServerCertificate = null;
|
||||
async function sync() {
|
||||
try {
|
||||
await syncMutexService.doExclusively(async () => {
|
||||
if (!await sqlInit.isDbUpToDate()) {
|
||||
return {
|
||||
success: false,
|
||||
message: "DB not up to date"
|
||||
};
|
||||
}
|
||||
|
||||
const syncContext = await login();
|
||||
|
||||
await pushSync(syncContext);
|
||||
|
||||
Reference in New Issue
Block a user