Skip to content
Snippets Groups Projects
Commit 566abe7b authored by Gabriel Engel's avatar Gabriel Engel
Browse files

Merge pull request #155 from RocketChat/rocket-packages

parents f905a6c0 ef529034
No related branches found
No related tags found
No related merge requests found
Showing
with 198 additions and 25 deletions
......@@ -50,3 +50,5 @@ rocket:file
pauli:accounts-linkedin
iframely:oembed
pierreeric:rxfavico
rocket:lib
rocket:me
\ No newline at end of file
......@@ -94,6 +94,8 @@ reactive-var@1.0.5
reload@1.1.3
retry@1.0.3
rocket:file@0.0.1
rocket:lib@0.0.1
rocket:me@0.0.1
routepolicy@1.0.5
service-configuration@1.0.4
session@1.1.0
......
The MIT License (MIT)
Copyright (c) 2015 ChatRocket
Copyright (c) 2015 RocketChat
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
@Rocket = (->
@RocketChat = (->
@Login = (->
......
{
"deploy": {
"production": {
"user": "root",
"host": ["rocket.chat"],
"ref": "origin/master",
"repo": "https://github.com/RocketChat/Rocket.Chat.git",
"path": "/var/www/rocket.chat",
"post-deploy": "source build.sh production"
}
}
}
......@@ -5,28 +5,28 @@ path = Npm.require('path')
mkdirp = Npm.require('mkdirp')
gm = Npm.require('gm')
RocketFile =
RocketChatFile =
gm: gm
RocketFile.bufferToStream = (buffer) ->
RocketChatFile.bufferToStream = (buffer) ->
bufferStream = new stream.PassThrough()
bufferStream.end buffer
bufferStream.end buffer
return bufferStream
RocketFile.dataURIParse = (dataURI) ->
RocketChatFile.dataURIParse = (dataURI) ->
imageData = dataURI.split ';base64,'
return {
image: imageData[1]
contentType: imageData[0].replace('data:', '')
}
RocketFile.addPassThrough = (st, fn) ->
RocketChatFile.addPassThrough = (st, fn) ->
pass = new stream.PassThrough()
fn pass, st
return pass
RocketFile.GridFS = class
RocketChatFile.GridFS = class
constructor: (config={}) ->
{name, transformWrite} = config
......@@ -61,7 +61,7 @@ RocketFile.GridFS = class
content_type: contentType
if self.transformWrite?
ws = RocketFile.addPassThrough ws, (rs, ws) ->
ws = RocketChatFile.addPassThrough ws, (rs, ws) ->
file =
name: self.name
fileName: fileName
......@@ -101,7 +101,7 @@ RocketFile.GridFS = class
return this.remove fileName
RocketFile.FileSystem = class
RocketChatFile.FileSystem = class
constructor: (config={}) ->
{absolutePath, transformWrite} = config
......@@ -127,7 +127,7 @@ RocketFile.FileSystem = class
ws = fs.createWriteStream path.join this.absolutePath, fileName
if self.transformWrite?
ws = RocketFile.addPassThrough ws, (rs, ws) ->
ws = RocketChatFile.addPassThrough ws, (rs, ws) ->
file =
fileName: fileName
contentType: contentType
......
Package.describe({
name: 'rocket:file',
name: 'rocketchat:file',
version: '0.0.1',
summary: '',
git: ''
......@@ -18,9 +18,9 @@ Package.onUse(function(api) {
api.addFiles('file.server.coffee', 'server');
api.export(['RocketFile'], ['server']);
api.export(['RocketChatFile'], ['server']);
});
Package.onTest(function(api) {
});
\ No newline at end of file
});
# https://github.com/TelescopeJS/Telescope/blob/master/packages/telescope-lib/lib/callbacks.js
###
# Callback hooks provide an easy way to add extra steps to common operations.
# @namespace RocketChat.callbacks
###
RocketChat.callbacks = {}
###
# Callback priorities
###
RocketChat.callbacks.priority =
HIGH: -1
MEDIUM: 0
LOW: 1
###
# Add a callback function to a hook
# @param {String} hook - The name of the hook
# @param {Function} callback - The callback function
###
RocketChat.callbacks.add = (hook, callback, priority) ->
# if callback array doesn't exist yet, initialize it
priority ?= RocketChat.callbacks.priority.MEDIUM
unless _.isNumber priority
priority = RocketChat.callbacks.priority.MEDIUM
callback.priority = priority
RocketChat.callbacks[hook] ?= []
RocketChat.callbacks[hook].push callback
return
###
# Remove a callback from a hook
# @param {string} hook - The name of the hook
# @param {string} functionName - The name of the function to remove
###
RocketChat.callbacks.remove = (hookName, callbackName) ->
RocketChat.callbacks[hookName] = _.reject RocketChat.callbacks[hookName], (callback) ->
callback.name is callbackName
return
###
# Successively run all of a hook's callbacks on an item
# @param {String} hook - The name of the hook
# @param {Object} item - The post, comment, modifier, etc. on which to run the callbacks
# @param {Object} [constant] - An optional constant that will be passed along to each callback
# @returns {Object} Returns the item after it's been through all the callbacks for this hook
###
RocketChat.callbacks.run = (hook, item, constant) ->
callbacks = RocketChat.callbacks[hook]
if !!callbacks?.length
# if the hook exists, and contains callbacks to run
_.sortBy(callbacks, (callback) -> return callback.priority or RocketChat.callbacks.priority.MEDIUM).reduce (result, callback) ->
# console.log(callback.name);
callback result, constant
, item
else
# else, just return the item unchanged
item
###
# Successively run all of a hook's callbacks on an item, in async mode (only works on server)
# @param {String} hook - The name of the hook
# @param {Object} item - The post, comment, modifier, etc. on which to run the callbacks
# @param {Object} [constant] - An optional constant that will be passed along to each callback
###
RocketChat.callbacks.runAsync = (hook, item, constant) ->
callbacks = RocketChat.callbacks[hook]
if Meteor.isServer and !!callbacks?.length
# use defer to avoid holding up client
Meteor.defer ->
# run all post submit server callbacks on post object successively
_.sortBy(callbacks, (callback) -> return callback.priority or RocketChat.callbacks.priority.MEDIUM).forEach (callback) ->
# console.log(callback.name);
callback item, constant
return
return
else
return item
return
###
# Kick off the global namespace for RocketChat.
# @namespace RocketChat
###
RocketChat = {}
# This will add underscore.string methods to Underscore.js
# except for include, contains, reverse and join that are
# dropped because they collide with the functions already
# defined by Underscore.js.
_.mixin(s.exports())
\ No newline at end of file
Package.describe({
name: 'rocketchat:lib',
version: '0.0.1',
summary: 'RocketChat libraries',
git: ''
});
Package.onUse(function(api) {
api.versionsFrom('1.0');
api.use([
'coffeescript',
'underscore',
'underscorestring:underscore.string'
]);
api.addFiles('lib/underscore.string.coffee', 'server');
api.addFiles('lib/core.coffee', 'server');
api.addFiles('lib/callbacks.coffee', 'server');
api.export(['RocketChat'], ['server']);
});
Package.onTest(function(api) {
});
###
# Me is a named function that will replace /me commands
# @param {Object} doc - The message object
###
class Me
constructor: (doc) ->
# If message starts with /me, replace it for text formatting
if doc.message.indexOf('/me') is 0
doc.message = '######' + Meteor.user().name + doc.message.replace('/me', '')
return doc
RocketChat.callbacks.add 'sendMessage', Me
Package.describe({
name: 'rocketchat:me',
version: '0.0.1',
summary: 'Message pre-processor that will translate /me commands',
git: ''
});
Package.onUse(function(api) {
api.versionsFrom('1.0');
api.use([
'coffeescript',
'rocketchat:lib@0.0.1'
]);
api.addFiles('me.coffee', 'server');
});
Package.onTest(function(api) {
});
......@@ -87,7 +87,7 @@
<button class="button red"><span>Access the Online Demo</span></button>
</a>
<div class='text'>
<h1>RocketChat</h1>
<h1>Rocket.Chat</h1>
<h2>Your own Open Source chat solution</h2>
<p>Have your own web chat. Developed with Meteor.com, the Rocket.Chat is a great solution for developers looking forward to build and evolve their own chat platform.</p>
<a class="button" href="/login"><span>Access the Online Demo</span></a>
......
......@@ -48,6 +48,8 @@ Meteor.methods
if mentions.length is 0
mentions = undefined
msg = RocketChat.callbacks.run 'sendMessage', msg
ChatMessage.upsert messageFilter,
$set:
'u._id': Meteor.userId()
......
......@@ -9,10 +9,10 @@ Meteor.methods
Meteor.users.update {_id: user._id}, {$set: {avatarOrigin: service}}
return
{image, contentType} = RocketFile.dataURIParse dataURI
{image, contentType} = RocketChatFile.dataURIParse dataURI
rs = RocketFile.bufferToStream new Buffer(image, 'base64')
ws = RocketFileAvatarInstance.createWriteStream "#{user.username}.jpg", contentType
rs = RocketChatFile.bufferToStream new Buffer(image, 'base64')
ws = RocketChatFileAvatarInstance.createWriteStream "#{user.username}.jpg", contentType
ws.on 'end', Meteor.bindEnvironment ->
Meteor.users.update {_id: user._id}, {$set: {avatarOrigin: service}}
......@@ -26,7 +26,7 @@ Meteor.methods
user = Meteor.user()
RocketFileAvatarInstance.deleteFile "#{user.username}.jpg"
RocketChatFileAvatarInstance.deleteFile "#{user.username}.jpg"
Meteor.users.update user._id, {$unset: {avatarOrigin: 1}}
return
......@@ -4,10 +4,10 @@ Meteor.startup ->
if Meteor.settings?.public?.avatarStore?.type?
storeType = Meteor.settings.public.avatarStore.type
RocketStore = RocketFile[storeType]
RocketChatStore = RocketChatFile[storeType]
if not RocketStore?
throw new Error "Invalid RocketStore type [#{storeType}]"
if not RocketChatStore?
throw new Error "Invalid RocketChatStore type [#{storeType}]"
console.log "Using #{storeType} for Avatar storage".green
......@@ -16,14 +16,14 @@ Meteor.startup ->
height = Meteor.settings.public.avatarStore.size.height
width = Meteor.settings.public.avatarStore.size.width
transformWrite = (file, readStream, writeStream) ->
RocketFile.gm(readStream, file.fileName).background('#ffffff').resize(width, height+'^>').gravity('Center').extent(width, height).stream('jpeg').pipe(writeStream)
RocketChatFile.gm(readStream, file.fileName).background('#ffffff').resize(width, height+'^>').gravity('Center').extent(width, height).stream('jpeg').pipe(writeStream)
path = "~/uploads"
if Meteor.settings?.public?.avatarStore?.path?
path = Meteor.settings.public.avatarStore.path
@RocketFileAvatarInstance = new RocketStore
@RocketChatFileAvatarInstance = new RocketChatStore
name: 'avatars'
absolutePath: path
transformWrite: transformWrite
......@@ -33,7 +33,7 @@ Meteor.startup ->
'stream': true
'get': (data) ->
this.params.username
file = RocketFileAvatarInstance.getFileWithReadStream this.params.username
file = RocketChatFileAvatarInstance.getFileWithReadStream this.params.username
this.addHeader 'Content-Disposition', 'inline'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment