From b44e199d1d2031172606495a4506e1fea64c6e28 Mon Sep 17 00:00:00 2001 From: ale Date: Fri, 15 Nov 2024 20:03:32 +0100 Subject: [PATCH] refactor blockcount --- lib/apiswagger.js | 16 ++-------------- public/main.js | 6 +++--- 2 files changed, 5 insertions(+), 17 deletions(-) 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 + '',