From 3738e305da5cb29db181129d459df81eee9f8289 Mon Sep 17 00:00:00 2001 From: James Nicol Date: Sun, 11 Oct 2015 11:32:03 -0700 Subject: [PATCH] Bumped sharp version, fixed issues with removing mods from path. --- package.json | 2 +- src/image.js | 18 ++++-------------- src/lib/modifiers.js | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 8dbb725..b095707 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/image.js b/src/image.js index eab5fa4..4f1367b 100644 --- a/src/image.js +++ b/src/image.js @@ -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); }; diff --git a/src/lib/modifiers.js b/src/lib/modifiers.js index 0e4656b..35cb48a 100644 --- a/src/lib/modifiers.js +++ b/src/lib/modifiers.js @@ -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); @@ -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); @@ -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; } @@ -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); } @@ -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