Skip to content

Commit

Permalink
fix(selector): only select if image is valid
Browse files Browse the repository at this point in the history
schettn authored Sep 14, 2021
1 parent fa07b75 commit c0e6ee8
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/snek-finder/src/common/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const isValidHttpUrl = (string: string) => {
let url

try {
url = new URL(string)
} catch (_) {
return false
}

return url.protocol === 'http:' || url.protocol === 'https:'
}
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ import {useDropzone} from 'react-dropzone'

import {MimeTypes} from '../../../common/mimeTypes'
import {fileToBase64} from '../../../common/toBase64'
import {isValidHttpUrl} from '../../../common/url'
import {uuidv4} from '../../../common/uuid'
import ContextModal from '../../molecules/ContextModal'
import FileContextMenu from '../../molecules/FileContextMenu'
@@ -313,7 +314,12 @@ const Finder: React.FC<SnekFinderProps> = ({mode = 'browser', ...props}) => {
} else {
if (mode === 'selector') {
if (props.onSelectorSelect) {
props.onSelectorSelect(item)
const url = (item as FinderFileItem).src
// check if url is valid

if (isValidHttpUrl(url)) {
props.onSelectorSelect(item)
}
}
} else {
props.onItemOpen(uuid)

0 comments on commit c0e6ee8

Please sign in to comment.