build: extract zip from stream

previous bug should be fixed in recent node versions
b03e462e42

https://github.com/ZJONSSON/node-unzipper/issues/271#issuecomment-2021223739
This commit is contained in:
MDLeom 2024-10-27 05:18:07 +00:00
parent 479825bc45
commit 499330a12d
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
2 changed files with 6 additions and 17 deletions

View File

@ -5,7 +5,7 @@
"build": "node src/build.js"
},
"dependencies": {
"extract-zip": "^2.0.1"
"unzipper": "^0.12.3"
},
"engines": {
"node": ">= 18.12.0"

View File

@ -7,10 +7,9 @@
// Instead of using the API, I find it easier to failover to GitHub.
// ref: https://gitlab.com/gitlab-org/gitlab/-/issues/29257
import unzip from 'extract-zip'
import { basename, dirname, join } from 'node:path'
import { Extract } from 'unzipper'
import { dirname, join } from 'node:path'
import { mkdir, readdir, rm } from 'node:fs/promises'
import { createWriteStream } from 'node:fs'
import { pipeline } from 'node:stream/promises'
import { fileURLToPath } from 'node:url'
import { Readable } from 'node:stream'
@ -24,7 +23,7 @@ const projects = [
'phishing-filter',
'tracking-filter',
'vn-badsite-filter',
'botnet-filter',
'botnet-filter'
// 'pup-filter'
]
@ -41,15 +40,13 @@ 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
console.log(`Downloading ${filename} from "${link}"`)
try {
await pipeline(
Readable.fromWeb((await fetch(link)).body),
createWriteStream(zipPath)
Extract({ path: rootPath })
)
await pipelineStatus(pipelineUrl)
} catch ({ message }) {
@ -61,12 +58,11 @@ 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),
createWriteStream(zipPath)
Extract({ path: publicPath })
)
} catch ({ message }) {
throw new Error(JSON.stringify({
@ -76,13 +72,6 @@ const dl = async (project) => {
}))
}
}
console.log(`Extracting ${basename(zipPath)}...`)
if (isMirror === false) {
await unzip(zipPath, { dir: rootPath })
} else {
await unzip(zipPath, { dir: publicPath })
}
}
const f = async () => {