Skip to content

Commit

Permalink
Bumped sharp version, fixed issues with removing mods from path.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmynicol committed Oct 11, 2015
1 parent 16f644e commit 3738e30
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -38,7 +38,7 @@
"mkdirp": "^0.5.0",
"morgan": "^1.0.1",
"request": "~2.34.0",
"sharp": "^0.10.1",
"sharp": "^0.11.3",
"twit": "~1.1.15"
},
"devDependencies": {
Expand Down
18 changes: 4 additions & 14 deletions src/image.js
Expand Up @@ -95,23 +95,13 @@ Image.prototype.parseUrl = function(request){
// not mess things up
parts[parts.length - 1] = this.image;

// if the request is for no modification or metadata then assume the s3path
// is the entire request path
if (_.indexOf(['original', 'json', 'resizeOriginal'], this.modifiers.action) > -1){
if (this.modifiers.external){
parts.shift();
this.path = parts.join('/');
} else {
this.path = parts.join('/');
}
}

// otherwise drop the first segment and set the s3path as the rest
else {
// if there is a modifier string remove it
if (this.modifiers.hasModStr) {
parts.shift();
this.path = parts.join('/');
}

this.path = parts.join('/');

// account for any spaces in the path
this.path = decodeURI(this.path);
};
Expand Down
17 changes: 14 additions & 3 deletions src/lib/modifiers.js
Expand Up @@ -166,7 +166,7 @@ function parseModifiers(mods, modArr) {
value = item.slice(1);

if (inArray(key, modKeys)){

// get the modifier object that responds to the listed key
mod = getModifier(key);

Expand All @@ -180,47 +180,56 @@ function parseModifiers(mods, modArr) {
if (mods.height > dimensionLimit) {
mods.height = dimensionLimit;
}
mods.hasModStr = true;
break;
case 'width':
mods.width = string.sanitize(value);
if (mods.width > dimensionLimit) {
mods.width = dimensionLimit;
}
mods.hasModStr = true;
break;
case 'square':
mods.action = 'square';
mods.height = string.sanitize(value);
mods.width = string.sanitize(value);
mods.hasModStr = true;
break;
case 'gravity':
value = string.sanitize(value, 'alpha');
if (inArray(value.toLowerCase(), mod.values)){
mods.gravity = value.toLowerCase();
}
mods.hasModStr = true;
break;
case 'top':
mods.y = string.sanitize(value);
mods.hasModStr = true;
break;
case 'left':
mods.x = string.sanitize(value);
mods.hasModStr = true;
break;
case 'crop':
value = string.sanitize(value, 'alpha');
if (inArray(value.toLowerCase(), mod.values)){
mods.crop = value.toLowerCase();
}
mods.hasModStr = true;
break;
case 'external':
value = string.sanitize(value, 'alphanumeric');
if (inArray(value.toLowerCase(), mod.values)){
mods.external = value.toLowerCase();
}
mods.hasModStr = true;
break;
case 'filter':
value = string.sanitize(value, 'alpha');
if (inArray(value.toLowerCase(), mod.values)){
mods.filter = value.toLowerCase();
}
mods.hasModStr = true;
break;
case 'quality':
value = string.sanitize(value);
Expand All @@ -229,6 +238,7 @@ function parseModifiers(mods, modArr) {
max = mod.range[1];
mods.quality = Math.max(min, Math.min(max, value));
}
mods.hasModStr = true;
break;
}

Expand Down Expand Up @@ -281,7 +291,7 @@ exports.parse = function(requestUrl, namedMods, envOverride){
// override 'env' for testing
if(typeof envOverride !== 'undefined'){
env = _.clone(envOverride);
}else{
} else {
env = _.clone(environment);
}

Expand All @@ -303,7 +313,8 @@ exports.parse = function(requestUrl, namedMods, envOverride){
width: null,
gravity: gravity.default,
crop: crop.default,
quality: quality.default
quality: quality.default,
hasModStr: false
};

// check the request to see if it includes a named modifier
Expand Down

0 comments on commit 3738e30

Please sign in to comment.