11import base64url from 'base64url'
2- import * as cheerio from 'cheerio'
32import crypto from 'crypto'
43import ms from 'ms'
4+ import { parse } from 'node-html-parser'
55import type AtlassianServerManager from '../AtlassianServerManager'
66import 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
4443export const downloadAndCacheImages = async (
0 commit comments