Skip to content

Commit

Permalink
Skip mirroring images with invalid URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
oetherington committed Oct 4, 2023
1 parent dd9144f commit 9ef36e6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/lesswrong/server/scripts/convertImagesToCloudinary.ts
Original file line number Diff line number Diff line change
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 9ef36e6

Please sign in to comment.