This commit is contained in:
parent
9699ffac71
commit
f85d17604b
@ -3,6 +3,10 @@ const nodeinfo = require('activitypub-express/pub/nodeinfo')
|
|||||||
module.exports = (app, client) => {
|
module.exports = (app, client) => {
|
||||||
const constant = require('./constant'),
|
const constant = require('./constant'),
|
||||||
zlib = require('zlib'),
|
zlib = require('zlib'),
|
||||||
|
{ pick } = require('stream-json/filters/Pick'),
|
||||||
|
{ parser } = require('stream-json'),
|
||||||
|
{ streamArray } = require('stream-json/streamers/StreamArray'),
|
||||||
|
{ chain } = require('stream-chain'),
|
||||||
clean = str => {
|
clean = str => {
|
||||||
return str.replace(/[/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '')
|
return str.replace(/[/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '')
|
||||||
}
|
}
|
||||||
@ -472,15 +476,24 @@ module.exports = (app, client) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}, { asStream: true, meta: false }),
|
||||||
const instances = result.hits?.hits?.length > 0 ? result.hits.hits : [],
|
instancescomment = [],
|
||||||
instancescomment = instances.map(i => ({
|
block_count = 0,
|
||||||
instance: i._source.instance, comment: i._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({
|
res.json({
|
||||||
block_count: instances.length,
|
block_count,
|
||||||
instances: instancescomment,
|
instances: instancescomment
|
||||||
took: result.took
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
res.status(404).end()
|
res.status(404).end()
|
||||||
@ -501,15 +514,22 @@ module.exports = (app, client) => {
|
|||||||
app.use('/api/download_index', async (req, res) => {
|
app.use('/api/download_index', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
res.setHeader('Content-Type', 'application/gzip')
|
res.setHeader('Content-Type', 'application/gzip')
|
||||||
res.setHeader('Content-disposition', 'attachment; filename=fediblock-index.json.gz')
|
res.setHeader('Content-disposition', 'attachment; filename=fediblock-index.jsonl.gz')
|
||||||
const result = await client.search({
|
const result = await client.search({
|
||||||
index: constant.index,
|
index: constant.index,
|
||||||
size: 9999,
|
size: 9999,
|
||||||
query: {
|
query: {
|
||||||
match_all: {}
|
match_all: {}
|
||||||
}
|
}
|
||||||
}, { asStream: true, meta: false })
|
}, { asStream: true, meta: false }),
|
||||||
result.pipe(zlib.createGzip()).pipe(res)
|
pipeline = chain([
|
||||||
|
parser(),
|
||||||
|
pick({ filter: 'hits.hits' }),
|
||||||
|
streamArray(),
|
||||||
|
data => JSON.stringify(data.value._source) + '\n',
|
||||||
|
zlib.createGzip()
|
||||||
|
])
|
||||||
|
result.pipe(pipeline).pipe(res)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
res.status(404).end()
|
res.status(404).end()
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
"node-schedule": "^2.1.1",
|
"node-schedule": "^2.1.1",
|
||||||
"parcel": "^2.12.0",
|
"parcel": "^2.12.0",
|
||||||
"rotating-file-stream": "^3.2.5",
|
"rotating-file-stream": "^3.2.5",
|
||||||
|
"stream-json": "^1.8.0",
|
||||||
"swagger-jsdoc": "^6.2.8",
|
"swagger-jsdoc": "^6.2.8",
|
||||||
"swagger-ui-express": "^5.0.1"
|
"swagger-ui-express": "^5.0.1"
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<p>
|
<p>
|
||||||
<span id="blockcount"></span> public instances are block<span id="blockinstance"></span>
|
<span id="blockcount"></span> public instances are block<span id="blockinstance"></span>
|
||||||
<br /><small>(search in <span id="blocktook"></span>ms)</small>
|
<br /><small id="blocktook"></small>
|
||||||
</p>
|
</p>
|
||||||
<ul id="blocklist"></ul>
|
<ul id="blocklist"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -39,7 +39,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
if (res && res.block_count >= 0) {
|
if (res && res.block_count >= 0) {
|
||||||
document.getElementById('blockcount').innerText = res.block_count
|
document.getElementById('blockcount').innerText = res.block_count
|
||||||
document.getElementById('blockinstance').innerText = 'ing ' + content
|
document.getElementById('blockinstance').innerText = 'ing ' + content
|
||||||
document.getElementById('blocktook').innerText = res.took
|
|
||||||
var list = document.getElementById('blocklist'),
|
var list = document.getElementById('blocklist'),
|
||||||
download = document.getElementById('download')
|
download = document.getElementById('download')
|
||||||
download.removeAttribute('href')
|
download.removeAttribute('href')
|
||||||
@ -115,7 +114,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
fetch('/api/download_index', { signal: ac.signal }).then(async function (result) {
|
fetch('/api/download_index', { signal: ac.signal }).then(async function (result) {
|
||||||
var res = await result.blob(),
|
var res = await result.blob(),
|
||||||
a = document.createElement('a')
|
a = document.createElement('a')
|
||||||
a.download = 'fediblock-index.json.gz'
|
a.download = 'fediblock-index.jsonl.gz'
|
||||||
a.href = URL.createObjectURL(res)
|
a.href = URL.createObjectURL(res)
|
||||||
a.type = 'application/gzip'
|
a.type = 'application/gzip'
|
||||||
a.target = '_blank'
|
a.target = '_blank'
|
||||||
@ -213,7 +212,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
document.getElementById('blockinstance').innerHTML = 'ed by ' + (res.api ? '<a href="/api/detail_api/' + res.instance + '" title="API info for ' + res.instance + '" target="_blank">'
|
document.getElementById('blockinstance').innerHTML = 'ed by ' + (res.api ? '<a href="/api/detail_api/' + res.instance + '" title="API info for ' + res.instance + '" target="_blank">'
|
||||||
+ res.instance + '</a>' : res.instance) + (res.nodeinfo ? ' <a href="/api/detail_nodeinfo/' + res.instance + '" title="Nodeinfo for ' + res.instance + '" target="_blank">ⓘ</a>' : '')
|
+ res.instance + '</a>' : res.instance) + (res.nodeinfo ? ' <a href="/api/detail_nodeinfo/' + res.instance + '" title="Nodeinfo for ' + res.instance + '" target="_blank">ⓘ</a>' : '')
|
||||||
+ '<br/>Last update: ' + (new Date(res.last)).toLocaleString()
|
+ '<br/>Last update: ' + (new Date(res.last)).toLocaleString()
|
||||||
document.getElementById('blocktook').innerText = res.took
|
document.getElementById('blocktook').innerText = '(search in ' + res.took + 'ms)'
|
||||||
if (csv.split('\n').length > 2) {
|
if (csv.split('\n').length > 2) {
|
||||||
download.href = window.URL.createObjectURL(new Blob([csv], { type: 'text/csv' }))
|
download.href = window.URL.createObjectURL(new Blob([csv], { type: 'text/csv' }))
|
||||||
download.download = 'fediblock-' + res.instance + '.csv'
|
download.download = 'fediblock-' + res.instance + '.csv'
|
||||||
|
Loading…
Reference in New Issue
Block a user