Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added website thumbnails

  • Loading branch information...
commit f512a5d82262694f56e4d04f6c97a6a91514a27f 1 parent c452dd8
Jaakko Lukkari authored
27 lib/repositories/messages.js
View
@@ -270,8 +270,6 @@ exports.saveMessage = function (message, callback) {
data.id = id;
data.ts = time;
- eventEmitter.trigger('new_message', data);
-
var multi = redis.multi();
var hash = 'message:' + id;
@@ -312,7 +310,30 @@ exports.saveMessage = function (message, callback) {
return;
}
- callback(null, true);
+
+ (function nextUrl(i) {
+ var url = data.urls[i];
+ if (url == null) {
+ eventEmitter.trigger('new_message', data);
+ callback(null, true);
+ return;
+ }
+
+ if (url.type != 'website') {
+ nextUrl(++i);
+ return;
+ }
+
+ utils.makeWebPageThumbnail(url.url, __dirname + "/../../public/img/thumbnails/" + id + ".png", function (err) {
+ if (err) {
+ eventEmitter.trigger('new_message', data);
+ callback(err);
+ return;
+ }
+ nextUrl(++i);
+ });
+
+ })(0);
});
});
9 lib/utils.js
View
@@ -3,6 +3,9 @@ var tagRegex = /[#]+[ÄäÅåÖöA-Za-z0-9-_]+/;
var types = require('./mediatypes').media;
+var Thumbbot = require('thumbbot');
+
+
exports.parseMessage = function (message, callback) {
var msg = message.toString();
var urls = [];
@@ -55,5 +58,11 @@ exports.parseMessage = function (message, callback) {
});
})(0);
})(0);
+};
+exports.makeWebPageThumbnail = function (url, target, callback) {
+ console.log("Creating thumbnail", url, target);
+ var bot = new Thumbbot(url, target);
+ bot.set({width: 200, height: 150, method: 'resize'});
+ bot.snap(callback);
};
1  package.json
View
@@ -8,6 +8,7 @@
"redis":"0.7.1"
, "irc":"0.3.3"
, "express":"2.5.9"
+ , "thumbbot":"0.1.0"
, "request":"2.9.202"
, "reds":"0.1.3"
, "socket.io":"0.9.5"
BIN  public/img/thumbnails/10.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  public/img/thumbnails/11.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  public/img/thumbnails/12.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  public/img/thumbnails/13.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  public/img/thumbnails/9.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.