Skip to content

Commit

Permalink
add xss packge and use node8
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhutu committed Jul 10, 2017
1 parent 0cba4cd commit 41ac6a9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM jackhu/jenkins-deploy-nodejs:7
FROM jackhu/jenkins-deploy-nodejs:8
MAINTAINER Jack Hu <[email protected]>

EXPOSE 8800
Expand Down
16 changes: 12 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jackblog-api-koa",
"version": "2.2.1",
"version": "2.3.0",
"description": "jackblog API koa版",
"main": "server/app.js",
"scripts": {
Expand Down Expand Up @@ -73,7 +73,8 @@
"passport-qq": "0.0.3",
"passport-weibo": "^0.1.2",
"qiniu": "6.1.13",
"trek-captcha": "^0.3.0"
"trek-captcha": "^0.3.0",
"xss": "^0.3.3"
},
"devDependencies": {
"ava": "^0.20.0",
Expand Down
20 changes: 12 additions & 8 deletions server/api/comment/comment.controller.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict'

const _ = require('lodash')
const xss = require('xss')
const mongoose = require('mongoose')
const Comment = mongoose.model('Comment')
const Blog = mongoose.model('Article')

//添加新的评论.
exports.addNewComment = async (ctx,next) => {
const aid = ctx.request.body.aid
const content = ctx.request.body.content
let content = ctx.request.body.content
const userId = ctx.req.user._id
let error_msg
if(!aid){
Expand All @@ -20,6 +21,8 @@ exports.addNewComment = async (ctx,next) => {
ctx.status = 422
return ctx.body = {error_msg:error_msg}
}
content = xss(content)

try{
let result = await Comment.create({ aid:aid,content:content,user_id:userId })
let comment = result.toObject()
Expand All @@ -41,13 +44,13 @@ exports.getFrontCommentList = async (ctx,next)=>{
const aid = ctx.params.id
try{
const commentList = await Comment.find({aid:aid,status:{$eq:1}})
.sort('created')
.populate({
path: 'user_id',
select: 'nickname avatar'
})
.exec()

.sort('created')
.populate({
path: 'user_id',
select: 'nickname avatar',
match: { nickname: { $exists: true } },
})
.exec()
ctx.status = 200
ctx.body = {data:commentList}
}catch(err){
Expand All @@ -61,6 +64,7 @@ exports.addNewReply = async (ctx,next)=>{
ctx.status = 422
return ctx.body = {error_msg:'回复内容不能为空'}
}
ctx.request.body.content = xss(ctx.request.body.content)
let reply = ctx.request.body
reply.user_info = {
id:ctx.req.user._id,
Expand Down

0 comments on commit 41ac6a9

Please sign in to comment.