refactor blockcount
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
ale 2024-11-15 21:56:24 +01:00
parent 0d3bf4be19
commit cfb7baff52
2 changed files with 8 additions and 9 deletions

View File

@ -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,12 +473,10 @@ 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({ objectMode: true })
])
pipeline.on('readable', () => res.write('['))
pipeline.on('data', data => res.write(data.toString() + ','))
pipeline.on('end', () => res.end(']'))
result.pipe(pipeline)
result.pipe(pipeline).pipe(res)
} else {
res.status(404).end()
}

View File

@ -37,9 +37,9 @@ document.addEventListener('DOMContentLoaded', function () {
if (content && content.length > 0) {
loading()
fetch('/api/block_count/' + content).then(async function (result) {
var res = await result.json()
if (Array.isArray(res) && res?.length >= 0) {
document.getElementById('blockcount').innerText = res.length
var res = await result.text()
if (res?.length >= 0) {
document.getElementById('blockcount').innerText = res.split('\n').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.map(function (instance, index) {
res.split('\n').map(JSON.parse).map(function (instance, index) {
var li = document.createElement('li'),
text = document.createTextNode((index + 1) + '. '),
link = '<a href="/' + (new URLSearchParams(window.location.search).has('matrix') ? '?matrix' : '') + '#' + instance.instance + '" onclick="window.location.href=this.href; window.location.reload(false);">' + instance.instance + '</a>',