refactor: replace got with fetch
This commit is contained in:
parent
7cb3cd0567
commit
565d2f9236
|
@ -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"
|
||||
|
|
11
src/build.js
11
src/build.js
|
@ -7,13 +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 got from 'got'
|
||||
import unzip from 'extract-zip'
|
||||
import { basename, 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'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
const envVar = process.env
|
||||
|
@ -44,8 +44,9 @@ const oisdFilters = {
|
|||
}
|
||||
|
||||
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)
|
||||
|
@ -62,7 +63,7 @@ const dl = async (project) => {
|
|||
console.log(`Downloading ${filename} from "${link}"`)
|
||||
try {
|
||||
await pipeline(
|
||||
got.stream(link),
|
||||
Readable.fromWeb((await fetch(link)).body),
|
||||
createWriteStream(zipPath)
|
||||
)
|
||||
await pipelineStatus(pipelineUrl)
|
||||
|
@ -79,7 +80,7 @@ const dl = async (project) => {
|
|||
|
||||
try {
|
||||
await pipeline(
|
||||
got.stream(mirrorLink),
|
||||
Readable.fromWeb((await fetch(mirrorLink)).body),
|
||||
createWriteStream(zipPath)
|
||||
)
|
||||
} catch ({ message }) {
|
||||
|
@ -104,7 +105,7 @@ const oisdDl = async (link, filename) => {
|
|||
console.log(`Downloading ${filename} from "${link}"`)
|
||||
try {
|
||||
await pipeline(
|
||||
got.stream(link),
|
||||
Readable.fromWeb((await fetch(link)).body),
|
||||
createWriteStream(txtPath)
|
||||
)
|
||||
} catch ({ message }) {
|
||||
|
|
Loading…
Reference in New Issue