Skip to content

Commit

Permalink
refactor: replace got with fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
MDLeom committed Apr 7, 2024
1 parent dea0ece commit 7c4b71b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"build": "node src/build.js"
},
"dependencies": {
"extract-zip": "^2.0.1",
"got": "^13.0.0"
"extract-zip": "^2.0.1"
},
"engines": {
"node": ">= 18.12.0"
Expand Down
9 changes: 5 additions & 4 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

// for deployment outside of GitLab CI, e.g. Cloudflare Pages and Netlify

import got from 'got'
import unzip from 'extract-zip'
import { dirname, join } from 'node:path'
import { mkdir } 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'

const __dirname = dirname(fileURLToPath(import.meta.url))
const rootPath = join(__dirname, '..')
Expand All @@ -20,8 +20,9 @@ const pipelineUrl = 'https://gitlab.com/malware-filter/urlhaus-filter/badges/mai
const ghMirror = 'https://nightly.link/curbengh/urlhaus-filter/workflows/pages/main/public.zip'

const pipelineStatus = async (url) => {
console.log(`Checking pipeline from "${url}"`)
try {
const svg = await got(url).text()
const svg = await (await fetch(url)).text()
if (svg.includes('failed')) throw new Error('last gitlab pipeline failed')
} catch ({ message }) {
throw new Error(message)
Expand All @@ -36,7 +37,7 @@ const f = async () => {
console.log(`Downloading artifacts.zip from "${artifactsUrl}"`)
try {
await pipeline(
got.stream(artifactsUrl),
Readable.fromWeb((await fetch(artifactsUrl)).body),
createWriteStream(zipPath)
)
await pipelineStatus(pipelineUrl)
Expand All @@ -51,7 +52,7 @@ const f = async () => {

try {
await pipeline(
got.stream(ghMirror),
Readable.fromWeb((await fetch(ghMirror)).body),
createWriteStream(zipPath)
)
} catch ({ message }) {
Expand Down

0 comments on commit 7c4b71b

Please sign in to comment.