Skip to content

Commit

Permalink
add pic upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ltebean committed Feb 18, 2013
1 parent 2cb6b41 commit bc4e6ec
Show file tree
Hide file tree
Showing 6 changed files with 463 additions and 43 deletions.
81 changes: 42 additions & 39 deletions invitation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var Step = require('step');
var fs = require('fs');
var mongo = require('mongodb');
var check = require('validator').check;
var msg=require('./msg.js');
Expand Down Expand Up @@ -61,6 +61,7 @@ exports.welcome=function(req, res){
res.send(invitation);
});
}

exports.create=function(req, res){
//validateInvitation(req.body);
Step(
Expand Down Expand Up @@ -94,10 +95,7 @@ exports.create=function(req, res){
},
function sendNotification(err,invitation){
if (err) throw err;
var weiboIds=[];
for (var i = 0; i < invitation.invitees.length; i++) {
weiboIds.push(invitation.invitees[i].user.weiboId);
}
var weiboIds=getNotificationList(invitation,invitation.inviter.user.weiboId);
var msg=invitation.inviter.user.weiboName+'发起了一个活动('+invitation.shopList[0].shopName+')';
notification.send(weiboIds,msg,{});
return invitation;
Expand Down Expand Up @@ -176,31 +174,15 @@ exports.replyStatus= function(req, res){
{safe:true,new:true},
this);
},
function sendMessage(err,invitation){
if (err) throw err;
// invitation.invitees.forEach(function(invitee){
// msg.addMessage(invitee.user.weiboId,{type:'status',body:req.body});
// });
// msg.addMessage(invitation.inviter.user.weiboId,{type:'status',body:req.body});
return invitation;
},
function sendNotification(err,invitation){
if (err) throw err;
var weiboIds=[];
var msg='';
if(req.body.status==='accept'){
msg=req.body.user.weiboName+'参加了活动('+invitation.shopList[0].shopName+')';
}else{
msg=req.body.user.weiboName+'拒绝了活动('+invitation.shopList[0].shopName+')';
}
if(invitation.inviter.user.weiboId!=req.body.user.weiboId){
weiboIds.push(invitation.inviter.user.weiboId);
}
for (var i = 0; i < invitation.invitees.length; i++) {
if(invitation.invitees[i].user.weiboId!=req.body.user.weiboId){
weiboIds.push(invitation.invitees[i].user.weiboId);
}
}
var weiboIds=getNotificationList(invitation,req.body.user.weiboId);
notification.send(weiboIds,msg,{});
return invitation;
},
Expand All @@ -222,28 +204,37 @@ exports.replyComment=function(req, res){
{$push:{'replyList':req.body}, $set:{'lastUpdateDate':new Date()}},
{safe:true,new:true},
this);
},
function sendMessage(err,invitation){
},function sendNotification(err,invitation){
if (err) throw err;
// invitation.invitees.forEach(function(invitee){
// msg.addMessage(invitee.user.weiboId,{type:'reply',body:req.body});
// });
// msg.addMessage(invitation.inviter.user.weiboId,{type:'reply',body:req.body});
var msg=req.body.user.weiboName+'发表了回复:'+req.body.content;
var weiboIds=getNotificationList(invitation,req.body.user.weiboId);
notification.send(weiboIds,msg,{});
return invitation;
},
function generateResponse(err, invitation){
if (err) throw err;
res.send(invitation);
});
}

exports.addPic=function(req, res){
Step(
function getCollection(){
db.collection('invitation', this);
},
function updateData(err,collection){
if (err) throw err;
collection.findAndModify(
{'_id':new BSON.ObjectID(req.params.id)},[],
{$push:{'picWall':req.body}, $set:{'lastUpdateDate':new Date()}},
{safe:true,new:true},
this);
},
function sendNotification(err,invitation){
if (err) throw err;
var msg=req.body.user.weiboName+'发表了回复:'+req.body.content;
var weiboIds=[];
if(invitation.inviter.user.weiboId!=req.body.user.weiboId){
weiboIds.push(invitation.inviter.user.weiboId);
}
for (var i = 0; i < invitation.invitees.length; i++) {
if(invitation.invitees[i].user.weiboId!=req.body.user.weiboId){
weiboIds.push(invitation.invitees[i].user.weiboId);
}
}
notification.send(weiboIds,msg,{});
// var msg=req.body.user.weiboName+'添加了一张图片';
// var weiboIds=getNotificationList(invitation,req.body.user.weiboId);
// notification.send(weiboIds,msg,{});
return invitation;
},
function generateResponse(err, invitation){
Expand All @@ -252,6 +243,18 @@ exports.replyComment=function(req, res){
});
}

function getNotificationList(invitation,senderId){
var weiboIds=[];
if(invitation.inviter.user.weiboId!=senderId){
weiboIds.push(invitation.inviter.user.weiboId);
}
for (var i = 0; i < invitation.invitees.length; i++) {
if(invitation.invitees[i].user.weiboId!=senderId){
weiboIds.push(invitation.invitees[i].user.weiboId);
}
}
return weiboIds
}

function validateInvitation(invitation){
check(invitation.inviter).isNull();
Expand Down
24 changes: 24 additions & 0 deletions lib/picUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Date.prototype.format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}

exports.generatePicPath=function () {
return '/user/'+ new Date().format('yyyyMMddhhmmss');
}

exports.getDomian=function () {
return 'http://lets-party-pic.b0.upaiyun.com';

}
Loading

0 comments on commit bc4e6ec

Please sign in to comment.