Skip to content

Commit

Permalink
try url check
Browse files Browse the repository at this point in the history
  • Loading branch information
feruzm committed Oct 10, 2024
1 parent fc804de commit 4edf6d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ecency/render-helper",
"version": "2.2.35",
"version": "2.2.36",
"description": "Markdown+Html Render helper",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
11 changes: 10 additions & 1 deletion src/proxify-image-src.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ export function extractPHash(url: string): string | null {
return null
}

export function isValidUrl(url: string): boolean {
try {
return Boolean(new URL(url));
}
catch(e){
return false;
}
}

export function getLatestUrl(str: string): string {
const [last] = [...str.replace(/https?:\/\//g, '\n$&').trim().split('\n')].reverse()
return last
}

export function proxifyImageSrc(url?: string, width = 0, height = 0, format = 'match') {
if (!url || typeof url !== 'string') {
if (!url || typeof url !== 'string' || !isValidUrl(url)) {
return ''
}

Expand Down

0 comments on commit 4edf6d3

Please sign in to comment.