refactor: unzip gotStream directly
without saving as a zipfile
This commit is contained in:
parent
61b1f67060
commit
c9617be450
|
@ -5,8 +5,8 @@
|
|||
"build": "node src/build.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"extract-zip": "^2.0.1",
|
||||
"got": "^11.8.3"
|
||||
"got": "^11.8.3",
|
||||
"unzipper": "^0.10.14"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14.15.0"
|
||||
|
|
18
src/build.js
18
src/build.js
|
@ -9,8 +9,8 @@
|
|||
|
||||
const { stream: gotStream } = require('got')
|
||||
const got = require('got')
|
||||
const unzip = require('extract-zip')
|
||||
const { basename, join } = require('path')
|
||||
const { Extract: unzip } = require('unzipper')
|
||||
const { 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('passed')) throw new Error('last gitlab pipeline failed')
|
||||
if (svg.includes('failed')) throw new Error('last gitlab pipeline failed')
|
||||
} catch ({ message }) {
|
||||
throw new Error(message)
|
||||
}
|
||||
|
@ -54,7 +54,6 @@ 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
|
||||
|
||||
|
@ -62,7 +61,7 @@ const dl = async (project) => {
|
|||
try {
|
||||
await pipeline(
|
||||
gotStream(link),
|
||||
createWriteStream(zipPath)
|
||||
unzip({ path: rootPath })
|
||||
)
|
||||
await pipelineStatus(pipelineUrl)
|
||||
} catch ({ message }) {
|
||||
|
@ -79,7 +78,7 @@ const dl = async (project) => {
|
|||
try {
|
||||
await pipeline(
|
||||
gotStream(mirrorLink),
|
||||
createWriteStream(zipPath)
|
||||
unzip({ path: publicPath })
|
||||
)
|
||||
} catch ({ message }) {
|
||||
throw new Error(JSON.stringify({
|
||||
|
@ -89,13 +88,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 oisdDl = async (link, filename) => {
|
||||
|
|
Loading…
Reference in New Issue