diff --git a/lib/api/get-log.js b/lib/api/get-log.js index af5d8b4..d517166 100644 --- a/lib/api/get-log.js +++ b/lib/api/get-log.js @@ -11,15 +11,19 @@ const db = require ('../db'); const { http } = require ('@sapphirecode/consts'); module.exports = async (req, res) => { - if ( - typeof req.headers.app_id === 'undefined' - || isNaN (parseInt (req.headers.app_id)) - ) { + const limit = parseInt (req.headers.limit); + const offset = parseInt (req.headers.offset); + const app_id = parseInt (req.headers.app_id); + + if (isNaN (app_id)) { res.status (http.status_bad_request) - .end (); - } - else { - res.status (http.status_ok) - .json (await db.log.get_all (parseInt (req.headers.app_id))); + .end ('app id not specified'); } + + res.status (http.status_ok) + .json (await db.log.get_all ( + parseInt (req.headers.app_id), + isNaN (limit) ? 100 : limit, + isNaN (offset) ? 0 : offset + )); }; diff --git a/lib/db/log.js b/lib/db/log.js index 39cc304..5f37220 100644 --- a/lib/db/log.js +++ b/lib/db/log.js @@ -8,7 +8,7 @@ 'use strict'; module.exports = (get_db) => ({ - get_all (app_id) { + get_all (app_id, limit = 100, offset = 0) { const knex = get_db (); return knex.select ( 'id', @@ -17,7 +17,10 @@ module.exports = (get_db) => ({ 'timestamp' ) .from ('log') - .where ({ app_id }); + .where ({ app_id }) + .orderBy ('timestamp') + .limit (Math.min (limit, 10000)) + .offset (offset); }, insert (app_id, message, data = '{}', timestamp = (new Date)) { const knex = get_db (); diff --git a/package.json b/package.json index 467089c..43f1cdd 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "@sapphirecode/consts": "^1.1.28", + "@sapphirecode/crypto-helper": "^1.1.57", "@sapphirecode/utilities": "^1.8.5", "body-parser": "^1.19.0", "chart.js": "^2.9.3", diff --git a/src/components/ConfigEditor.vue b/src/components/ConfigEditor.vue index 06100db..98eaf70 100644 --- a/src/components/ConfigEditor.vue +++ b/src/components/ConfigEditor.vue @@ -7,6 +7,14 @@ class="label" v-text="template.name" /> +