Compare commits

..

2 Commits

Author SHA1 Message Date
ale
3d78001edf download index
All checks were successful
continuous-integration/drone/push Build is passing
2024-09-23 05:11:56 +02:00
ale
30cea142d1 download index 2024-09-23 05:11:18 +02:00
3 changed files with 4 additions and 22 deletions

View File

@ -3,10 +3,6 @@ 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'),
{ chain } = require('stream-chain'),
{ parser } = require('stream-json'),
{ stringer } = require('stream-json/jsonl/Stringer'),
{ streamArray } = require('stream-json/streamers/StreamArray'),
clean = str => { clean = str => {
return str.replace(/[\/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '') return str.replace(/[\/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '')
} }
@ -505,28 +501,15 @@ 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/x-gzip') res.setHeader('Content-Type', 'application/x-gzip')
res.setHeader('Content-disposition', 'attachment; filename=fediblock-index.jsonl.gz') res.setHeader('Content-disposition', 'attachment; filename=fediblock-index.json.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 }) }, { asStream: true, meta: false })
result.pipe(chain([ result.pipe(zlib.createGzip()).pipe(res, { end: true })
parser(),
data => data.value.hits.hits,
streamArray(),
data => ({
instance: data.value._source.instance,
blocks: data.value._source.blocks,
api: data.value._source.api,
last: data.value._source.last,
nodeinfo: data.value._source.nodeinfo
}),
stringer(),
zlib.createGzip()
])).pipe(res, { end: true })
} catch (e) { } catch (e) {
console.error(e) console.error(e)
res.status(404).end() res.status(404).end()

View File

@ -25,7 +25,6 @@
"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"
} }

View File

@ -115,7 +115,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.jsonl.gz' a.download = 'fediblock-index.json.gz'
a.href = URL.createObjectURL(res) a.href = URL.createObjectURL(res)
a.type = 'application/x-gzip' a.type = 'application/x-gzip'
a.target = '_blank' a.target = '_blank'