added app-info method to etapi #2697

This commit is contained in:
zadam 2022-03-07 22:57:48 +01:00
parent c9e72f8fb9
commit eba824a5b1
6 changed files with 89 additions and 3 deletions

12
src/etapi/app_info.js Normal file
View file

@ -0,0 +1,12 @@
const appInfo = require('../services/app_info');
const eu = require("./etapi_utils.js");
function register(router) {
eu.route(router, 'get', '/etapi/app-info', (req, res, next) => {
res.status(200).json(appInfo);
});
}
module.exports = {
register
};

View file

@ -589,6 +589,24 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/app-info:
get:
description: returns information about the running Trilium instance
operationId: getAppInfo
responses:
'200':
description: app info
content:
application/json:
schema:
$ref: '#/components/schemas/AppInfo'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
securitySchemes:
EtapiTokenAuth:
@ -777,6 +795,48 @@ components:
type: string
pattern: '[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}Z'
example: 2021-12-31 19:18:11.939Z
AppInfo:
type: object
required:
- statu
- code
- message
properties:
appVersion:
type: string
description: Trilium version
example: 0.50.2
dbVersion:
type: integer
format: int32
description: DB version
example: 194
syncVersion:
type: integer
format: int32
description: Sync protocol version
example: 25
buildDate:
type: string
format: date-time
description: build date
example: 2022-02-09T22:52:36+01:00
buildRevision:
type: string
description: git build revision
example: 23daaa2387a0655685377f0a541d154aeec2aae8
dataDirectory:
type: string
description: data directory where Trilium stores files
example: /home/user/data
clipperProtocolVersion:
type: string
description: version of the supported Trilium Web Clipper protocol
example: 1.0
utcDateTime:
type: string
description: current UTC date time
example: 2022-03-07T21:54:25.277Z
Error:
type: object
required:

View file

@ -42,6 +42,7 @@ const fontsRoute = require('./api/fonts');
const etapiTokensApiRoutes = require('./api/etapi_tokens');
const shareRoutes = require('../share/routes');
const etapiAuthRoutes = require('../etapi/auth');
const etapiAppInfoRoutes = require('../etapi/app_info');
const etapiAttributeRoutes = require('../etapi/attributes');
const etapiBranchRoutes = require('../etapi/branches');
const etapiNoteRoutes = require('../etapi/notes');
@ -391,6 +392,7 @@ function register(app) {
shareRoutes.register(router);
etapiAuthRoutes.register(router);
etapiAppInfoRoutes.register(router);
etapiAttributeRoutes.register(router);
etapiBranchRoutes.register(router);
etapiNoteRoutes.register(router);

View file

@ -1,7 +1,6 @@
"use strict";
const build = require('./build');
const dateUtils = require('./date_utils');
const packageJson = require('../../package');
const {TRILIUM_DATA_DIR} = require('./data_dir');
@ -17,5 +16,5 @@ module.exports = {
buildRevision: build.buildRevision,
dataDirectory: TRILIUM_DATA_DIR,
clipperProtocolVersion: CLIPPER_PROTOCOL_VERSION,
utcDateTime: dateUtils.utcNowDateTime() // for timezone inference
utcDateTime: new Date().toISOString() // for timezone inference
};

7
test-etapi/app-info.http Normal file
View file

@ -0,0 +1,7 @@
GET {{triliumHost}}/etapi/app-info
Authorization: {{authToken}}
> {%
client.assert(response.status === 200);
client.assert(response.body == "Hi there!");
%}

View file

@ -96,8 +96,14 @@ POST {{triliumHost}}/etapi/create-note
> {% client.assert(response.status === 401); %}
###
GET {{triliumHost}}/etapi/app-info
> {% client.assert(response.status === 401); %}
### Fake URL will get a 404 even without token
GET {{triliumHost}}/etapi/zzzzzz
> {% client.assert(response.status === 404); %}
> {% client.assert(response.status === 404); %}