Comparing version 1.4.1 to 2.0.0
20
index.js
@@ -70,3 +70,4 @@ var uuid = require('uuid') | ||
Giffer.prototype.handleGif = function(url) { | ||
Giffer.prototype.handleGif = function(url, metadata) { | ||
if(!metadata || !metadata.origin) return | ||
this.urlDb.get(url, function(err, value) { | ||
@@ -77,28 +78,29 @@ if(!err && value) return | ||
this.download(id, url) | ||
this.download(id, url, metadata) | ||
}.bind(this)) | ||
} | ||
Giffer.prototype.download = function(id, url) { | ||
Giffer.prototype.download = function(id, url, metadata) { | ||
downloader.download(url, this.outDir + '/' + id + '.gif', function() { | ||
this.saveMetaData(url, id) | ||
this.saveMetaData(url, id, metadata) | ||
}.bind(this)) | ||
} | ||
Giffer.prototype.saveMetaData = function(url, id) { | ||
Giffer.prototype.saveMetaData = function(url, id, metadata) { | ||
this.urlDb.put(url, { | ||
filename: id + '.gif', | ||
dir: this.outDir, | ||
time: new Date().getTime() | ||
time: new Date().getTime(), | ||
meta: metadata | ||
}, function(err) { | ||
if(err) throw err | ||
this.emitGif(id + '.gif') | ||
this.emitGif(id + '.gif', metadata) | ||
}.bind(this)) | ||
} | ||
Giffer.prototype.emitGif = function(filename) { | ||
this.emit('gif', filename) | ||
Giffer.prototype.emitGif = function(filename, metadata) { | ||
this.emit('gif', filename, metadata) | ||
} | ||
module.exports = Giffer |
{ | ||
"name": "giffer", | ||
"version": "1.4.1", | ||
"version": "2.0.0", | ||
"description": "GIF download bot", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,3 +11,3 @@ var test = require('tap').test | ||
test('Test basic functionality of giffer', function(t) { | ||
t.plan(5) | ||
t.plan(7) | ||
var testAdapter = new TestAdapter() | ||
@@ -39,7 +39,9 @@ | ||
giffer.start() | ||
giffer.on('gif', function(url) { | ||
giffer.on('gif', function(url, metadata) { | ||
giffer.stop() | ||
t.ok(url) | ||
t.ok(metadata) | ||
t.ok(metadata.origin) | ||
t.end() | ||
}) | ||
}) |
@@ -9,3 +9,3 @@ var inherits = require('util').inherits | ||
TestAdapter.prototype.start = function() { | ||
setTimeout(this.emit.bind(this, 'gif', 'http://d3dsacqprgcsqh.cloudfront.net/photo/axNxReD_460sa_v1.gif'), 2000) | ||
setTimeout(this.emit.bind(this, 'gif', 'http://d3dsacqprgcsqh.cloudfront.net/photo/axNxReD_460sa_v1.gif', { origin: 'test' }), 2000) | ||
} | ||
@@ -12,0 +12,0 @@ |
7177
169