From 1fcadc150d889f2c595dfa6a0e5bd29547e3760a Mon Sep 17 00:00:00 2001 From: ale Date: Fri, 15 Nov 2024 20:50:56 +0100 Subject: [PATCH] refactor blockcount --- lib/apiswagger.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/apiswagger.js b/lib/apiswagger.js index 176a8ac..dcee05c 100644 --- a/lib/apiswagger.js +++ b/lib/apiswagger.js @@ -5,6 +5,7 @@ module.exports = (app, client) => { { parser } = require('stream-json'), { streamArray } = require('stream-json/streamers/StreamArray'), { chain } = require('stream-chain'), + { stringer } = require('stream-json/jsonl/Stringer'), clean = str => { return str.replace(/[/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '') } @@ -472,9 +473,12 @@ module.exports = (app, client) => { parser(), pick({ filter: 'hits.hits' }), streamArray(), - data => ({ instance: data.value._source.instance, comment: data.value._source.blocks.find(block => block.domain === clean(req.params.instance)).comment }) + data => ({ instance: data.value._source.instance, comment: data.value._source.blocks.find(block => block.domain === clean(req.params.instance)).comment }), + stringer() ]) - result.pipe(pipeline).pipe(res, { end: true }) + res.once('data', data => '[' + data.toString()) + res.on('finish', () => res.end(']')) + result.pipe(pipeline).pipe(res) } else { res.status(404).end() }