mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Convert routes/api/options
This commit is contained in:
parent
c63c7d518c
commit
3d75366f02
@ -1,9 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const optionService = require('../../services/options');
|
import optionService = require('../../services/options');
|
||||||
const log = require('../../services/log');
|
import log = require('../../services/log');
|
||||||
const searchService = require('../../services/search/services/search');
|
import searchService = require('../../services/search/services/search');
|
||||||
const ValidationError = require('../../errors/validation_error');
|
import ValidationError = require('../../errors/validation_error');
|
||||||
|
import { Request } from 'express';
|
||||||
|
|
||||||
// options allowed to be updated directly in the Options dialog
|
// options allowed to be updated directly in the Options dialog
|
||||||
const ALLOWED_OPTIONS = new Set([
|
const ALLOWED_OPTIONS = new Set([
|
||||||
@ -62,7 +63,7 @@ const ALLOWED_OPTIONS = new Set([
|
|||||||
|
|
||||||
function getOptions() {
|
function getOptions() {
|
||||||
const optionMap = optionService.getOptionMap();
|
const optionMap = optionService.getOptionMap();
|
||||||
const resultMap = {};
|
const resultMap: Record<string, string> = {};
|
||||||
|
|
||||||
for (const optionName in optionMap) {
|
for (const optionName in optionMap) {
|
||||||
if (isAllowed(optionName)) {
|
if (isAllowed(optionName)) {
|
||||||
@ -75,7 +76,7 @@ function getOptions() {
|
|||||||
return resultMap;
|
return resultMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateOption(req) {
|
function updateOption(req: Request) {
|
||||||
const {name, value} = req.params;
|
const {name, value} = req.params;
|
||||||
|
|
||||||
if (!update(name, value)) {
|
if (!update(name, value)) {
|
||||||
@ -83,7 +84,7 @@ function updateOption(req) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateOptions(req) {
|
function updateOptions(req: Request) {
|
||||||
for (const optionName in req.body) {
|
for (const optionName in req.body) {
|
||||||
if (!update(optionName, req.body[optionName])) {
|
if (!update(optionName, req.body[optionName])) {
|
||||||
// this should be improved
|
// this should be improved
|
||||||
@ -93,7 +94,7 @@ function updateOptions(req) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function update(name, value) {
|
function update(name: string, value: string) {
|
||||||
if (!isAllowed(name)) {
|
if (!isAllowed(name)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -128,14 +129,14 @@ function getUserThemes() {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAllowed(name) {
|
function isAllowed(name: string) {
|
||||||
return ALLOWED_OPTIONS.has(name)
|
return ALLOWED_OPTIONS.has(name)
|
||||||
|| name.startsWith("keyboardShortcuts")
|
|| name.startsWith("keyboardShortcuts")
|
||||||
|| name.endsWith("Collapsed")
|
|| name.endsWith("Collapsed")
|
||||||
|| name.startsWith("hideArchivedNotes");
|
|| name.startsWith("hideArchivedNotes");
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export = {
|
||||||
getOptions,
|
getOptions,
|
||||||
updateOption,
|
updateOption,
|
||||||
updateOptions,
|
updateOptions,
|
@ -30,7 +30,7 @@ const autocompleteApiRoute = require('./api/autocomplete');
|
|||||||
const cloningApiRoute = require('./api/cloning');
|
const cloningApiRoute = require('./api/cloning');
|
||||||
const revisionsApiRoute = require('./api/revisions');
|
const revisionsApiRoute = require('./api/revisions');
|
||||||
const recentChangesApiRoute = require('./api/recent_changes.js');
|
const recentChangesApiRoute = require('./api/recent_changes.js');
|
||||||
const optionsApiRoute = require('./api/options.js');
|
const optionsApiRoute = require('./api/options');
|
||||||
const passwordApiRoute = require('./api/password');
|
const passwordApiRoute = require('./api/password');
|
||||||
const syncApiRoute = require('./api/sync');
|
const syncApiRoute = require('./api/sync');
|
||||||
const loginApiRoute = require('./api/login');
|
const loginApiRoute = require('./api/login');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user