From 1eb0efe2a263f4b3d2cdd549cf3abd45673c9e82 Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 14 Oct 2024 00:15:11 +0200 Subject: [PATCH] stream-json --- lib/apiswagger.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/apiswagger.js b/lib/apiswagger.js index 294c4bb..ef9c5ea 100644 --- a/lib/apiswagger.js +++ b/lib/apiswagger.js @@ -477,21 +477,23 @@ module.exports = (app, client) => { }, { asStream: true, meta: false }), instancescomment = [], block_count = 0, - pipeline = chain([ - parser(), - pick({ filter: 'hits.hits' }), - streamArray(), - data => { - block_count++ - instancescomment.push({ - instance: data.value._source.instance, comment: data.value._source.blocks.find(block => block.domain === clean(req.params.instance)).comment - }) - } - ]) + pipeline = chain([ + parser(), + pick({ filter: 'hits.hits' }), + streamArray(), + data => { + block_count++ + instancescomment.push({ + instance: data.value._source.instance, comment: data.value._source.blocks.find(block => block.domain === clean(req.params.instance)).comment + }) + } + ]) result.pipe(pipeline) - res.json({ - block_count, - instances: instancescomment + pipeline.on('end', () => { + res.json({ + block_count, + instances: instancescomment + }) }) } else { res.status(404).end()