forked from DesertsP/Valine-Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comments.js
94 lines (88 loc) · 2.64 KB
/
comments.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use strict';
const router = require('express').Router();
const AV = require('leanengine');
const mail = require('../utilities/send-mail');
const spam = require('../utilities/check-spam');
const Comment = AV.Object.extend('Comment');
// Comment 列表
router.get('/', function (req, res, next) {
if (req.currentUser) {
let query = new AV.Query(Comment);
query.descending('createdAt');
query.limit(50);
query.find().then(function (results) {
res.render('comments', {
title: process.env.SITE_NAME + '上的评论',
comment_list: results
});
}, function (err) {
if (err.code === 101) {
res.render('comments', {
title: process.env.SITE_NAME + '上的评论',
comment_list: []
});
} else {
next(err);
}
}).catch(next);
} else {
res.redirect('/');
}
});
router.get('/resend-email', function (req, res, next) {
if (req.currentUser) {
let query = new AV.Query(Comment);
query.get(req.query.id).then(function (object) {
query.get(object.get('rid')).then(function (parent) {
mail.send(object, parent);
res.redirect('/comments')
}, function (err) {
}
).catch(next);
}, function (err) {
}).catch(next);
} else {
res.redirect('/');
}
});
router.get('/delete', function (req, res, next) {
if (req.currentUser) {
let query = new AV.Query(Comment);
query.get(req.query.id).then(function (object) {
object.destroy();
res.redirect('/comments')
}, function (err) {
}).catch(next);
} else {
res.redirect('/');
}
});
router.get('/not-spam', function (req, res, next) {
if (req.currentUser) {
let query = new AV.Query(Comment);
query.get(req.query.id).then(function (object) {
object.set('isSpam', false);
object.save();
spam.submitHam(object);
res.redirect('/comments')
}, function (err) {
}).catch(next);
} else {
res.redirect('/');
}
});
router.get('/mark-spam', function (req, res, next) {
if (req.currentUser) {
let query = new AV.Query(Comment);
query.get(req.query.id).then(function (object) {
object.set('isSpam', true);
object.save();
spam.submitSpam(object);
res.redirect('/comments')
}, function (err) {
}).catch(next);
} else {
res.redirect('/');
}
});
module.exports = router;