Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blitline-resizer

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blitline-resizer - npm Package Compare versions

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 @@ }

4

package.json
{
"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.

@@ -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);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc