download link
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
ale 2024-09-23 01:22:27 +02:00
parent bc52c4b8cc
commit bfd205d568
5 changed files with 43 additions and 14 deletions

View File

@ -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()

View File

@ -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"
}

View File

@ -54,8 +54,8 @@
Total scanned <span id="instances">0</span> instances with <span id="peers">0</span> peers - <span
id="created">0</span> created - <span id="updated">0</span>
updated<br />
matrix <a id="matrix" href="/?matrix">off</a> - download <a download target="_blank"
href="/api/download_index">index</a> - by <a href="https://about.manalejandro.com" target="_blank">ale</a>
matrix <a id="matrix" href="/?matrix">off</a> - download json <a id="download" download target="_blank">index</a> -
by <a href="https://about.manalejandro.com" target="_blank">ale</a>
&copy;2024
</footer>
<div id="modal">

View File

@ -395,8 +395,6 @@
100% {
top: 109.5%
}
;
}
@keyframes l10-2 {

View File

@ -1,16 +1,10 @@
document.addEventListener('DOMContentLoaded', function () {
loading()
var hold = false,
external = false,
timeout = undefined,
ac = undefined,
last = undefined
var hold, external, timeout, ac, last
document.getElementById('instance').addEventListener('keydown', function (event) {
if (event.key && !event.ctrlKey && !event.altKey && !event.shiftKey) {
if ((event.key.length === 1 && /[a-z0-9.\-*:]/i.test(event.key)) || (event.key === 'Backspace' && event.target.value !== '')) {
last = event.target.value
} else if (event.key === 'Backspace' && event.target.value === '') {
last = ''
} else {
event.preventDefault()
event.stopPropagation()
@ -115,6 +109,28 @@ document.addEventListener('DOMContentLoaded', function () {
a.dispatchEvent(new MouseEvent('click'))
})
})
document.getElementById('download').addEventListener('click', function (event) {
loading()
ac = new AbortController()
try {
fetch('/api/donwload_index', { signal: ac.signal }).then(async function (result) {
var res = await result.blob(),
a = document.createElement('a')
a.download = 'fediblock-index.json.gz'
a.href = URL.createObjectURL(res)
a.type = 'application/x-gzip'
a.target = '_blank'
a.dispatchEvent(new MouseEvent('click'))
document.getElementById('loader-content').style.display = 'none'
}).catch(function (err) {
console.error(err)
document.getElementById('loader-content').style.display = 'none'
})
} catch (e) {
console.error(e)
document.getElementById('loader-content').style.display = 'none'
}
})
function keypress(event, content) {
loading()
if (timeout) {