Skip to content

Commit

Permalink
refactor: removes hardcoded https replace from string
Browse files Browse the repository at this point in the history
replace it with updated validImageUrl regex
  • Loading branch information
arkgor committed Sep 10, 2020
1 parent 0412d39 commit 3b669e4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils/getBasicImageProps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const validImageUrlPattern = /^\/\/a.storyblok.com\/f\/[0-9]+\/[0-9]+x[0-9]+\/[A-Za-z0-9]+\/[\S]+\.[A-Za-z]+/
const validImageUrlPattern = /^(https?:)?\/\/a.storyblok.com\/f\/[0-9]+\/[0-9]+x[0-9]+\/[A-Za-z0-9]+\/[\S]+\.[a-z]+/

function getBasicImageProps(image) {
let url = null
Expand All @@ -13,14 +13,14 @@ function getBasicImageProps(image) {
lqip = image.base64 ? image.base64 : null
}

url = url.replace('https:', '')
url = validImageUrlPattern.test(url) ? url : null

if (!url) {
return false
}

let originalPath = url.replace('//a.storyblok.com/', '')
const storyblokRegex = /^(https?:)?\/\/a.storyblok.com\//
let originalPath = url.replace(storyblokRegex, '')

let [, , dimensions, , filename] = originalPath.split('/')
let [width, height] = dimensions.split('x').map(num => parseInt(num, 10))
Expand Down

0 comments on commit 3b669e4

Please sign in to comment.