From d3c6afa590b11df649151f9ad202021f6c8d3c91 Mon Sep 17 00:00:00 2001 From: ale Date: Sun, 22 Sep 2024 06:23:28 +0200 Subject: [PATCH] gzip download --- lib/apiswagger.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/apiswagger.js b/lib/apiswagger.js index fde03ec..be4ca3f 100644 --- a/lib/apiswagger.js +++ b/lib/apiswagger.js @@ -500,18 +500,17 @@ module.exports = (app, client) => { */ app.use('/api/download_index', async (req, res) => { try { - 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 }) + (await client.search({ + index: constant.index, + size: 9999, + query: { + match_all: {} + } + }, { asStream: true })).pipe(zlib.createGzip()).pipe(res, { end: true }) } catch (e) { console.error(e) res.status(404).end()