From 835629543300f3fd318fa926251a81c0bb78a6d8 Mon Sep 17 00:00:00 2001 From: ale Date: Sun, 22 Sep 2024 06:53:35 +0200 Subject: [PATCH] gzip download --- lib/apiswagger.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/apiswagger.js b/lib/apiswagger.js index e7bc2a7..373d4ed 100644 --- a/lib/apiswagger.js +++ b/lib/apiswagger.js @@ -500,18 +500,15 @@ module.exports = (app, client) => { */ app.use('/api/download_index', async (req, res) => { try { - res.writeHead(200, { - 'Content-Type': 'application/x-gzip', - 'Content-disposition': 'attachment; filename=fediblock-index.json.gz' - }) - const result = await client.search({ - index: constant.index, - size: 9999, - query: { - match_all: {} - } - }, { asStream: true }) - result.pipe(zlib.createGzip()).pipe(res, { end: true }) + res.header('Content-Type', 'application/x-gzip') + res.header('Content-disposition', 'attachment; filename=fediblock-index.json.gz') + (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()