Added URL support for Node.js client

This commit is contained in:
Chinmay Pandhare
2017-07-28 12:32:04 +05:30
parent b1c9949757
commit b59383ce53
2 changed files with 16 additions and 10 deletions

View File

@@ -8,10 +8,21 @@ function LoadImage(ref, name, src, main_callback) {
}
function CImage(src, callback) {
var datauri;
if (src.substring(0,11) == "data:image/") {
if (!!src.match(/^data:/i)) {
datauri = src;
callback(datauri);
}
else if (!ref.options.inBrowser && !!src.match(/^https?:\/\//i)) {
require( src.match(/^(https?):\/\//i)[1] ).get(src,function(res){
var data = '';
var contentType = res.headers['content-type'];
res.setEncoding('base64');
res.on('data',function(chunk) {data += chunk;});
res.on('end',function() {
callback("data:"+contentType+";base64,"+data);
});
});
}
else if (ref.options.inBrowser) {
var ext = src.split('.').pop();
var image = document.createElement('img');

View File

@@ -40,18 +40,13 @@ test('loadImages loads a DataURL image and creates a step.', function (t){
t.end();
});
test('loadImages loads a PATH image and creates a step. (NodeJS)', function (t){
if(sequencer.options.inBrowser){
t.equal(1,1,"Not applicable for Browser");
t.end();
}
else {
sequencer.loadImages(red);
if(!sequencer.options.inBrowser)
test('loadImages loads an image from PATH and creates a step. (NodeJS)', function (t){
sequencer.loadImages('examples/red.jpg');
t.equal(sequencer.images.image1.steps.length, 1, "Initial Step Created");
t.equal(typeof(sequencer.images.image1.steps[0].output.src), "string", "Initial output exists");
t.end();
}
});
});
test('loadImage works too.', function (t){
sequencer.loadImage('test2',red);