blitline-resizer
Advanced tools
Comparing version 0.1.0 to 0.2.0
17
index.js
@@ -9,2 +9,3 @@ var Blitline = require('simple_blitline_node'); | ||
var path = require('path'); | ||
var request = require('request'); | ||
@@ -19,3 +20,4 @@ var BlitlineResizer = function(config) { | ||
if (!validator.isURL(config.postbackUrl)) | ||
throw new TypeError('must provide a valid URL for \'postbackUrl\''); | ||
console.log('Blitline really recommends you provide a \'postbackUrl\': https://www.blitline.com/docs/polling\n' + | ||
'but since you have not provided a valid url we will long poll for a response'); | ||
@@ -89,3 +91,14 @@ if (typeof config.s3Bucket != 'string') | ||
if (!err) data.secret = secret; | ||
callback(err, data); | ||
if (config.postbackUrl || err) return callback(err, data); | ||
var jobs = data.results.map(function(value) { return value.job_id; }); | ||
var results = []; | ||
jobs.forEach(function(job_id) { | ||
request('https://cache.blitline.com/listen/' + job_id, function(err, res, body) { | ||
if (err) callback(err); | ||
results.push(JSON.parse(body)); | ||
if (results.length === jobs.length) callback(null, results); | ||
}); | ||
}); | ||
}); | ||
@@ -92,0 +105,0 @@ } |
{ | ||
"name": "blitline-resizer", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Resizes images using Blitline", | ||
@@ -25,2 +25,3 @@ "main": "index.js", | ||
"validator": "^3.27.0", | ||
"request": "^2.53.0", | ||
"xtend": "^4.0.0" | ||
@@ -35,3 +36,2 @@ }, | ||
"ngrok": "^0.1.98", | ||
"request": "^2.53.0", | ||
"tap-spec": "^2.2.2", | ||
@@ -38,0 +38,0 @@ "tape": "^3.0.3" |
@@ -18,4 +18,8 @@ [![Build Status](https://travis-ci.org/digidem/blitline-resizer.svg)](https://travis-ci.org/digidem/blitline-resizer) | ||
3. You will need a server that can receive and process the [postback](https://www.blitline.com/docs/postback) (think webhook) that Blitline posts to when image processing is complete. | ||
3. If you submit a postbackUrl you will need a server that can receive and process the [postback](https://www.blitline.com/docs/postback) (think webhook) that Blitline posts to when image processing is complete. | ||
If you set `options.postbackUrl` then `resize()` will return an array of hashes with job_id according to https://www.blitline.com/docs/api#returnData - one job for each image you submit. | ||
If you do not set `options.postbackUrl` then it should return an array of results for each image as described http://www.blitline.com/docs/postback - this is not guaranteed though, the request can timeout. Using a postbackUrl is more reliable. | ||
```javascript | ||
@@ -43,9 +47,9 @@ var config = { | ||
Needs a config file `./test_config.json`: | ||
Needs the following environment variables set: | ||
```json | ||
{ | ||
"blitline_app_id": "YOUR_BLITLINE_APP_ID", | ||
"s3_bucket": "TEST_AMAZON_S3_BUCKET_NAME" | ||
} | ||
```sh | ||
BLITLINE_APP_ID=_your blitline app id_ | ||
S3_KEY=_s3 key ID for test user_ | ||
S3_SECRET=_s3 secret key for test user_ | ||
S3_BUCKET=_test s3 bucket_ # NB. Blitline should have PutObject permissions, your S3 test user should have DeleteObject permissions | ||
``` | ||
@@ -58,3 +62,3 @@ | ||
- [x] Better test coverage | ||
- [ ] Support [polling](https://www.blitline.com/docs/polling) to avoid needing postback server | ||
- [x] Support [polling](https://www.blitline.com/docs/polling) to avoid needing postback server | ||
- [ ] Allow resizing to fit both height and width | ||
@@ -64,4 +68,8 @@ | ||
### v0.2.0 | ||
Support for long polling without a postback | ||
### v0.1.0 | ||
Add `options.retina` to also create retina versions of images. Defaults to false. **NB. Breaking change** previously it created retina versions by default. |
28
test.js
@@ -45,3 +45,2 @@ var test = require('tape'); | ||
t.throws(Resizer.bind(null, {}), /must provide a 'blitlineAppId' option/, 'throws if no blitlineAppId option'); | ||
t.throws(Resizer.bind(null, { blitlineAppId: 'dummy' }), /must provide a valid URL for 'postbackUrl'/, 'throws if no valid postbackUrl'); | ||
@@ -259,2 +258,29 @@ ngrok.connect(port, function(err, url) { | ||
test('Long polls for response if no postbackUrl is provided', function(t) { | ||
var resize = Resizer({ | ||
blitlineAppId: process.env.BLITLINE_APP_ID, | ||
s3Bucket: process.env.S3_BUCKET | ||
}), | ||
timer; | ||
var resizeTask = { | ||
images: images, | ||
sizes: [500, 1000] | ||
}; | ||
resize(resizeTask, function(err, data) { | ||
t.error(err, 'longpoll returned without error'); | ||
t.ok(data instanceof Array, 'got an array back'); | ||
t.equal(data.length, resizeTask.images.length, 'got correct number of jobs back'); | ||
t.equal(typeof data[0], 'object', 'got and object back for first job'); | ||
t.error(data[0].results.errors, 'Blitline processing complete without errors'); | ||
t.equal(data[0].results.images.length, resizeTask.sizes.length, 'got correct number of images back'); | ||
t.end(); | ||
}); | ||
postbackCallback = function(err, req, res) { | ||
t.fail('should not call postback'); | ||
}; | ||
}); | ||
teardown(test); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16480
8
345
72
6
8
+ Addedrequest@^2.53.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.13.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)