ETAPI auth, spec improvements etc.

This commit is contained in:
zadam
2022-01-10 17:09:20 +01:00
parent 2d2641dbd7
commit 91dec23d5e
90 changed files with 1468 additions and 11753 deletions

View File

@@ -10,8 +10,8 @@ const appInfo = require('../../services/app_info');
const eventService = require('../../services/events');
const sqlInit = require('../../services/sql_init');
const sql = require('../../services/sql');
const ApiToken = require('../../becca/entities/api_token');
const ws = require("../../services/ws");
const etapiTokenService = require("../../services/etapi_tokens");
function loginSync(req) {
if (!sqlInit.schemaExists()) {
@@ -90,15 +90,12 @@ function token(req) {
return [401, "Incorrect password"];
}
const apiToken = new ApiToken({
// for backwards compatibility with Sender which does not send the name
name: req.body.tokenName || "Trilium Sender",
token: utils.randomSecureToken()
}).save();
// for backwards compatibility with Sender which does not send the name
const tokenName = req.body.tokenName || "Trilium Sender / Web Clipper";
const {authToken} = etapiTokenService.createToken(tokenName);
return {
token: apiToken.token
};
return { token: authToken };
}
module.exports = {