Updated logs viewer component

- now by default last 50 lines are showed
- added copy to clipboard button
- added loading spinner to indicate to users when the logs are loading

app.get('/api/logs') is now app.post to allow for additional parameters (such as lines to retrieve)
This commit is contained in:
Isaac Grynsztein
2020-07-03 03:46:58 -04:00
parent 3732d13562
commit a9f197e46d
11 changed files with 45 additions and 15 deletions

View File

@@ -29,6 +29,7 @@ var config_api = require('./config.js');
var subscriptions_api = require('./subscriptions')
const CONSTS = require('./consts')
const { spawn } = require('child_process')
const read_last_lines = require('read-last-lines');
const is_windows = process.platform === 'win32';
@@ -1867,15 +1868,17 @@ app.get('/api/using-encryption', function(req, res) {
res.send(usingEncryption);
});
app.get('/api/logs', function(req, res) {
app.post('/api/logs', async function(req, res) {
let logs = null;
let lines = req.body.lines;
logs_path = path.join('appdata', 'logs', 'combined.log')
if (fs.existsSync(logs_path))
logs = fs.readFileSync(logs_path, 'utf8');
if (fs.existsSync(logs_path)) {
if (lines) logs = await read_last_lines.read(logs_path, lines);
else logs = fs.readFileSync(logs_path, 'utf8');
}
else
logger.error(`Failed to find logs file at the expected location: ${logs_path}`)
console.log(logs)
res.send({
logs: logs,
success: !!logs