Skip to content

Commit e2e3bae

Browse files
authored
fix: ditch cheerio and undici (#12040)
1 parent 608d54b commit e2e3bae

File tree

3 files changed

+24
-105
lines changed

3 files changed

+24
-105
lines changed

packages/server/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"@amplitude/analytics-types": "^1.3.2",
2424
"@types/analytics-node": "^3.1.3",
2525
"@types/bcryptjs": "^2.4.2",
26-
"@types/cheerio": "^0.22.30",
2726
"@types/dotenv": "^6.1.1",
2827
"@types/faker": "^5.5.9",
2928
"@types/jsdom": "^21.1.7",
@@ -76,7 +75,6 @@
7675
"adaptivecards": "2.10.0",
7776
"axios": "^1.8.4",
7877
"bcryptjs": "^2.4.3",
79-
"cheerio": "1.0.0",
8078
"cron": "^4.3.0",
8179
"dataloader": "^2.0.0",
8280
"dayjs": "^1.11.13",
@@ -105,6 +103,7 @@
105103
"nest-graphql-endpoint": "^0.8.3",
106104
"node-env-flag": "0.1.0",
107105
"node-html-markdown-cloudflare": "^1.3.0",
106+
"node-html-parser": "^7.0.1",
108107
"nodemailer": "^6.9.9",
109108
"oauth-1.0a": "^2.2.6",
110109
"object-hash": "^3.0.0",

packages/server/utils/atlassian/jiraImages.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base64url from 'base64url'
2-
import * as cheerio from 'cheerio'
32
import crypto from 'crypto'
43
import ms from 'ms'
4+
import {parse} from 'node-html-parser'
55
import type AtlassianServerManager from '../AtlassianServerManager'
66
import getRedis from '../getRedis'
77

@@ -24,21 +24,20 @@ export const updateJiraImageUrls = (cloudId: string, descriptionHTML: string) =>
2424
const imageUrlToHash = {} as Record<string, string>
2525
const projectBaseUrl = `https://api.atlassian.com/ex/jira/${cloudId}`
2626
if (!descriptionHTML) return {updatedDescription: descriptionHTML, imageUrlToHash}
27-
const $ = cheerio.load(descriptionHTML)
28-
$('body')
29-
.find('img')
30-
.each((_i, img) => {
31-
const imageUrl = $(img).attr('src')
32-
if (!imageUrl) return
3327

34-
const absoluteImageUrl = `${projectBaseUrl}${imageUrl}`
35-
const hashedImageUrl = createImageUrlHash(absoluteImageUrl)
36-
imageUrlToHash[absoluteImageUrl] = hashedImageUrl
28+
const root = parse(descriptionHTML)
29+
const imgTags = root.getElementsByTagName('img')
30+
imgTags.forEach((img) => {
31+
const imageUrl = img.getAttribute('src')
32+
if (!imageUrl) return
3733

38-
$(img).attr('src', createParabolImageUrl(hashedImageUrl))
39-
})
34+
const absoluteImageUrl = `${projectBaseUrl}${imageUrl}`
35+
const hashedImageUrl = createImageUrlHash(absoluteImageUrl)
36+
imageUrlToHash[absoluteImageUrl] = hashedImageUrl
4037

41-
return {updatedDescription: $.html(), imageUrlToHash}
38+
img.setAttribute('src', createParabolImageUrl(hashedImageUrl))
39+
})
40+
return {updatedDescription: root.toString(), imageUrlToHash}
4241
}
4342

4443
export const downloadAndCacheImages = async (

pnpm-lock.yaml

Lines changed: 11 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)