clean up sendImage code
This commit is contained in:
parent
a034cc1a0c
commit
24fe201b43
@ -53,11 +53,12 @@ class Matrix extends Adapter
|
|||||||
|
|
||||||
@robot.logger.info 'found image: downloading...'
|
@robot.logger.info 'found image: downloading...'
|
||||||
|
|
||||||
@getImage line, (buffer, info) =>
|
@downloadImage line, (buffer) =>
|
||||||
@sendImage envelope, buffer, info, -> done()
|
name = line.split('/')[-1..][0]
|
||||||
|
@sendImage envelope, buffer, name, -> done()
|
||||||
|
|
||||||
|
|
||||||
getImage: (imageURL, callback) ->
|
downloadImage: (imageURL, callback) ->
|
||||||
# process the image a bit
|
# process the image a bit
|
||||||
ne.get imageURL, follow_max: 5, (err, res, body) =>
|
ne.get imageURL, follow_max: 5, (err, res, body) =>
|
||||||
gm(body)
|
gm(body)
|
||||||
@ -66,15 +67,17 @@ class Matrix extends Adapter
|
|||||||
.resize(360000,'@>')
|
.resize(360000,'@>')
|
||||||
.toBuffer (err, buffer) =>
|
.toBuffer (err, buffer) =>
|
||||||
@robot.logger.info 'image downloaded and processed'
|
@robot.logger.info 'image downloaded and processed'
|
||||||
|
callback buffer
|
||||||
|
|
||||||
|
|
||||||
|
getImageInfo: (buffer, callback) ->
|
||||||
gm(buffer).identify "%m %w %h", (err, format) ->
|
gm(buffer).identify "%m %w %h", (err, format) ->
|
||||||
[type, width, height] = format.split ' '
|
[type, width, height] = format.split ' '
|
||||||
callback buffer,
|
callback
|
||||||
mimetype: "image/" + type.toLowerCase()
|
mimetype: "image/" + type.toLowerCase()
|
||||||
w: width
|
w: width
|
||||||
h: height
|
h: height
|
||||||
size: buffer.length
|
size: buffer.length
|
||||||
url: imageURL
|
|
||||||
|
|
||||||
|
|
||||||
sendText: (envelope, text, callback) ->
|
sendText: (envelope, text, callback) ->
|
||||||
@ -85,7 +88,7 @@ class Matrix extends Adapter
|
|||||||
callback() if callback?
|
callback() if callback?
|
||||||
|
|
||||||
|
|
||||||
sendImage: (envelope, buffer, info, callback) ->
|
sendRawImage: (envelope, buffer, info, callback) ->
|
||||||
try
|
try
|
||||||
@client.uploadContent(buffer,
|
@client.uploadContent(buffer,
|
||||||
name: info.url
|
name: info.url
|
||||||
@ -104,6 +107,14 @@ class Matrix extends Adapter
|
|||||||
callback() if callback?
|
callback() if callback?
|
||||||
|
|
||||||
|
|
||||||
|
sendImage: (envelope, buffer, name, callback) ->
|
||||||
|
@getImageInfo buffer, (info) =>
|
||||||
|
@sendRawImage envelope, buffer,
|
||||||
|
url: if name? then name else 'image'
|
||||||
|
mimetype: info.mimetype
|
||||||
|
, callback
|
||||||
|
|
||||||
|
|
||||||
send: (envelope, lines...) ->
|
send: (envelope, lines...) ->
|
||||||
[..., last] = lines
|
[..., last] = lines
|
||||||
if typeof last is 'function'
|
if typeof last is 'function'
|
||||||
|
Loading…
Reference in New Issue
Block a user