Use superagent for image download
This commit is contained in:
parent
6b0575f191
commit
357578e20c
|
@ -492,7 +492,7 @@ button {
|
|||
#chat .action .user:before {
|
||||
content: '* ';
|
||||
}
|
||||
#chat .thumb {
|
||||
#chat .image {
|
||||
max-height: 120px;
|
||||
max-width: 240px;
|
||||
}
|
||||
|
|
|
@ -223,8 +223,8 @@
|
|||
</span>
|
||||
<span class="text">
|
||||
<em class="type">{{type}}</em>
|
||||
{{#equal type "thumb"}}
|
||||
<img src="{{text}}" class="thumb">
|
||||
{{#equal type "image"}}
|
||||
<img src="{{text}}" class="image">
|
||||
{{else}}
|
||||
{{{uri text}}}
|
||||
{{/equal}}
|
||||
|
|
|
@ -367,7 +367,6 @@ $(function() {
|
|||
});
|
||||
|
||||
chat.on("msg", ".messages", function(e, target, msg) {
|
||||
console.log(msg);
|
||||
var btn = sidebar.find(".chan[data-target=" + target + "]:not(.active)");
|
||||
var query = btn.hasClass("query");
|
||||
var type = msg.type;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "shout",
|
||||
"description": "A web IRC client",
|
||||
"version": "0.10.0",
|
||||
"version": "0.10.1",
|
||||
"author": "Mattias Erming",
|
||||
"preferGlobal": true,
|
||||
"bin": {
|
||||
|
@ -30,7 +30,8 @@
|
|||
"moment": "~2.7.0",
|
||||
"read": "^1.0.5",
|
||||
"slate-irc": "~0.6.0",
|
||||
"socket.io": "~1.0.6"
|
||||
"socket.io": "~1.0.6",
|
||||
"superagent": "^0.18.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"grunt": "~0.4.5",
|
||||
|
|
|
@ -10,6 +10,7 @@ module.exports = Client;
|
|||
var id = 0;
|
||||
var events = [
|
||||
"error",
|
||||
"image",
|
||||
"join",
|
||||
"kick",
|
||||
"mode",
|
||||
|
@ -20,7 +21,6 @@ var events = [
|
|||
"notice",
|
||||
"part",
|
||||
"quit",
|
||||
"thumb",
|
||||
"topic",
|
||||
"welcome",
|
||||
"whois"
|
||||
|
|
|
@ -4,6 +4,7 @@ var moment = require("moment");
|
|||
Msg.Type = {
|
||||
ACTION: "action",
|
||||
ERROR: "error",
|
||||
IMAGE: "image",
|
||||
JOIN: "join",
|
||||
KICK: "kick",
|
||||
MESSAGE: "message",
|
||||
|
@ -13,7 +14,6 @@ Msg.Type = {
|
|||
NOTICE: "notice",
|
||||
PART: "part",
|
||||
QUIT: "quit",
|
||||
THUMB: "thumb",
|
||||
TOPIC: "topic",
|
||||
WHOIS: "whois"
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ var Msg = require("../../models/msg");
|
|||
var config = require("../../../config.json");
|
||||
var fs = require("fs");
|
||||
var mkdirp = require("mkdirp");
|
||||
var http = require("http");
|
||||
var request = require("superagent");
|
||||
|
||||
module.exports = function(irc, network) {
|
||||
var client = this;
|
||||
|
@ -26,7 +26,7 @@ module.exports = function(irc, network) {
|
|||
}
|
||||
fetchImage(image, function(name) {
|
||||
var msg = new Msg({
|
||||
type: Msg.Type.THUMB,
|
||||
type: Msg.Type.IMAGE,
|
||||
from: data.from,
|
||||
text: "thumbs/" + name
|
||||
});
|
||||
|
@ -41,23 +41,16 @@ module.exports = function(irc, network) {
|
|||
|
||||
function fetchImage(url, callback) {
|
||||
var path = process.env.HOME + "/.shout/cache/thumbs";
|
||||
var name = new Date().getTime().toString()
|
||||
var name = new Date().getTime().toString();
|
||||
mkdirp(path, function(e) {
|
||||
if (e) {
|
||||
console.log(e);
|
||||
}
|
||||
var stream = fs.createWriteStream(path + "/" + name);
|
||||
stream.on("error", function(e) {
|
||||
// ..
|
||||
});
|
||||
http.get(url, function(res) {
|
||||
res.on("data", function(chunk) {
|
||||
stream.write(chunk);
|
||||
});
|
||||
res.on("end", function() {
|
||||
stream.end();
|
||||
var req = request.get(url);
|
||||
req.pipe(stream);
|
||||
req.on("end", function() {
|
||||
callback(name);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue