From b03e462e421486e31ee92a495fdae42ec36a160d Mon Sep 17 00:00:00 2001 From: MDLeom <2809763-curben@users.noreply.gitlab.com> Date: Sun, 6 Aug 2023 11:16:26 +0000 Subject: [PATCH] Revert "refactor: unzip gotStream directly" - extracted files are missing first few lines This reverts commit c9617be4500aa1392892b3bbe49c8db1c7a6f16d. --- package.json | 4 ++-- src/build.js | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 2410b73..a323a3b 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "build": "node src/build.js" }, "dependencies": { - "got": "^11.8.3", - "unzipper": "^0.10.14" + "extract-zip": "^2.0.1", + "got": "^11.8.3" }, "engines": { "node": ">= 16.13.0" diff --git a/src/build.js b/src/build.js index 2ad7787..77bbe75 100644 --- a/src/build.js +++ b/src/build.js @@ -9,8 +9,8 @@ const { stream: gotStream } = require('got') const got = require('got') -const { Extract: unzip } = require('unzipper') -const { join } = require('path') +const unzip = require('extract-zip') +const { basename, join } = require('path') const { mkdir } = require('fs/promises') const { createWriteStream } = require('fs') const { pipeline } = require('stream/promises') @@ -45,7 +45,7 @@ const oisdFilters = { const pipelineStatus = async (url) => { try { const svg = await got(url).text() - if (svg.includes('failed')) throw new Error('last gitlab pipeline failed') + if (!svg.includes('passed')) throw new Error('last gitlab pipeline failed') } catch ({ message }) { throw new Error(message) } @@ -54,6 +54,7 @@ const pipelineStatus = async (url) => { const dl = async (project) => { const filename = project + '.zip' const link = `https://gitlab.com/malware-filter/${project}/-/jobs/artifacts/main/download?job=pages` + const zipPath = join(tmpPath, filename) const pipelineUrl = `https://gitlab.com/malware-filter/${project}/badges/main/pipeline.svg` let isMirror = false @@ -61,7 +62,7 @@ const dl = async (project) => { try { await pipeline( gotStream(link), - unzip({ path: rootPath }) + createWriteStream(zipPath) ) await pipelineStatus(pipelineUrl) } catch ({ message }) { @@ -78,7 +79,7 @@ const dl = async (project) => { try { await pipeline( gotStream(mirrorLink), - unzip({ path: publicPath }) + createWriteStream(zipPath) ) } catch ({ message }) { throw new Error(JSON.stringify({ @@ -88,6 +89,13 @@ const dl = async (project) => { })) } } + + console.log(`Extracting ${basename(zipPath)}...`) + if (isMirror === false) { + await unzip(zipPath, { dir: rootPath }) + } else { + await unzip(zipPath, { dir: publicPath }) + } } const oisdDl = async (link, filename) => {