Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pisns-forum-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
scrmGroup
pisns-forum-api
Commits
585ec733
Commit
585ec733
authored
Dec 17, 2015
by
strong
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'remould_1214_api_optimize' into SANDBOX
parents
c75e8d9d
c76dbf7f
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
276 additions
and
176 deletions
+276
-176
commentTips.js
app/controllers/mobile/commentTips.js
+2
-0
forumInfo.js
app/controllers/mobile/forumInfo.js
+28
-28
forumModerator.js
app/controllers/mobile/forumModerator.js
+2
-0
forumThread.js
app/controllers/mobile/forumThread.js
+10
-17
forumCommentService.js
app/service/forumCommentService.js
+13
-1
forumThreadService.js
app/service/forumThreadService.js
+220
-129
express.js
config/express.js
+1
-1
No files found.
app/controllers/mobile/commentTips.js
View file @
585ec733
...
...
@@ -17,6 +17,8 @@ router.get('/commentTips', function(req, res, next) {
if
(
err
){
res
.
json
(
returnCode
.
UNCHECK_ERROR
(
err
));
}
else
{
res
.
setHeader
(
'Cache-Control'
,
'private, max-age=600'
);
// 私有缓存一个10分钟
res
.
setHeader
(
'Expires'
,
new
Date
(
Date
.
now
()
+
600000
).
toUTCString
());
res
.
json
(
_
.
assign
({
data
:
result
},
returnCode
.
SUCCESS
));
}
});
...
...
app/controllers/mobile/forumInfo.js
View file @
585ec733
...
...
@@ -37,6 +37,8 @@ router.get('/info/list/all', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
datas
.
items
;
res
.
setHeader
(
'Cache-Control'
,
'public, max-age=3600'
);
// 公共缓存一个小时
res
.
setHeader
(
'Expires'
,
new
Date
(
Date
.
now
()
+
3600000
).
toUTCString
());
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
...
...
@@ -66,18 +68,13 @@ router.get('/info/:fid/get', function(req, res, next) {
if
(
fid
)
{
var
source
=
req
.
session
.
mobileForumUser
.
source
;
httpService
.
createLog
(
req
,
source
,
fid
,
2
);
async
.
waterfall
([
function
(
callback
)
{
//更新浏览数
forumInfoService
.
updateInfoPvCount
(
fid
,
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
console
.
error
(
err
);
}
});
},
function
(
data
,
callback
)
{
async
.
parallel
([
function
(
callback
)
{
forumInfoService
.
getInfoById
(
fid
,
function
(
err
,
info
)
{
if
(
err
)
{
callback
(
err
,
null
);
...
...
@@ -86,25 +83,25 @@ router.get('/info/:fid/get', function(req, res, next) {
}
});
},
function
(
info
,
callback
)
{
function
(
callback
)
{
forumThreadService
.
getAllCountByFid
({
info
:
fid
},
function
(
err
,
threadCount
)
{
if
(
err
)
{
callback
(
err
,
null
,
null
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
info
,
threadCount
);
callback
(
null
,
threadCount
);
}
});
}
],
function
(
err
,
info
,
threadCount
)
{
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
info
;
rs
.
data
.
threadCount
=
threadCount
;
rs
.
data
=
results
[
0
]
;
rs
.
data
.
threadCount
=
results
[
1
]
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
...
...
@@ -170,17 +167,18 @@ router.get('/info/:fid/threads', function(req, res, next) {
if
(
fid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
if
(
doc
)
{
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
// forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
// if (err) {
// callback(err, null);
// } else {
// if (doc) {
// callback(null, doc);
// } else {
// callback(null, null);
// }
// }
// });
}
],
function
(
err
,
result
)
{
if
(
err
)
{
...
...
@@ -667,6 +665,8 @@ router.get('/info/:fid/tags', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
setHeader
(
'Cache-Control'
,
'public, max-age=3600'
);
// 公共缓存一个小时
res
.
setHeader
(
'Expires'
,
new
Date
(
Date
.
now
()
+
3600000
).
toUTCString
());
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
...
...
app/controllers/mobile/forumModerator.js
View file @
585ec733
...
...
@@ -72,6 +72,8 @@ router.get('/moderators/plates', function(req, res, next) {
if
(
result
&&
result
.
infoIds
){
items
=
result
.
infoIds
;
}
res
.
setHeader
(
'Cache-Control'
,
'public, max-age=3600'
);
// 公共缓存一个小时
res
.
setHeader
(
'Expires'
,
new
Date
(
Date
.
now
()
+
3600000
).
toUTCString
());
res
.
json
(
_
.
assign
({
items
:
items
},
returnCode
.
SUCCESS
));
});
});
...
...
app/controllers/mobile/forumThread.js
View file @
585ec733
...
...
@@ -518,20 +518,16 @@ router.get('/thread/:tid/get', function(req, res, next) {
var
tid
=
req
.
params
.
tid
||
null
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
tid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumThreadService
.
updateThreadPvCount
(
tid
,
function
(
err
,
doc
)
{
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
//文章类型 1、文章 2、话题 3、照片墙
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
callback
(
null
,
thread
);
}
});
},
function
(
data
,
callback
)
{
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
//文章类型 1、文章 2、话题 3、照片墙
var
info_id
=
thread
.
info
.
_id
,
pid
=
thread
.
pid
,
source
=
req
.
session
.
mobileForumUser
.
source
;
...
...
@@ -544,13 +540,10 @@ router.get('/thread/:tid/get', function(req, res, next) {
}
else
if
(
thread
.
type
==
3
&&
thread
.
level
==
1
)
{
httpService
.
createLog
(
req
,
source
,
info_id
,
3
,
3
,
tid
);
}
});
forumThreadService
.
updateThreadPvCount
(
tid
,
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
console
.
error
(
err
);
}
});
},
...
...
app/service/forumCommentService.js
View file @
585ec733
...
...
@@ -4,6 +4,18 @@ var ForumComment = mongoose.model('ForumComment');
var
forumUserService
=
require
(
'./forumUserService'
);
var
async
=
require
(
'async'
);
var
listCommentFields
=
{
from
:
1
,
content
:
1
,
level
:
1
,
floor
:
1
,
praise_count
:
1
,
comment_count
:
1
,
comments
:
1
,
status
:
1
};
//创建评论
exports
.
createComment
=
function
(
entity
,
callback
)
{
var
forum
=
new
ForumComment
(
entity
);
...
...
@@ -125,7 +137,7 @@ exports.getAllComment = function(conditions, pageNo, pageSize, callback) {
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
ForumComment
.
find
(
conditions
).
populate
(
'from'
).
populate
(
'to
'
).
limit
(
limit
).
skip
(
skip
).
sort
(
'-created'
).
exec
(
function
(
err
,
docs
)
{
ForumComment
.
find
(
conditions
,
listCommentFields
).
populate
(
'from'
,
'uid mid nickName icon exp'
).
populate
(
'to'
,
'uid mid nickName icon exp
'
).
limit
(
limit
).
skip
(
skip
).
sort
(
'-created'
).
exec
(
function
(
err
,
docs
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
app/service/forumThreadService.js
View file @
585ec733
...
...
@@ -10,6 +10,80 @@ var forumCommentService = require('./forumCommentService');
var
async
=
require
(
'async'
);
var
then
=
require
(
'thenjs'
);
var
listThreadFields
=
{
content
:
1
,
type
:
1
,
title
:
1
,
pid
:
1
,
from
:
1
,
created
:
1
,
recommend
:
1
,
praise_count
:
1
,
comment_count
:
1
,
images
:
1
,
comments
:
1
,
level
:
1
,
top
:
1
,
pv_count
:
1
,
address
:
1
};
var
singleThreadFields
=
{
content
:
1
,
type
:
1
,
title
:
1
,
pid
:
1
,
info
:
1
,
from
:
1
,
created
:
1
,
recommend
:
1
,
praise_count
:
1
,
comment_count
:
1
,
images
:
1
,
level
:
1
,
top
:
1
,
pv_count
:
1
,
address
:
1
};
var
subThreadFields
=
{
from
:
1
};
/**
* 过滤 html 标签正则
* @type {RegExp}
*/
var
htmlElReg
=
/<
[^
>
]
*>/ig
;
/**
* 过滤表情正则
* @type {RegExp}
*/
var
emElReg
=
/
\【
em_
([
0-9
]
*
)\】
/ig
;
/**
* 帖子内容处理函数
* @param {String} content 原始帖子内容
* @return {String} 处理完的帖子
*/
function
handleContent
(
content
)
{
content
=
content
||
""
;
content
=
content
.
replace
(
htmlElReg
,
""
)
.
replace
(
emElReg
,
""
);
if
(
content
.
length
>
200
)
{
content
=
content
.
substr
(
0
,
200
)
+
"……"
;
}
return
content
.
trim
();
}
//根据发帖者分页查询话题列表
exports
.
findThreadByPage
=
function
(
pageNo
,
pageSize
,
q
,
callback
)
{
then
(
function
(
cont
)
{
...
...
@@ -135,21 +209,19 @@ exports.getByConditions = function(conditions, callback) {
}
//根据ID获取文章
exports
.
getThreadById
=
function
(
tid
,
callback
)
{
async
.
parallel
([
function
(
cb
)
{
var
conditions
=
{
_id
:
tid
};
ForumThread
.
findOne
(
conditions
).
populate
(
'from'
).
populate
(
'info'
).
populate
(
'share'
).
exec
(
function
(
err
,
doc
)
{
ForumThread
.
findOne
({
_id
:
tid
},
singleThreadFields
).
populate
(
'from'
,
'uid mid nickName icon exp'
).
populate
(
'info'
,
'name icon'
).
populate
(
'share'
).
exec
(
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
cb
(
null
,
doc
);
}
});
},
if
(
doc
)
{
async
.
parallel
([
function
(
cb
)
{
if
(
doc
.
type
!==
1
)
{
cb
(
null
,
null
);
return
;
}
var
conditions
=
{
thread
:
tid
,
level
:
'1'
...
...
@@ -167,6 +239,10 @@ exports.getThreadById = function(tid, callback) {
},
function
(
cb
)
{
//获取话题子文章列表
if
(
doc
.
type
!==
2
)
{
cb
(
null
,
null
);
return
;
}
var
conditions
=
{
pid
:
tid
,
type
:
2
,
...
...
@@ -184,6 +260,10 @@ exports.getThreadById = function(tid, callback) {
},
function
(
cb
)
{
//获取照片墙最新文章列表
if
(
doc
.
type
!==
3
)
{
cb
(
null
,
null
);
return
;
}
var
conditions
=
{
pid
:
tid
,
type
:
3
,
...
...
@@ -201,6 +281,10 @@ exports.getThreadById = function(tid, callback) {
},
function
(
cb
)
{
//获取照片墙最热文章列表
if
(
doc
.
type
!==
3
)
{
cb
(
null
,
null
);
return
;
}
var
conditions
=
{
pid
:
tid
,
type
:
3
,
...
...
@@ -243,12 +327,12 @@ exports.getThreadById = function(tid, callback) {
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
var
thread
=
results
[
0
]
;
var
comments
=
results
[
1
];
var
subThreads
=
results
[
2
]
||
[];
//话题子文章列表
var
latestPhotos
=
results
[
3
]
||
[];
//最新照片墙列表
var
hotPhotos
=
results
[
4
]
||
[];
//最热照片墙列表
var
canyuPeopleCount
=
results
[
5
]
||
0
;
//参与人数
var
thread
=
doc
;
var
comments
=
results
[
0
]
||
[
];
var
subThreads
=
results
[
1
]
||
[];
//话题子文章列表
var
latestPhotos
=
results
[
2
]
||
[];
//最新照片墙列表
var
hotPhotos
=
results
[
3
]
||
[];
//最热照片墙列表
var
canyuPeopleCount
=
results
[
4
]
||
0
;
//参与人数
var
threadObj
=
thread
&&
thread
.
toObject
()
||
{};
threadObj
.
comments
=
comments
;
...
...
@@ -260,6 +344,12 @@ exports.getThreadById = function(tid, callback) {
callback
(
null
,
threadObj
);
}
});
}
else
{
callback
(
null
,
{});
}
}
});
};
//根据ID获取文章
exports
.
getThreadByIdSimple
=
function
(
conditions
,
callback
)
{
...
...
@@ -274,7 +364,7 @@ exports.getThreadByIdNoLimit = function(tid, callback) {
var
conditions
=
{
_id
:
tid
};
ForumThread
.
findOne
(
conditions
).
populate
(
'from'
).
populate
(
'info'
).
populate
(
'share'
).
exec
(
function
(
err
,
doc
)
{
ForumThread
.
findOne
(
conditions
,
singleThreadFields
).
populate
(
'from'
).
populate
(
'info'
).
populate
(
'share'
).
exec
(
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -582,6 +672,7 @@ function populateSubComment(subComments, callback) {
//获取数量
function
countAllByFid
(
conditions
,
callback
)
{
// callback(null, 21);
ForumThread
.
count
(
conditions
,
function
(
err
,
count
)
{
if
(
err
)
{
console
.
error
(
err
);
...
...
@@ -611,7 +702,7 @@ function getSubThreads(doc, sort, callback) {
if
(
sort
)
{
sortBy
=
sort
;
}
ForumThread
.
find
(
conditions
).
populate
(
'from
'
).
sort
(
sortBy
).
exec
(
function
(
err
,
docs
)
{
ForumThread
.
find
(
conditions
,
subThreadFields
).
populate
(
'from'
,
'icon
'
).
sort
(
sortBy
).
exec
(
function
(
err
,
docs
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -642,8 +733,8 @@ function getAllThreadByFidHelp(conditions, pageNo, pageSize, sort, callback) {
if
(
sort
)
{
sortBy
=
sort
;
}
ForumThread
.
find
(
conditions
).
populate
(
'from'
).
populate
(
'info
'
).
populate
({
path
:
'tag'
ForumThread
.
find
(
conditions
,
listThreadFields
).
populate
(
'from'
,
'uid mid nickName icon'
).
populate
(
'info'
,
'name icon pv_count
'
).
populate
({
path
:
'tag'
,
select
:
'title pv_count'
}).
populate
({
path
:
'comments'
,
options
:
{
...
...
@@ -662,7 +753,6 @@ function getAllThreadByFidHelp(conditions, pageNo, pageSize, sort, callback) {
obj
.
pageNo
=
pageNo
;
obj
.
pageSize
=
pageSize
;
obj
.
items
=
docs
;
if
(
docs
&&
docs
.
length
>
0
)
{
var
asyncTasks
=
[];
...
...
@@ -710,8 +800,8 @@ function getAllThreadByFidHelpNoLimit(conditions, pageNo, pageSize, sort, callba
if
(
sort
)
{
sortBy
=
sort
;
}
ForumThread
.
find
(
conditions
).
populate
(
'from'
).
populate
(
'info
'
).
populate
({
path
:
'tag'
ForumThread
.
find
(
conditions
,
listThreadFields
).
populate
(
'from'
,
'uid mid nickName icon'
).
populate
(
'info'
,
'name icon pv_count
'
).
populate
({
path
:
'tag'
,
select
:
'title pv_count'
}).
populate
({
path
:
'comments'
,
options
:
{
...
...
@@ -774,6 +864,7 @@ exports.getAllThreadByFidNoLimit = function(conditions, pageNo, pageSize, sort,
//获取全部列表数据
exports
.
getAllThreadByFid
=
function
(
conditions
,
pageNo
,
pageSize
,
sort
,
callback
)
{
getAllThreadByFidHelp
(
conditions
,
pageNo
,
pageSize
,
sort
,
callback
);
};
//根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶)
...
...
@@ -1027,8 +1118,8 @@ function getAllThreadByFidAndUserHelp(user_ids, conditions, pageNo, pageSize, so
if
(
sort
)
{
sortBy
=
sort
;
}
ForumThread
.
find
(
conditions
).
populate
(
'from'
).
populate
(
'info
'
).
populate
({
path
:
'tag'
ForumThread
.
find
(
conditions
,
listThreadFields
).
populate
(
'from'
,
'uid mid nickName icon'
).
populate
(
'info'
,
'name icon pv_count
'
).
populate
({
path
:
'tag'
,
select
:
'title pv_count'
}).
populate
({
path
:
'comments'
,
options
:
{
...
...
config/express.js
View file @
585ec733
...
...
@@ -21,7 +21,7 @@ module.exports = function(app, config) {
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
app
.
use
(
compress
());
//
app.use(compress());
app
.
use
(
cookieParser
());
app
.
use
(
methodOverride
());
app
.
use
(
multiparty
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment