From 6ce68b15c5fea2ffd0c7ac2d0aee3d3088877a21 Mon Sep 17 00:00:00 2001 From: ale Date: Sun, 22 Sep 2024 00:49:45 +0200 Subject: [PATCH] out gc and download index --- lib/apiswagger.js | 32 +++++++++++++++++++++++++++++++- lib/fediblock.js | 3 --- package.json | 2 +- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/apiswagger.js b/lib/apiswagger.js index 0675f3f..c650659 100644 --- a/lib/apiswagger.js +++ b/lib/apiswagger.js @@ -2,6 +2,7 @@ const nodeinfo = require('activitypub-express/pub/nodeinfo') module.exports = (app, client) => { const constant = require('./constant'), + zlib = require('zlib'), clean = str => { return str.replace(/[\/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '') } @@ -476,7 +477,6 @@ module.exports = (app, client) => { instancescomment = instances.map(i => ({ instance: i._source.instance, comment: i._source.blocks.find(block => block.domain === clean(req.params.instance)).comment })) - global.gc() res.json({ block_count: instances.length, instances: instancescomment, @@ -486,4 +486,34 @@ module.exports = (app, client) => { res.status(404).end() } }) + /** + * @swagger + * /api/download_index: + * get: + * summary: Retrieve all content of ElasticSearch index. + * description: Retrieve all content of ElasticSearch index. + * responses: + * 200: + * description: A file compressed with gzip. + * content: + * application/octect-stream + */ + app.use('/api/download_index', async (req, res) => { + if (req.params.instance && req.params.instance.length > 0) { + const result = await client.search({ + index: constant.index, + size: 9999, + query: { + match_all: {} + } + }, { asStream: true }) + res.writeHead(200, { + 'Content-Type': 'application/x-gzip', + 'Content-disposition': 'attachment; filename=fediblock-index.json.gz' + }) + result.pipe(zlib.createGzip()).pipe(res, { end: true }) + } else { + res.status(404).end() + } + }) } diff --git a/lib/fediblock.js b/lib/fediblock.js index 6a4c399..f376361 100644 --- a/lib/fediblock.js +++ b/lib/fediblock.js @@ -148,10 +148,8 @@ module.exports = async (client, apex, app) => { console.error(e) } } - global.gc() yield 0 } catch (e) { - global.gc() console.error(e) yield 1 } @@ -220,7 +218,6 @@ module.exports = async (client, apex, app) => { } }, scanReturn = async () => { - global.gc() app.locals.scannum = 0 if (servers && servers.length > 0) { return await scan(servers.shift()) diff --git a/package.json b/package.json index 5347ce5..0d05a9b 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "license": "MIT", "scripts": { - "start": "node --max-old-space-size=1024 --expose-gc server.js", + "start": "node --max-old-space-size=1024 server.js", "build": "rm -rf dist/* && parcel build public/index.html --no-source-maps --dist-dir dist/", "install": "cd node_modules && rm -rf http-signature && rm -rf request/node_modules/http-signature && mv @peertube/http-signature ." },