|
|
|
|
@ -592,59 +592,57 @@ class SlackBridge { |
|
|
|
|
const parsedUrl = url.parse(slackFileURL, true); |
|
|
|
|
parsedUrl.headers = { 'Authorization': `Bearer ${ this.apiToken }` }; |
|
|
|
|
requestModule.get(parsedUrl, Meteor.bindEnvironment((stream) => { |
|
|
|
|
const fileStore = UploadFS.getStore('Uploads'); |
|
|
|
|
const fileId = fileStore.create(details); |
|
|
|
|
if (fileId) { |
|
|
|
|
fileStore.write(stream, fileId, (err, file) => { |
|
|
|
|
if (err) { |
|
|
|
|
throw new Error(err); |
|
|
|
|
} else { |
|
|
|
|
const url = file.url.replace(Meteor.absoluteUrl(), '/'); |
|
|
|
|
const attachment = { |
|
|
|
|
title: `File Uploaded: ${ file.name }`, |
|
|
|
|
title_link: url |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (/^image\/.+/.test(file.type)) { |
|
|
|
|
attachment.image_url = url; |
|
|
|
|
attachment.image_type = file.type; |
|
|
|
|
attachment.image_size = file.size; |
|
|
|
|
attachment.image_dimensions = file.identify && file.identify.size; |
|
|
|
|
} |
|
|
|
|
if (/^audio\/.+/.test(file.type)) { |
|
|
|
|
attachment.audio_url = url; |
|
|
|
|
attachment.audio_type = file.type; |
|
|
|
|
attachment.audio_size = file.size; |
|
|
|
|
} |
|
|
|
|
if (/^video\/.+/.test(file.type)) { |
|
|
|
|
attachment.video_url = url; |
|
|
|
|
attachment.video_type = file.type; |
|
|
|
|
attachment.video_size = file.size; |
|
|
|
|
} |
|
|
|
|
const fileStore = FileUpload.getStore('Uploads'); |
|
|
|
|
|
|
|
|
|
const msg = { |
|
|
|
|
rid: details.rid, |
|
|
|
|
ts: timeStamp, |
|
|
|
|
msg: '', |
|
|
|
|
file: { |
|
|
|
|
_id: file._id |
|
|
|
|
}, |
|
|
|
|
groupable: false, |
|
|
|
|
attachments: [attachment] |
|
|
|
|
}; |
|
|
|
|
fileStore.insert(details, stream, (err, file) => { |
|
|
|
|
if (err) { |
|
|
|
|
throw new Error(err); |
|
|
|
|
} else { |
|
|
|
|
const url = file.url.replace(Meteor.absoluteUrl(), '/'); |
|
|
|
|
const attachment = { |
|
|
|
|
title: `File Uploaded: ${ file.name }`, |
|
|
|
|
title_link: url |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (isImporting) { |
|
|
|
|
msg.imported = 'slackbridge'; |
|
|
|
|
} |
|
|
|
|
if (/^image\/.+/.test(file.type)) { |
|
|
|
|
attachment.image_url = url; |
|
|
|
|
attachment.image_type = file.type; |
|
|
|
|
attachment.image_size = file.size; |
|
|
|
|
attachment.image_dimensions = file.identify && file.identify.size; |
|
|
|
|
} |
|
|
|
|
if (/^audio\/.+/.test(file.type)) { |
|
|
|
|
attachment.audio_url = url; |
|
|
|
|
attachment.audio_type = file.type; |
|
|
|
|
attachment.audio_size = file.size; |
|
|
|
|
} |
|
|
|
|
if (/^video\/.+/.test(file.type)) { |
|
|
|
|
attachment.video_url = url; |
|
|
|
|
attachment.video_type = file.type; |
|
|
|
|
attachment.video_size = file.size; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (details.message_id && (typeof details.message_id === 'string')) { |
|
|
|
|
msg['_id'] = details.message_id; |
|
|
|
|
} |
|
|
|
|
const msg = { |
|
|
|
|
rid: details.rid, |
|
|
|
|
ts: timeStamp, |
|
|
|
|
msg: '', |
|
|
|
|
file: { |
|
|
|
|
_id: file._id |
|
|
|
|
}, |
|
|
|
|
groupable: false, |
|
|
|
|
attachments: [attachment] |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return RocketChat.sendMessage(rocketUser, msg, rocketChannel, true); |
|
|
|
|
if (isImporting) { |
|
|
|
|
msg.imported = 'slackbridge'; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (details.message_id && (typeof details.message_id === 'string')) { |
|
|
|
|
msg['_id'] = details.message_id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return RocketChat.sendMessage(rocketUser, msg, rocketChannel, true); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|