refactor: replace got with fetch
This commit is contained in:
parent
21fe97dc0a
commit
5e3b49cf1f
|
@ -5,8 +5,7 @@
|
||||||
"build": "node src/build.js"
|
"build": "node src/build.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"extract-zip": "^2.0.1",
|
"extract-zip": "^2.0.1"
|
||||||
"got": "^13.0.0"
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 18.12.0"
|
"node": ">= 18.12.0"
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
// for deployment outside of GitLab CI, e.g. Cloudflare Pages and Netlify
|
// for deployment outside of GitLab CI, e.g. Cloudflare Pages and Netlify
|
||||||
|
|
||||||
import got from 'got'
|
|
||||||
import unzip from 'extract-zip'
|
import unzip from 'extract-zip'
|
||||||
import { dirname, join } from 'node:path'
|
import { dirname, join } from 'node:path'
|
||||||
import { mkdir } from 'node:fs/promises'
|
import { mkdir } from 'node:fs/promises'
|
||||||
import { createWriteStream } from 'node:fs'
|
import { createWriteStream } from 'node:fs'
|
||||||
import { pipeline } from 'node:stream/promises'
|
import { pipeline } from 'node:stream/promises'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import { Readable } from 'node:stream'
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||||
const rootPath = join(__dirname, '..')
|
const rootPath = join(__dirname, '..')
|
||||||
|
@ -20,8 +20,9 @@ const pipelineUrl = 'https://gitlab.com/malware-filter/tracking-filter/badges/ma
|
||||||
const ghMirror = 'https://nightly.link/curbengh/tracking-filter/workflows/pages/main/public.zip'
|
const ghMirror = 'https://nightly.link/curbengh/tracking-filter/workflows/pages/main/public.zip'
|
||||||
|
|
||||||
const pipelineStatus = async (url) => {
|
const pipelineStatus = async (url) => {
|
||||||
|
console.log(`Checking pipeline from "${url}"`)
|
||||||
try {
|
try {
|
||||||
const svg = await got(url).text()
|
const svg = await (await fetch(url)).text()
|
||||||
if (!svg.includes('passed')) throw new Error('last gitlab pipeline failed')
|
if (!svg.includes('passed')) throw new Error('last gitlab pipeline failed')
|
||||||
} catch ({ message }) {
|
} catch ({ message }) {
|
||||||
throw new Error(message)
|
throw new Error(message)
|
||||||
|
@ -36,7 +37,7 @@ const f = async () => {
|
||||||
console.log(`Downloading artifacts.zip from "${artifactsUrl}"`)
|
console.log(`Downloading artifacts.zip from "${artifactsUrl}"`)
|
||||||
try {
|
try {
|
||||||
await pipeline(
|
await pipeline(
|
||||||
got.stream(artifactsUrl),
|
Readable.fromWeb((await fetch(artifactsUrl)).body),
|
||||||
createWriteStream(zipPath)
|
createWriteStream(zipPath)
|
||||||
)
|
)
|
||||||
await pipelineStatus(pipelineUrl)
|
await pipelineStatus(pipelineUrl)
|
||||||
|
@ -51,7 +52,7 @@ const f = async () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await pipeline(
|
await pipeline(
|
||||||
got.stream(ghMirror),
|
Readable.fromWeb((await fetch(ghMirror)).body),
|
||||||
createWriteStream(zipPath)
|
createWriteStream(zipPath)
|
||||||
)
|
)
|
||||||
} catch ({ message }) {
|
} catch ({ message }) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ const { parse } = JSON
|
||||||
|
|
||||||
const f = async () => {
|
const f = async () => {
|
||||||
// __dirname is src/
|
// __dirname is src/
|
||||||
const outputFile = join(__dirname, '..', 'tmp','tracking-data-raw.txt')
|
const outputFile = join(__dirname, '..', 'tmp', 'tracking-data-raw.txt')
|
||||||
await rm(outputFile, { force: true })
|
await rm(outputFile, { force: true })
|
||||||
const domains = join(__dirname, '..', 'tmp', 'tracker-radar', 'domains')
|
const domains = join(__dirname, '..', 'tmp', 'tracker-radar', 'domains')
|
||||||
const countries = await readdir(domains)
|
const countries = await readdir(domains)
|
||||||
|
|
Loading…
Reference in New Issue