Added file sending

This commit is contained in:
hydrabolt
2015-08-21 14:00:39 +01:00
parent 68db1f6ac0
commit 9572236b69
3 changed files with 102 additions and 54 deletions

View File

@@ -124,6 +124,22 @@ Internal.XHR.sendMessage = function( token, channelID, messageParameters, callba
}
Internal.XHR.sendFile = function( token, channelID, file, fileName, callback ) {
request
.post( Endpoints.CHANNELS + "/" + channelID + "/messages" )
.set( "authorization", token )
.attach("file", file, fileName)
.end( function( err, res ) {
if ( err ) {
callback( err );
} else {
callback( null, res.body );
}
} );
}
Internal.XHR.deleteMessage = function( token, channelID, messageID, callback ) {
request
.del( Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID )
@@ -133,19 +149,19 @@ Internal.XHR.deleteMessage = function( token, channelID, messageID, callback ) {
} );
}
Internal.XHR.updateMessage = function( token, channelID, messageID, messageParameters, callback ){
Internal.XHR.updateMessage = function( token, channelID, messageID, messageParameters, callback ) {
request
.patch(Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID)
.set( "authorization", token )
.send( messageParameters )
.end(function(err, res){
if ( err ) {
callback( err );
} else {
callback( null, res.body );
}
});
request
.patch( Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID )
.set( "authorization", token )
.send( messageParameters )
.end( function( err, res ) {
if ( err ) {
callback( err );
} else {
callback( null, res.body );
}
} );
}
Internal.XHR.getChannelLogs = function( token, channelID, amount, callback ) {
@@ -225,36 +241,36 @@ Internal.XHR.getServer = function( token, serverID, callback ) {
}
Internal.XHR.acceptInvite = function(token, inviteID, callback){
Internal.XHR.acceptInvite = function( token, inviteID, callback ) {
request
.post( Endpoints.API + "/invite/" + inviteID )
.set( "authorization", token )
.end(function(err, res){
if(err){
callback(err);
}else{
callback(null, res.body)
.end( function( err, res ) {
if ( err ) {
callback( err );
} else {
callback( null, res.body )
}
});
} );
}
Internal.XHR.setUsername = function(token, avatar, email, newPassword, password, username, callback){
Internal.XHR.setUsername = function( token, avatar, email, newPassword, password, username, callback ) {
request
.patch(Endpoints.API + "/users/@me")
.patch( Endpoints.API + "/users/@me" )
.set( "authorization", token )
.send({
avatar : avatar,
email : email,
new_password : newPassword,
password : password,
username : username
})
.end(function(err){
callback(err);
});
.send( {
avatar: avatar,
email: email,
new_password: newPassword,
password: password,
username: username
} )
.end( function( err ) {
callback( err );
} );
}