diff --git a/src/build.js b/src/build.js index 9e60c38..d212574 100644 --- a/src/build.js +++ b/src/build.js @@ -7,12 +7,13 @@ // Instead of using the API, I find it easier to failover to GitHub. // ref: https://gitlab.com/gitlab-org/gitlab/-/issues/29257 -import { Extract } from 'unzipper' -import { dirname, join } from 'node:path' +import { Open } from 'unzipper' +import { basename, dirname, join } from 'node:path' import { mkdir, readdir, rm, stat } from 'node:fs/promises' import { pipeline } from 'node:stream/promises' import { fileURLToPath } from 'node:url' import { Readable } from 'node:stream' +import { createWriteStream } from 'node:fs' const __dirname = dirname(fileURLToPath(import.meta.url)) const rootPath = join(__dirname, '..') @@ -39,14 +40,16 @@ const pipelineStatus = async (url) => { const dl = async (project) => { const filename = project + '.zip' + const zipPath = join(tmpPath, filename) const link = `https://gitlab.com/malware-filter/${project}/-/jobs/artifacts/main/download?job=pages` const pipelineUrl = `https://gitlab.com/malware-filter/${project}/badges/main/pipeline.svg` + let isMirror = false console.log(`Downloading ${filename} from "${link}"`) try { await pipeline( Readable.fromWeb((await fetch(link)).body), - Extract({ path: rootPath }) + createWriteStream(zipPath) ) await pipelineStatus(pipelineUrl) } catch ({ message }) { @@ -58,11 +61,12 @@ const dl = async (project) => { const mirrorLink = `https://nightly.link/curbengh/${project}/workflows/pages/main/public.zip` console.log(`Downloading ${filename} from "${mirrorLink}"`) + isMirror = true try { await pipeline( Readable.fromWeb((await fetch(mirrorLink)).body), - Extract({ path: publicPath }) + createWriteStream(zipPath) ) } catch ({ message }) { throw new Error(JSON.stringify({ @@ -72,6 +76,14 @@ const dl = async (project) => { })) } } + + console.log(`Extracting ${basename(zipPath)}...`) + if (isMirror === false) { + await Open.file(zipPath).then((dir) => dir.extract({ path: rootPath })) + } else { + await Open.file(zipPath).then((dir) => dir.extract({ path: publicPath })) + } + } const f = async () => {