Skip to content

Commit

Permalink
Update with querystring modifier support
Browse files Browse the repository at this point in the history
This is related to tripviss#22
  • Loading branch information
yamadapc committed Oct 5, 2016
1 parent 180bc37 commit a228b72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ app.use((err, req, res, next) => {
res.status(err.status || 500);
res.json({
error: err.message,
stack: err.stack,
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function Image(request) {
this.parseImage(request);

// determine the requested modifications
this.modifiers = modifiers.parse(request.path);
this.modifiers = modifiers.parse(request.path, null, null, request.query);

// pull the various parts needed from the request params
this.parseUrl(request);
Expand All @@ -61,8 +61,8 @@ Image.validOutputFormats = ['jpeg', 'png', 'webp'];
Image.prototype.parseImage = function(request){
const parts = request.path.split('/');
this.image = _.last(parts);
this.format = request.query.format;
this.outputFormat = request.query.outputFormat;
this.format = request.query.format || '';
this.outputFormat = request.query.outputFormat || '';
};

// Determine the file path for the requested image
Expand Down
16 changes: 8 additions & 8 deletions src/lib/modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ var limitMaxDimension = function(mods, env){
// Exposed method to parse an incoming URL for modifiers, can add a map of
// named (preset) modifiers if need be (mostly just for unit testing). Named
// modifiers are usually added via config json file in root of application.
exports.parse = function(requestUrl, namedMods, envOverride){
exports.parse = function(requestUrl, namedMods, envOverride, query) {
// override 'env' for testing
if(typeof envOverride !== 'undefined'){
if(envOverride != null) {
env = _.clone(envOverride);
} else {
env = _.clone(environment);
Expand All @@ -308,12 +308,12 @@ exports.parse = function(requestUrl, namedMods, envOverride){

// set the mod keys and defaults
mods = {
action: 'original',
height: null,
width: null,
gravity: gravity.default,
crop: crop.default,
quality: quality.default,
action: query.action || 'original',
height: !isNaN(+query.height) ? +query.height : null,
width: !isNaN(+query.width) ? +query.width : null,
gravity: query.gravity || gravity.default,
crop: query.crop || crop.default,
quality: query.quality || quality.default,
hasModStr: false
};

Expand Down

0 comments on commit a228b72

Please sign in to comment.