diff --git a/lib/apiswagger.js b/lib/apiswagger.js index d8cd8dd..673d850 100644 --- a/lib/apiswagger.js +++ b/lib/apiswagger.js @@ -481,21 +481,9 @@ module.exports = (app, client) => { parser(), pick({ filter: 'hits.hits' }), streamArray(), - data => data.value._source + data => ({ instance: data.value._source.instance, comment: data.value._source.blocks.find(block => block.domain === clean(req.params.instance)).comment }) ]) - pipeline.on('data', data => { - block_count++ - instancescomment.push({ - instance: data.instance, comment: data.blocks.find(block => block.domain === clean(req.params.instance)).comment - }) - }) - pipeline.on('end', () => { - res.json({ - block_count, - instances: instancescomment - }) - }) - result.pipe(pipeline) + result.pipe(pipeline).pipe(res, { end: true }) } else { res.status(404).end() } diff --git a/public/main.js b/public/main.js index 5bd3734..5b1de35 100644 --- a/public/main.js +++ b/public/main.js @@ -38,8 +38,8 @@ document.addEventListener('DOMContentLoaded', function () { loading() fetch('/api/block_count/' + content).then(async function (result) { var res = await result.json() - if (res && res.block_count >= 0) { - document.getElementById('blockcount').innerText = res.block_count + if (Array.isArray(res) && res?.length >= 0) { + document.getElementById('blockcount').innerText = res.length document.getElementById('blockinstance').innerText = 'ing ' + content document.getElementById('blocktook').innerText = '' var list = document.getElementById('blocklist'), @@ -50,7 +50,7 @@ document.addEventListener('DOMContentLoaded', function () { while (list.hasChildNodes()) { list.removeChild(list.firstChild) } - res.instances.map(function (instance, index) { + res.map(function (instance, index) { var li = document.createElement('li'), text = document.createTextNode((index + 1) + '. '), link = '' + instance.instance + '',