Fix line param parsing

lines is a positive integer or -1 to disable line limiting. The
default value is 10 if no argument is given.

Fixes #604
This commit is contained in:
Girish Ramakrishnan
2019-01-08 12:10:53 -08:00
parent 1affb2517a
commit 810f5e7409
9 changed files with 48 additions and 37 deletions
+5 -4
View File
@@ -59,13 +59,13 @@ function list(req, res, next) {
function getLogs(req, res, next) {
assert.strictEqual(typeof req.params.taskId, 'string');
var lines = req.query.lines ? parseInt(req.query.lines, 10) : 100;
var lines = 'lines' in req.query ? parseInt(req.query.lines, 10) : 10; // we ignore last-event-id
if (isNaN(lines)) return next(new HttpError(400, 'lines must be a number'));
var options = {
lines: lines,
follow: false,
format: req.query.format
format: req.query.format || 'json'
};
tasks.getLogs(req.params.taskId, options, function (error, logStream) {
@@ -86,7 +86,7 @@ function getLogs(req, res, next) {
function getLogStream(req, res, next) {
assert.strictEqual(typeof req.params.taskId, 'string');
var lines = req.query.lines ? parseInt(req.query.lines, 10) : -10; // we ignore last-event-id
var lines = 'lines' in req.query ? parseInt(req.query.lines, 10) : 10; // we ignore last-event-id
if (isNaN(lines)) return next(new HttpError(400, 'lines must be a valid number'));
function sse(id, data) { return 'id: ' + id + '\ndata: ' + data + '\n\n'; }
@@ -95,7 +95,8 @@ function getLogStream(req, res, next) {
var options = {
lines: lines,
follow: true
follow: true,
format: 'json'
};
tasks.getLogs(req.params.taskId, options, function (error, logStream) {