changed the file upload to use streams

v1.18.x
Baris Usakli 12 years ago
parent f767d3a007
commit 39798b9f79

@ -59,7 +59,6 @@
</div> </div>
<div id="user-actions" class="container"> <div id="user-actions" class="container">
<a id="add-friend-btn" href="#" class="btn">Add Friend</a> <a id="add-friend-btn" href="#" class="btn">Add Friend</a>
<a id="send-message-btn" href="#" class="btn">Send Message</a>
</div> </div>
</div> </div>
@ -88,16 +87,15 @@ var theirid = '{theirid}';
var editLink = $('#editLink'); var editLink = $('#editLink');
var addFriendBtn = $('#add-friend-btn'); var addFriendBtn = $('#add-friend-btn');
var sendMessageBtn = $('#send-message-btn');
if( yourid !== theirid) { if( yourid !== theirid) {
editLink.hide(); editLink.hide();
addFriendBtn.show(); addFriendBtn.show();
sendMessageBtn.show();
} }
else { else {
addFriendBtn.hide(); addFriendBtn.hide();
sendMessageBtn.hide();
} }
addFriendBtn.on('click', function() { addFriendBtn.on('click', function() {
@ -109,9 +107,7 @@ var theirid = '{theirid}';
return false; return false;
}); });
sendMessageBtn.on('click', function() {
return false;
});
}); });

@ -136,7 +136,37 @@ var user = require('./../user.js'),
console.log('trying to upload to : '+ global.configuration['ROOT_DIRECTORY'] + uploadPath); console.log('trying to upload to : '+ global.configuration['ROOT_DIRECTORY'] + uploadPath);
fs.rename( var is = fs.createReadStream(tempPath);
var os = fs.createWriteStream(global.configuration['ROOT_DIRECTORY'] + uploadPath);
is.pipe(os);
is.on('end', function(){
fs.unlinkSync(tempPath);
var imageUrl = config.upload_url + filename;
res.send({
path: imageUrl
});
user.setUserField(uid, 'uploadedpicture', imageUrl);
user.setUserField(uid, 'picture', imageUrl);
});
os.on('error', function(err) {
console.log(err);
});
/*util.pump(is, os, function() {
fs.unlinkSync('source_file');
});*/
/*fs.rename(
tempPath, tempPath,
global.configuration['ROOT_DIRECTORY'] + uploadPath, global.configuration['ROOT_DIRECTORY'] + uploadPath,
function(error) { function(error) {
@ -158,7 +188,7 @@ var user = require('./../user.js'),
user.setUserField(uid, 'picture', imageUrl); user.setUserField(uid, 'picture', imageUrl);
} }
); );*/
} }
@ -211,7 +241,9 @@ var user = require('./../user.js'),
}); });
function api_method(req, res) { function api_method(req, res) {
console.log("fail "+req.params.section);
var callerUID = req.user?req.user.uid : 0; var callerUID = req.user?req.user.uid : 0;
if (!req.params.section && !req.params.username) { if (!req.params.section && !req.params.username) {

@ -372,6 +372,15 @@ var config = require('../config.js'),
}); });
} }
User.removeFriend = function(uid, friendid, callback) {
RDB.srem('user:'+uid+':friends', friendid, function(err, data){
if(err === null)
callback(data);
else
console.log(err);
});
}
User.exists = function(username, callback) { User.exists = function(username, callback) {
User.get_uid_by_username(username, function(exists) { User.get_uid_by_username(username, function(exists) {
exists = !!exists; exists = !!exists;

Loading…
Cancel
Save