Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Add optional image cache expiry to the imageResize API #87

Merged
merged 6 commits into from Jan 8, 2013
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/resizeImages.js
Expand Up @@ -26,6 +26,10 @@ var $ = Mobify.$
bits.push(projectId);
}

if (options.cacheHours && typeof(options.cacheHours) === 'number') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone sets options.cacheHours as a string, then this will silently fail. Probably bad because I would imagine some people might set the value as a string, for example:

options.cacheHours = 27;
options.cacheHours = '27';

I feel like both of those should work. If the argument IS a string, we can check with isNaN or parseInt to determine if it is a valid number, and throw an exception if it is not a number.

bits.push('c' + options.cacheHours)
}

if (options.format) {
bits.push(options.format + (options.quality || ''));
}
Expand Down
16 changes: 16 additions & 0 deletions tests/index.html
Expand Up @@ -463,6 +463,22 @@ <h2 id="qunit-userAgent"></h2>
}
});

test('Mobify.getImageURL - projectName and cache expiry set', function() {
expect(1);

try {
Mobify.$.fn.resizeImages.defaults.projectName = 'testing';

got = Mobify.getImageURL('http://test/image.jpg',
{maxWidth: 320, cacheHours:8});
vow = "//ir0.mobify.com/project-testing/c8/320/http://test/image.jpg";

equal(got, vow);
} finally {
delete Mobify.$.fn.resizeImages.defaults.projectName;
}
});


module('enhance');

Expand Down