Skip to content

Commit

Permalink
Merge pull request #7942 from ForumMagnum/catch-invalid-image-urls
Browse files Browse the repository at this point in the history
Skip mirroring images with invalid URLs
  • Loading branch information
oetherington committed Oct 4, 2023
2 parents b7e99a4 + 9ef36e6 commit fc67cb6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/lesswrong/server/scripts/convertImagesToCloudinary.ts
Expand Up @@ -88,11 +88,15 @@ function getImageUrlWhitelist() {
}

function urlNeedsMirroring(url: string, filterFn: (url: string) => boolean) {
const parsedUrl = new URL(url);
if (getImageUrlWhitelist().indexOf(parsedUrl.hostname) !== -1) {
try {
const parsedUrl = new URL(url);
if (getImageUrlWhitelist().indexOf(parsedUrl.hostname) !== -1) {
return false;
}
return filterFn(url);
} catch (e) {
return false;
}
return filterFn(url);
}

async function convertImagesInHTML(html: string, originDocumentId: string, urlFilterFn: (url: string) => boolean = () => true): Promise<{count: number, html: string}> {
Expand Down

0 comments on commit fc67cb6

Please sign in to comment.