diff --git a/lib/apiswagger.js b/lib/apiswagger.js
index d8f7c7e..59c8724 100644
--- a/lib/apiswagger.js
+++ b/lib/apiswagger.js
@@ -3,6 +3,9 @@ const nodeinfo = require('activitypub-express/pub/nodeinfo')
module.exports = (app, client) => {
const constant = require('./constant'),
zlib = require('zlib'),
+ { chain } = require('stream-chain'),
+ { parser } = require('stream-json'),
+ { streamValues } = require('stream-json/streamers/StreamValues'),
clean = str => {
return str.replace(/[\/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '')
}
@@ -500,8 +503,8 @@ module.exports = (app, client) => {
*/
app.use('/api/download_index', async (req, res) => {
try {
- res.header('Content-Type', 'application/x-gzip')
- res.header('Content-disposition', 'attachment; filename=fediblock-index.json.gz')
+ res.setHeader('Content-Type', 'application/x-gzip')
+ res.setHeader('Content-disposition', 'attachment; filename=fediblock-index.json.gz')
const result = await client.search({
index: constant.index,
size: 9999,
@@ -509,7 +512,18 @@ module.exports = (app, client) => {
match_all: {}
}
}, { asStream: true })
- result.pipe(zlib.createGzip()).pipe(res, { end: true })
+ result.pipe(chain([
+ parser(),
+ streamValues(),
+ data => [data.value.hits.hits.map(hit => ({
+ instance: hit._source.instance,
+ blocks: hit._source.blocks,
+ api: hit._source.api,
+ last: hit._source.last,
+ nodeinfo: hit._source.nodeinfo
+ }))],
+ zlib.createGzip()
+ ])).pipe(res, { end: true })
} catch (e) {
console.error(e)
res.status(404).end()
diff --git a/package.json b/package.json
index 0d05a9b..fc2dfd4 100644
--- a/package.json
+++ b/package.json
@@ -25,6 +25,7 @@
"node-schedule": "^2.1.1",
"parcel": "^2.12.0",
"rotating-file-stream": "^3.2.5",
+ "stream-json": "^1.8.0",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1"
}
diff --git a/public/index.html b/public/index.html
index 35ef911..92aac24 100644
--- a/public/index.html
+++ b/public/index.html
@@ -54,8 +54,8 @@
Total scanned 0 instances with 0 peers - 0 created - 0
updated
- matrix off - download index - by ale
+ matrix off - download json index -
+ by ale
©2024