index.js
1.01 KB
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
var express = require('express');
var createError = require('http-errors');
var router = express.Router();
const post = require('../../../model/video')
router.get('/list', (req, res, next) => {
let { tag, skip } = req.query
let joinedTag = tag.join("|")
let regexsearch = { tag: { $regex: joinedTag, $options: 'si' } }
skip = parseInt(skip)
post.find()
.sort({'_id': -1})
.limit(12)
.skip(skip)
.then(rs => {
console.log(rs)
res.send({ success: true, d: rs, })
})
.catch(e => {
console.log(e)
res.send({ success: false, msg: e.message })
})
})
router.delete('/:_id', (req, res, next) => {
const _id = req.params._id
post.findOne({ _id })
.then(r => {
console.log(r)
return post.deleteOne({ _id })
})
.then(r => {
res.send({ success: true, d: r})
})
.catch(e => {
console.log(e)
res.send({ success: false, msg: e.message })
})
})
router.all('*', function (req, res, next) {
next(new Error ('Wrong Url!'));
});
module.exports = router;