Created
March 11, 2017 15:22
-
-
Save taylorstine/3f3418b950d7fd527b17cdd90ad4faae to your computer and use it in GitHub Desktop.
Validate alter image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
export const validateRequest = (req, res, next)=>{ | |
async.applyEachSeries([ | |
validateHeaders, | |
validateUrlParams, | |
validateResizeRequest, | |
validateAlterImageRequest | |
], req, res, next); | |
}; | |
//... | |
export const validateAlterImageRequest = (req, res, next)=>{ | |
const {q:quality, b:blur} = req.query; | |
const qualityParsed:number = parseInt(quality); | |
let qualityValue = 100; | |
if (_.isFinite(qualityParsed) && _.inRange(qualityParsed, 1, 101)) { | |
qualityValue = qualityParsed | |
} | |
let blurValue = null; | |
if (blur === "true") { | |
blurValue = true | |
}else { | |
const blurParsed = parseInt(blur); | |
if (_.isFinite(blurParsed)) { | |
blurValue = blurParsed; | |
} | |
} | |
res.props = { | |
...res.props, | |
quality: qualityValue, | |
blur: blurValue | |
}; | |
next(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment