mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
converted settings, note revisions, password change and recent changes routes
This commit is contained in:
parent
8550ed72f2
commit
9edee9340b
@ -25,7 +25,7 @@ async function showNoteRevisionsDialog(noteId, noteRevisionId) {
|
||||
$list.empty();
|
||||
$content.empty();
|
||||
|
||||
revisionItems = await server.get('notes-revisions/' + noteId);
|
||||
revisionItems = await server.get('note-revisions/' + noteId);
|
||||
|
||||
for (const item of revisionItems) {
|
||||
const dateModified = utils.parseDate(item.dateModifiedFrom);
|
||||
|
@ -105,7 +105,7 @@ addTabHandler((function() {
|
||||
$form.submit(() => {
|
||||
const protectedSessionTimeout = $protectedSessionTimeout.val();
|
||||
|
||||
settings.saveSettings(settingName, protectedSessionTimeout).then(() => {
|
||||
saveSettings(settingName, protectedSessionTimeout).then(() => {
|
||||
protectedSessionHolder.setProtectedSessionTimeout(protectedSessionTimeout);
|
||||
});
|
||||
|
||||
@ -127,7 +127,7 @@ addTabHandler((function () {
|
||||
}
|
||||
|
||||
$form.submit(() => {
|
||||
settings.saveSettings(settingName, $timeInterval.val());
|
||||
saveSettings(settingName, $timeInterval.val());
|
||||
|
||||
return false;
|
||||
});
|
||||
|
@ -1,31 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const sql = require('../../services/sql');
|
||||
const auth = require('../../services/auth');
|
||||
const protected_session = require('../../services/protected_session');
|
||||
const sync_table = require('../../services/sync_table');
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
|
||||
router.get('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
async function getNoteRevisions(req) {
|
||||
const noteId = req.params.noteId;
|
||||
const revisions = await sql.getRows("SELECT * FROM note_revisions WHERE noteId = ? order by dateModifiedTo desc", [noteId]);
|
||||
protected_session.decryptNoteRevisions(req, revisions);
|
||||
|
||||
res.send(revisions);
|
||||
}));
|
||||
return revisions;
|
||||
}
|
||||
|
||||
router.put('', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const sourceId = req.headers.source_id;
|
||||
|
||||
await sql.doInTransaction(async () => {
|
||||
await sql.replace("note_revisions", req.body);
|
||||
|
||||
await sync_table.addNoteRevisionSync(req.body.noteRevisionId, sourceId);
|
||||
});
|
||||
|
||||
res.send();
|
||||
}));
|
||||
|
||||
module.exports = router;
|
||||
module.exports = {
|
||||
getNoteRevisions
|
||||
};
|
@ -1,16 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const sql = require('../../services/sql');
|
||||
const changePassword = require('../../services/change_password');
|
||||
const auth = require('../../services/auth');
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
const changePasswordService = require('../../services/change_password');
|
||||
|
||||
router.post('/change', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const result = await changePassword.changePassword(req.body['current_password'], req.body['new_password'], req);
|
||||
async function changePassword(req) {
|
||||
return await changePasswordService.changePassword(req.body['current_password'], req.body['new_password'], req);
|
||||
}
|
||||
|
||||
res.send(result);
|
||||
}));
|
||||
|
||||
module.exports = router;
|
||||
module.exports = {
|
||||
changePassword
|
||||
};
|
@ -1,12 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const sql = require('../../services/sql');
|
||||
const auth = require('../../services/auth');
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
|
||||
router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
async function getRecentChanges() {
|
||||
const recentChanges = await sql.getRows(
|
||||
`SELECT
|
||||
notes.isDeleted AS current_isDeleted,
|
||||
@ -19,7 +15,9 @@ router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
dateModifiedTo DESC
|
||||
LIMIT 1000`);
|
||||
|
||||
res.send(recentChanges);
|
||||
}));
|
||||
return recentChanges;
|
||||
}
|
||||
|
||||
module.exports = router;
|
||||
module.exports = {
|
||||
getRecentChanges
|
||||
};
|
@ -1,44 +1,35 @@
|
||||
"use strict";
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const sql = require('../../services/sql');
|
||||
const options = require('../../services/options');
|
||||
const auth = require('../../services/auth');
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
|
||||
// options allowed to be updated directly in settings dialog
|
||||
const ALLOWED_OPTIONS = ['protected_session_timeout', 'note_revision_snapshot_time_interval'];
|
||||
|
||||
router.get('/all', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const settings = await sql.getMap("SELECT name, value FROM options");
|
||||
async function getAllSettings() {
|
||||
return await sql.getMap("SELECT name, value FROM options");
|
||||
}
|
||||
|
||||
res.send(settings);
|
||||
}));
|
||||
|
||||
router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
async function getAllowedSettings() {
|
||||
const settings = await sql.getMap("SELECT name, value FROM options WHERE name IN ("
|
||||
+ ALLOWED_OPTIONS.map(x => '?').join(",") + ")", ALLOWED_OPTIONS);
|
||||
|
||||
res.send(settings);
|
||||
}));
|
||||
return settings;
|
||||
}
|
||||
|
||||
router.post('/', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
async function updateSetting(req) {
|
||||
const body = req.body;
|
||||
const sourceId = req.headers.source_id;
|
||||
|
||||
if (ALLOWED_OPTIONS.includes(body['name'])) {
|
||||
const optionName = await options.getOption(body['name']);
|
||||
|
||||
await sql.doInTransaction(async () => {
|
||||
await options.setOption(body['name'], body['value'], sourceId);
|
||||
});
|
||||
|
||||
res.send({});
|
||||
if (!ALLOWED_OPTIONS.includes(body['name'])) {
|
||||
return [400, "not allowed option to set"];
|
||||
}
|
||||
else {
|
||||
res.send("not allowed option to set");
|
||||
}
|
||||
}));
|
||||
|
||||
module.exports = router;
|
||||
await options.setOption(body['name'], body['value'], sourceId);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAllowedSettings,
|
||||
getAllSettings,
|
||||
updateSetting
|
||||
};
|
@ -61,13 +61,17 @@ function apiRoute(method, path, handler) {
|
||||
}
|
||||
}
|
||||
else if (result === undefined) {
|
||||
res.status(200);
|
||||
res.status(200).send();
|
||||
}
|
||||
else {
|
||||
res.status(200).send(result);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
log.info(`${method} ${path} threw exception: ` + e.stack);
|
||||
|
||||
res.send(500);
|
||||
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
@ -106,11 +110,16 @@ function register(app) {
|
||||
apiRoute(GET, '/api/labels/names', labelsRoute.getAllLabelNames);
|
||||
apiRoute(GET, '/api/labels/values/:labelName', labelsRoute.getValuesForLabel);
|
||||
|
||||
app.use('/api/notes-revisions', noteRevisionsApiRoute);
|
||||
app.use('/api/recent-changes', recentChangesApiRoute);
|
||||
app.use('/api/settings', settingsApiRoute);
|
||||
app.use('/api/password', passwordApiRoute);
|
||||
app.use('/api/migration', migrationApiRoute);
|
||||
apiRoute(GET, '/api/note-revisions/:noteId', noteRevisionsApiRoute.getNoteRevisions);
|
||||
|
||||
apiRoute(GET, '/api/recent-changes', recentChangesApiRoute.getRecentChanges);
|
||||
|
||||
apiRoute(GET, '/api/settings', settingsApiRoute.getAllowedSettings);
|
||||
apiRoute(GET, '/api/settings/all', settingsApiRoute.getAllSettings);
|
||||
apiRoute(POST, '/api/settings', settingsApiRoute.updateSetting);
|
||||
|
||||
apiRoute(POST, '/api/password/change', passwordApiRoute.changePassword);
|
||||
|
||||
app.use('/api/sync', syncApiRoute);
|
||||
app.use('/api/login', loginApiRoute);
|
||||
app.use('/api/event-log', eventLogRoute);
|
||||
@ -127,7 +136,11 @@ function register(app) {
|
||||
app.use('/api/sender', senderRoute);
|
||||
app.use('/api/files', filesRoute);
|
||||
app.use('/api/search', searchRoute);
|
||||
|
||||
app.use('', router);
|
||||
|
||||
|
||||
app.use('/api/migration', migrationApiRoute);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -23,14 +23,7 @@ async function getOption(name) {
|
||||
}
|
||||
|
||||
async function setOption(name, value, sourceId = null) {
|
||||
let opt;
|
||||
|
||||
try {
|
||||
opt = await sql.getRow("SELECT * FROM options WHERE name = ?", [name]);
|
||||
}
|
||||
catch (e) {
|
||||
opt = await sql.getRow("SELECT * FROM options WHERE opt_name = ?", [name]);
|
||||
}
|
||||
const opt = await sql.getRow("SELECT * FROM options WHERE name = ?", [name]);
|
||||
|
||||
if (!opt) {
|
||||
throw new Error(`Option ${name} doesn't exist`);
|
||||
@ -40,14 +33,8 @@ async function setOption(name, value, sourceId = null) {
|
||||
await sync_table.addOptionsSync(name, sourceId);
|
||||
}
|
||||
|
||||
try {
|
||||
await sql.execute("UPDATE options SET value = ?, dateModified = ? WHERE name = ?",
|
||||
[value, utils.nowDate(), name]);
|
||||
}
|
||||
catch (e) {
|
||||
await sql.execute("UPDATE options SET opt_value = ?, date_modified = ? WHERE opt_name = ?",
|
||||
[value, utils.nowDate(), name]);
|
||||
}
|
||||
await sql.execute("UPDATE options SET value = ?, dateModified = ? WHERE name = ?",
|
||||
[value, utils.nowDate(), name]);
|
||||
}
|
||||
|
||||
async function createOption(name, value, isSynced, sourceId = null) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user