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"
|
"build": "node src/build.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"extract-zip": "^2.0.1",
|
"got": "^11.8.3",
|
||||||
"got": "^11.8.3"
|
"unzipper": "^0.10.14"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 14.15.0"
|
"node": ">= 14.15.0"
|
||||||
|
|
18
src/build.js
18
src/build.js
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
const { stream: gotStream } = require('got')
|
const { stream: gotStream } = require('got')
|
||||||
const got = require('got')
|
const got = require('got')
|
||||||
const unzip = require('extract-zip')
|
const { Extract: unzip } = require('unzipper')
|
||||||
const { basename, join } = require('path')
|
const { join } = require('path')
|
||||||
const { mkdir } = require('fs/promises')
|
const { mkdir } = require('fs/promises')
|
||||||
const { createWriteStream } = require('fs')
|
const { createWriteStream } = require('fs')
|
||||||
const { pipeline } = require('stream/promises')
|
const { pipeline } = require('stream/promises')
|
||||||
|
@ -45,7 +45,7 @@ const oisdFilters = {
|
||||||
const pipelineStatus = async (url) => {
|
const pipelineStatus = async (url) => {
|
||||||
try {
|
try {
|
||||||
const svg = await got(url).text()
|
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 }) {
|
} catch ({ message }) {
|
||||||
throw new Error(message)
|
throw new Error(message)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,6 @@ const pipelineStatus = async (url) => {
|
||||||
const dl = async (project) => {
|
const dl = async (project) => {
|
||||||
const filename = project + '.zip'
|
const filename = project + '.zip'
|
||||||
const link = `https://gitlab.com/malware-filter/${project}/-/jobs/artifacts/main/download?job=pages`
|
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`
|
const pipelineUrl = `https://gitlab.com/malware-filter/${project}/badges/main/pipeline.svg`
|
||||||
let isMirror = false
|
let isMirror = false
|
||||||
|
|
||||||
|
@ -62,7 +61,7 @@ const dl = async (project) => {
|
||||||
try {
|
try {
|
||||||
await pipeline(
|
await pipeline(
|
||||||
gotStream(link),
|
gotStream(link),
|
||||||
createWriteStream(zipPath)
|
unzip({ path: rootPath })
|
||||||
)
|
)
|
||||||
await pipelineStatus(pipelineUrl)
|
await pipelineStatus(pipelineUrl)
|
||||||
} catch ({ message }) {
|
} catch ({ message }) {
|
||||||
|
@ -79,7 +78,7 @@ const dl = async (project) => {
|
||||||
try {
|
try {
|
||||||
await pipeline(
|
await pipeline(
|
||||||
gotStream(mirrorLink),
|
gotStream(mirrorLink),
|
||||||
createWriteStream(zipPath)
|
unzip({ path: publicPath })
|
||||||
)
|
)
|
||||||
} catch ({ message }) {
|
} catch ({ message }) {
|
||||||
throw new Error(JSON.stringify({
|
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) => {
|
const oisdDl = async (link, filename) => {
|
||||||
|
|
Loading…
Reference in New Issue