From eba824a5b1ff2c2b33f75a9d2eb01aadae2e13d7 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 7 Mar 2022 22:57:48 +0100 Subject: [PATCH] added app-info method to etapi #2697 --- src/etapi/app_info.js | 12 ++++++++ src/etapi/etapi.openapi.yaml | 60 ++++++++++++++++++++++++++++++++++++ src/routes/routes.js | 2 ++ src/services/app_info.js | 3 +- test-etapi/app-info.http | 7 +++++ test-etapi/no-token.http | 8 ++++- 6 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 src/etapi/app_info.js create mode 100644 test-etapi/app-info.http diff --git a/src/etapi/app_info.js b/src/etapi/app_info.js new file mode 100644 index 000000000..ede96d792 --- /dev/null +++ b/src/etapi/app_info.js @@ -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 +}; diff --git a/src/etapi/etapi.openapi.yaml b/src/etapi/etapi.openapi.yaml index 3877bc03a..811517af5 100644 --- a/src/etapi/etapi.openapi.yaml +++ b/src/etapi/etapi.openapi.yaml @@ -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: diff --git a/src/routes/routes.js b/src/routes/routes.js index aee443e1a..f899e4f7d 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -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); diff --git a/src/services/app_info.js b/src/services/app_info.js index 674b31059..9ee16221f 100644 --- a/src/services/app_info.js +++ b/src/services/app_info.js @@ -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 }; diff --git a/test-etapi/app-info.http b/test-etapi/app-info.http new file mode 100644 index 000000000..5945a07b1 --- /dev/null +++ b/test-etapi/app-info.http @@ -0,0 +1,7 @@ +GET {{triliumHost}}/etapi/app-info +Authorization: {{authToken}} + +> {% + client.assert(response.status === 200); + client.assert(response.body == "Hi there!"); +%} diff --git a/test-etapi/no-token.http b/test-etapi/no-token.http index 441027e76..d8198ed2b 100644 --- a/test-etapi/no-token.http +++ b/test-etapi/no-token.http @@ -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); %} \ No newline at end of file +> {% client.assert(response.status === 404); %}